A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: permission gates for downloads on both library and folder level
aminnausinfd174ef4928e
diff --git a/app/Http/Controllers/Api/V1/Media/MediaController.php b/app/Http/Controllers/Api/V1/Media/MediaController.phpindex 88224371..e25a069a 100644--- a/app/Http/Controllers/Api/V1/Media/MediaController.php+++ b/app/Http/Controllers/Api/V1/Media/MediaController.php@@ -11,8 +11,8 @@ use Illuminate\Support\Facades\Storage;class MediaController extends Controller {public function download(Video $video) {- if (Auth::id() === null) {- abort(403, 'Forbidden Action');+ if (! $video->downloadsEnabled() || (Auth::id() === null && $video->folder->category->require_login_for_downloads)) {+ abort(403);}$path = substr($video->path, 7); // relative path from public diskdiff --git a/app/Models/Category.php b/app/Models/Category.phpindex 12cd599a..70077d6c 100755--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -15,6 +15,11 @@ class Category extends Model {protected $fillable = ['name', 'default_folder_id', 'editor_id'];+ protected $casts = [+ 'allow_downloads' => 'boolean',+ 'require_login_for_downloads' => 'boolean',+ ];+public function folders(): HasMany {return $this->hasMany(Folder::class);}@@ -30,4 +35,8 @@ class Category extends Model {public function sizeHistory(): HasMany {return $this->hasMany(LibrarySizeHistory::class);}++ public function downloadsEnabled(): bool {+ return $this->allow_downloads;+ }}diff --git a/app/Models/Folder.php b/app/Models/Folder.phpindex 6478baf5..a19a8330 100755--- a/app/Models/Folder.php+++ b/app/Models/Folder.php@@ -12,6 +12,17 @@ use Illuminate\Database\Eloquent\Relations\HasOne;class Folder extends Model {use HasFactory;+ /**+ * id -> int8 (pk) (index)+ * category_id -> int8 (fk)+ *+ * name -> varchar(255)+ * path -> varchar(255) (index) (unique)+ *+ * created_at -> timestamp (nullable)+ *+ * last_scan -> int8 (default=0) (unused)+ */public $timestamps = false;protected $casts = [@@ -52,4 +63,12 @@ class Folder extends Model {return $counts->total > 0 && $counts->audio >= ($counts->total / 2);}++ public function downloadsEnabled(): bool {+ if (! $this->category?->downloadsEnabled()) {+ return false;+ }++ return $this->series?->allow_downloads ?? false;+ }}diff --git a/app/Models/Series.php b/app/Models/Series.phpindex b68015b2..86f604c5 100644--- a/app/Models/Series.php+++ b/app/Models/Series.php@@ -69,6 +69,8 @@ class Series extends Model {'updated_at' => 'datetime','edited_at' => 'datetime',++ 'allow_downloads' => 'boolean',];public function folder(): BelongsTo {@@ -97,4 +99,12 @@ class Series extends Model {'thumbnail_url',];}++ public function downloadsEnabled(): bool {+ if (! $this->folder?->category?->downloadsEnabled()) {+ return false;+ }++ return $this->allow_downloads;+ }}diff --git a/app/Models/Video.php b/app/Models/Video.phpindex dc6e4925..0ec368d5 100755--- a/app/Models/Video.php+++ b/app/Models/Video.php@@ -50,4 +50,8 @@ class Video extends Model {public function metadata(): HasOne {return $this->hasOne(Metadata::class);}++ public function downloadsEnabled(): bool {+ return $this->folder?->downloadsEnabled() ?? false;+ }}diff --git a/database/migrations/2026_04_09_213400_add_downloadable_flags_to_libraries_and_folders.php b/database/migrations/2026_04_09_213400_add_downloadable_flags_to_libraries_and_folders.phpnew file mode 100644index 00000000..17c2fa89--- /dev/null+++ b/database/migrations/2026_04_09_213400_add_downloadable_flags_to_libraries_and_folders.php@@ -0,0 +1,34 @@+<?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::table('categories', function (Blueprint $table) {+ $table->boolean('allow_downloads')->default(false);+ $table->boolean('require_login_for_downloads')->default(true);+ });++ Schema::table('series', function (Blueprint $table) {+ $table->boolean('allow_downloads')->default(true);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void {+ Schema::table('categories', function (Blueprint $table) {+ $table->dropColumn(['allow_downloads', 'require_login_for_downloads']);+ });++ Schema::table('series', function (Blueprint $table) {+ $table->dropColumn('allow_downloads');+ });+ }+};