A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: simple library size tracking
aminnausin461892db137d
diff --git a/app/Models/Category.php b/app/Models/Category.phpindex 55b7212e..12cd599a 100755--- a/app/Models/Category.php+++ b/app/Models/Category.php@@ -26,4 +26,8 @@ class Category extends Model {public function editor(): BelongsTo {return $this->belongsTo(User::class);}++ public function sizeHistory(): HasMany {+ return $this->hasMany(LibrarySizeHistory::class);+ }}diff --git a/app/Models/LibrarySizeHistory.php b/app/Models/LibrarySizeHistory.phpnew file mode 100644index 00000000..e58412ea--- /dev/null+++ b/app/Models/LibrarySizeHistory.php@@ -0,0 +1,12 @@+<?php++namespace App\Models;++use Illuminate\Database\Eloquent\Model;+use Illuminate\Database\Eloquent\Relations\BelongsTo;++class LibrarySizeHistory extends Model {+ public function library(): BelongsTo {+ return $this->belongsTo(Category::class);+ }+}diff --git a/database/migrations/2026_02_01_222526_create_series_size_history_table.php b/database/migrations/2026_02_01_222526_create_series_size_history_table.phpindex edfbabcd..61592509 100644--- a/database/migrations/2026_02_01_222526_create_series_size_history_table.php+++ b/database/migrations/2026_02_01_222526_create_series_size_history_table.php@@ -25,7 +25,7 @@ return new class extends Migration {id,total_size,GREATEST(COALESCE(file_count, 0), COALESCE(episodes, 0)),- NOW()+ updated_at AS recorded_atFROM seriesWHERE total_size IS NOT NULLAND folder_id IS NOT NULL;diff --git a/database/migrations/2026_02_01_222730_create_library_size_history_table.php b/database/migrations/2026_02_01_222730_create_library_size_history_table.phpnew file mode 100644index 00000000..0f63b446--- /dev/null+++ b/database/migrations/2026_02_01_222730_create_library_size_history_table.php@@ -0,0 +1,44 @@+<?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 {+ /**+ * Run the migrations.+ */+ public function up(): void {+ Schema::create('library_size_histories', function (Blueprint $table) {+ $table->id();+ $table->foreignId('category_id')->constrained()->cascadeOnDelete();+ $table->unsignedBigInteger('total_bytes');+ $table->unsignedInteger('folder_count');+ $table->unsignedInteger('file_count');+ $table->timestampTz('recorded_at');+ $table->timestamptz('created_at')->default(now());+ });++ DB::statement('+ INSERT INTO library_size_histories (category_id, total_bytes, folder_count, file_count, recorded_at)+ SELECT+ c.id AS category_id,+ COALESCE(SUM(s.total_size), 0) AS total_bytes,+ COUNT(DISTINCT f.id) AS folder_count,+ COALESCE(SUM(GREATEST(COALESCE(s.file_count, 0), COALESCE(s.episodes, 0))), 0) AS file_count,+ COALESCE(MAX(s.updated_at), NOW()) AS recorded_at+ FROM categories c+ LEFT JOIN folders f ON f.category_id = c.id+ LEFT JOIN series s ON s.folder_id = f.id+ GROUP BY c.id;+ ');+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void {+ Schema::dropIfExists('library_size_histories');+ }+};