A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
fix: image source and image type should be string enums
aminnausin304dfd152ee7
diff --git a/app/Enums/ImageSource.php b/app/Enums/ImageSource.phpindex bc7bf308..76024f7a 100644--- a/app/Enums/ImageSource.php+++ b/app/Enums/ImageSource.php@@ -2,14 +2,14 @@namespace App\Enums;-enum ImageSource: int {- case GENERATED = 0;- case UPLOADED = 1;- case API = 2;- case URL = 3; // external url, not downloaded, makes no sense- case DOWNLOADED = 4;- case EMBEDDED = 5;- case LEGACY = 6;+enum ImageSource: string {+ case GENERATED = 'generated';+ case UPLOADED = 'uploaded';+ case API = 'api';+ case URL = 'url'; // external url, not downloaded, makes no sense+ case DOWNLOADED = 'downloaded';+ case EMBEDDED = 'embedded';+ case LEGACY = 'legacy';public function label(): string {return strtolower($this->name);diff --git a/app/Enums/ImageType.php b/app/Enums/ImageType.phpindex c4b2ab6d..7acb7754 100644--- a/app/Enums/ImageType.php+++ b/app/Enums/ImageType.php@@ -2,12 +2,9 @@namespace App\Enums;-enum ImageType: int {- case POSTER = 0;- case BANNER = 1;- case AVATAR = 2;-- public function label(): string {- return strtolower($this->name);- }+enum ImageType: string {+ case POSTER = 'poster';+ case BANNER = 'banner';+ case AVATAR = 'avatar';+ case PREVIEW = 'preview';}diff --git a/app/Models/Image.php b/app/Models/Image.phpindex 1b7aa1c9..97e6c5f5 100644--- a/app/Models/Image.php+++ b/app/Models/Image.php@@ -17,8 +17,8 @@ class Image extends Model {** user_id -> int8 (fk) (nullable) (onDelete=setNull)*- * image_type -> int2 (enum) (composite index with imageable_type, imageable_id, replaced_at)- * image_source -> int2 (enum)+ * image_type -> string (enum) (composite index with imageable_type, imageable_id, replaced_at)+ * image_source -> string (enum)* image_variant -> string (enum) (nullable)** width -> int4 (nullable)@@ -68,6 +68,6 @@ class Image extends Model {$variant = $this->image_variant ? "_{$this->image_variant->value}" : '';$ext = $this->format ?? 'webp';- return $this->image_type->label() . "{$variant}.{$ext}";+ return $this->image_type->value . "{$variant}.{$ext}";}}diff --git a/database/migrations/2026_06_06_195825_change_image_type_and_source_enums_to_strings_on_images.php b/database/migrations/2026_06_06_195825_change_image_type_and_source_enums_to_strings_on_images.phpnew file mode 100644index 00000000..27978b93--- /dev/null+++ b/database/migrations/2026_06_06_195825_change_image_type_and_source_enums_to_strings_on_images.php@@ -0,0 +1,107 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\DB;+use Illuminate\Support\Facades\Schema;++return new class extends Migration {+ private array $imageTypeMap = [+ 0 => 'poster',+ 1 => 'banner',+ 2 => 'avatar',+ ];++ private array $imageSourceMap = [+ 0 => 'generated',+ 1 => 'uploaded',+ 2 => 'api',+ 3 => 'url',+ 4 => 'downloaded',+ 5 => 'embedded',+ 6 => 'legacy',+ ];++ /**+ * Run the migrations.+ */+ public function up(): void {+ Schema::table('images', function (Blueprint $table) {+ $table->string('image_type_str', 50)->nullable();+ $table->string('image_source_str', 50)->nullable();+ });++ foreach ($this->imageTypeMap as $int => $str) {+ DB::table('images')->where('image_type', $int)->update(['image_type_str' => $str]);+ }++ foreach ($this->imageSourceMap as $int => $str) {+ DB::table('images')->where('image_source', $int)->update(['image_source_str' => $str]);+ }++ $unmappedType = DB::table('images')->whereNull('image_type_str')->count();+ $unmappedSource = DB::table('images')->whereNull('image_source_str')->count();++ if ($unmappedType > 0 || $unmappedSource > 0) {+ // abort if some entries failed to copy over+ Schema::table('images', function (Blueprint $table) {+ $table->dropColumn(['image_type_str', 'image_source_str']);+ });++ throw new \RuntimeException(+ "Migration aborted: {$unmappedType} unmapped image_type rows, {$unmappedSource} unmapped image_source rows."+ );+ }++ Schema::table('images', function (Blueprint $table) {+ $table->dropColumn(['image_type', 'image_source']);+ });++ Schema::table('images', function (Blueprint $table) {+ $table->renameColumn('image_type_str', 'image_type');+ $table->renameColumn('image_source_str', 'image_source');+ });++ // make not nullable+ Schema::table('images', function (Blueprint $table) {+ $table->string('image_type')->change();+ $table->string('image_source')->change();+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void {+ $imageTypeMap = array_flip($this->imageTypeMap);+ $imageSourceMap = array_flip($this->imageSourceMap);++ Schema::table('images', function (Blueprint $table) {+ $table->smallInteger('image_type_int')->nullable();+ $table->smallInteger('image_source_int')->nullable();+ });++ foreach ($imageTypeMap as $str => $int) {+ DB::table('images')->where('image_type', $str)->update(['image_type_int' => $int]);+ }++ foreach ($imageSourceMap as $str => $int) {+ DB::table('images')->where('image_source', $str)->update(['image_source_int' => $int]);+ }++ Schema::table('images', function (Blueprint $table) {+ $table->dropColumn(['image_type', 'image_source']);+ });++ Schema::table('images', function (Blueprint $table) {+ $table->renameColumn('image_type_int', 'image_type');+ $table->renameColumn('image_source_int', 'image_source');+ });++ // make not nullable+ Schema::table('images', function (Blueprint $table) {+ $table->smallInteger('image_type')->change();+ $table->smallInteger('image_source')->change();+ });+ }+};