Add Video model

This commit is contained in:
Daniel Supernault 2024-12-12 02:23:16 -07:00
parent 7c4846d2d6
commit 69d7bccca7
3 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class VideoController extends Controller
{
//
}

74
app/Models/Video.php Normal file
View File

@ -0,0 +1,74 @@
<?php
namespace App\Models;
use App\Concerns\HasSnowflakePrimary;
use App\Services\HashidService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Storage;
class Video extends Model
{
use HasFactory, HasSnowflakePrimary;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
public $guarded = [];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'profile_id' => 'string',
'is_sensitive' => 'boolean',
'media_metadata' => 'array',
];
}
public function hashid()
{
return HashidService::encode($this->id);
}
public function thumb()
{
$thumb = 'https://loopsusercontent.com/videos/video-placeholder.jpg';
if ($this->has_thumb) {
$ext = pathinfo($this->vid, PATHINFO_EXTENSION);
$url = str_replace('.' . $ext, '.jpg', $this->vid);
$thumb = Storage::disk('s3')->url($url);
}
return $thumb;
}
public function profile(): BelongsTo
{
return $this->belongsTo(Profile::class);
}
public function shareUrl(): string
{
return url('/v/' . HashidService::encode($this->id));
}
public function mediaUrl(): string
{
return Storage::disk('s3')
->url(
$this->has_processed && $this->vid_optimized ?
$this->vid_optimized :
$this->vid
);
}
}

View File

@ -0,0 +1,56 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('videos', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('profile_id')->nullable()->index();
$table->string('vid')->nullable();
$table->text('vid_optimized')->nullable();
$table->unsignedTinyInteger('status')->default(1)->index();
$table->unsignedTinyInteger('duration')->nullable();
$table->unsignedInteger('size_kb')->nullable();
$table->text('caption')->nullable();
$table->string('category', 50)->nullable();
$table->json('tags')->nullable();
$table->unsignedInteger('likes')->default(0);
$table->unsignedInteger('comments')->default(0);
$table->unsignedInteger('shares')->default(0);
$table->unsignedInteger('views')->default(0);
$table->boolean('is_sensitive')->default(false);
$table->boolean('is_adult')->default(false);
$table->boolean('has_audio')->default(true);
$table->boolean('has_thumb')->default(false);
$table->boolean('has_processed')->default(false);
$table->boolean('is_approved')->default(false)->index();
$table->json('features')->nullable();
$table->json('media_metadata')->nullable();
$table->unsignedTinyInteger('comment_state')->default(4);
$table->string('cw_title')->nullable();
$table->text('cw_body')->nullable();
$table->string('sha512_hash')->nullable()->index();
$table->boolean('has_hls')->default(false);
$table->boolean('can_download')->default(false);
$table->boolean('can_duet')->default(false);
$table->boolean('can_stitch')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('videos');
}
};