From 69d7bccca7331042f580b01196484b657c3607a2 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 12 Dec 2024 02:23:16 -0700 Subject: [PATCH] Add Video model --- app/Http/Controllers/VideoController.php | 10 +++ app/Models/Video.php | 74 +++++++++++++++++++ .../2024_12_12_091621_create_videos_table.php | 56 ++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 app/Http/Controllers/VideoController.php create mode 100644 app/Models/Video.php create mode 100644 database/migrations/2024_12_12_091621_create_videos_table.php diff --git a/app/Http/Controllers/VideoController.php b/app/Http/Controllers/VideoController.php new file mode 100644 index 0000000..b760852 --- /dev/null +++ b/app/Http/Controllers/VideoController.php @@ -0,0 +1,10 @@ + + */ + 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 + ); + } +} diff --git a/database/migrations/2024_12_12_091621_create_videos_table.php b/database/migrations/2024_12_12_091621_create_videos_table.php new file mode 100644 index 0000000..4f5894b --- /dev/null +++ b/database/migrations/2024_12_12_091621_create_videos_table.php @@ -0,0 +1,56 @@ +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'); + } +};