A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
shrug it works it feels scuffed but it works all that is left is activity and websockets
aminnausin7c0cd2afe3e2
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.phpindex 3fd81f15..541c98ec 100755--- a/app/Http/Controllers/DirectoryController.php+++ b/app/Http/Controllers/DirectoryController.php@@ -84,7 +84,6 @@ class DirectoryController extends Controller {new IndexFiles($task->id),];-$videoQuery = Video::orderBy('id');$folderQuery = Folder::orderBy('id');@@ -101,30 +100,11 @@ class DirectoryController extends Controller {$videos = $videoQuery->get();$folders = $folderQuery->get();-- // if ($category) {- // $videos = Video::whereHas('folder.category', function ($query) use ($category) {- // $query->where('id', $category->id);- // })- // ->with('folder.category')- // ->orderBy('id')- // ->get();- // $folders = Folder::whereHas('category', function ($query) use ($category) {- // $query->where('id', $category->id);- // })- // ->with('category')- // ->orderBy('id')- // ->get();- // } else {- // $videos = Video::orderBy('id')->get();- // $folders = Folder::orderBy('id')->get();- // }-- $videos->chunk(20, function ($chunk) use (&$fileChunks, $task) {+ $videos->chunk(20, function ($chunk) use (&$chain, $task) {$chain[] = new VerifyFiles($chunk, $task->id);});- $folders->chunk(20)->each(function ($chunk) use (&$folderChunks, $task) {+ $folders->chunk(20)->each(function ($chunk) use (&$chain, $task) {$chain[] = new VerifyFolders($chunk, $task->id);});@@ -198,42 +178,30 @@ class DirectoryController extends Controller {$task = $this->setupTask($userId, $name, $description);$chain = [];- $videoChunks = [];- $folderChunks = [];++ $videoQuery = Video::orderBy('id');+ $folderQuery = Folder::orderBy('id');if ($category) {- $videos = Video::whereHas('folder.category', function ($query) use ($category) {+ $videoQuery = $videoQuery->whereHas('folder.category', function ($query) use ($category) {$query->where('id', $category->id);- })- ->with('folder.category')- ->orderBy('id')- ->get();- $folders = Folder::whereHas('category', function ($query) use ($category) {+ })->with('folder.category');++ $folderQuery = $folderQuery->whereHas('category', function ($query) use ($category) {$query->where('id', $category->id);- })- ->with('category')- ->orderBy('id')- ->get();- } else {- $folders = Folder::orderBy('id')->get();- $videos = Video::orderBy('id')->get();+ })->with('category');}- $videos->chunk(20, function ($videos) use (&$videoChunks) {- $videoChunks[] = $videos;- });-- $folders->chunk(20)->each(function ($folders) use (&$folderChunks) {- $folderChunks[] = $folders;- });+ $videos = $videoQuery->get();+ $folders = $folderQuery->get();- foreach ($videoChunks as $chunk) {+ $videos->chunk(20, function ($chunk) use (&$chain, $task) {$chain[] = new VerifyFiles($chunk, $task->id);- }+ });- foreach ($folderChunks as $chunk) {- $chain[] = new VerifyFolders($chunk);- }+ $folders->chunk(20)->each(function ($chunk) use (&$chain, $task) {+ $chain[] = new VerifyFolders($chunk, $task->id);+ });$batch = $this->setupBatch($chain, $task);$task->update(['batch_id' => $batch->id, 'sub_tasks_total' => count($chain)]);@@ -256,7 +224,7 @@ class DirectoryController extends Controller {});foreach ($chunks as $chunk) {- $jobs[] = new VerifyFolders($chunk);+ $jobs[] = new VerifyFolders($chunk, 0);// break;}@@ -299,7 +267,7 @@ class DirectoryController extends Controller {}}- function setupTask($userId, $name, $description = '', $taskCount = 0) {+ public static function setupTask($userId, $name, $description = '', $taskCount = 0) {return Task::create(['user_id' => $userId,'name' => $name,@@ -309,7 +277,7 @@ class DirectoryController extends Controller {]);}- function setupBatch($chain, $task) {+ public static function setupBatch($chain, $task) {return Bus::batch($chain)->progress(function (Batch $batch) use ($task) {$task->refresh();$task->update([@@ -391,74 +359,4 @@ class DirectoryController extends Controller {]);})->dispatch();}--- public function verifyFiles2(Request $request, Category $category = null) {- try {- $jobs = [];- $chunks = [];-- if ($category) {- $videos = Video::whereHas('folder.category', function ($query) use ($category) {- $query->where('id', $category->id);- })- ->with('folder.category')- ->orderBy('id')- ->get();- } else {- $videos = Video::orderBy('id')->get();- }-- $videos->chunk(20, function ($videos) use (&$chunks) {- $chunks[] = $videos;- });-- foreach ($chunks as $chunk) {- // $jobs[] = new VerifyFiles($chunk);- // break;- }-- Bus::batch($jobs)->dispatch();- dump('verifyFiles : This job has no web output. Check queue listener console for updates.');- } catch (\Throwable $th) {- dump('Error cannot verify file metadata');- dump($th);- }-- try {- $jobs = [];- $chunks = [];-- // Folder::orderBy('id')->chunk(20, function ($folders) use (&$chunks) {- // $chunks[] = $folders;- // });-- $chunks = [];- if ($category) {- $folders = Folder::whereHas('category', function ($query) use ($category) {- $query->where('id', $category->id);- })- ->with('category')- ->orderBy('id')- ->get();- } else {- $folders = Folder::orderBy('id')->get();- }-- $folders->chunk(20)->each(function ($chunk) use (&$chunks) {- $chunks[] = $chunk;- });-- foreach ($chunks as $chunk) {- $jobs[] = new VerifyFolders($chunk);- // break;- }-- Bus::batch($jobs)->dispatch();- dump('verifyFolders : This job has no web output. Check queue listener console for updates.');- } catch (\Throwable $th) {- dump('Error cannot verify folder series data');- dump($th);- }- }}diff --git a/app/Jobs/EmbedUidInMetadata.php b/app/Jobs/EmbedUidInMetadata.phpindex dea5583f..6d5e8fa9 100644--- a/app/Jobs/EmbedUidInMetadata.php+++ b/app/Jobs/EmbedUidInMetadata.php@@ -2,12 +2,15 @@namespace App\Jobs;+use App\Enums\TaskStatus;+use App\Models\SubTask;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\Attributes\DeleteWhenMissingModels;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;+use Illuminate\Support\Facades\DB;use Symfony\Component\Process\Exception\ProcessFailedException;use Symfony\Component\Process\Process;@@ -16,17 +19,27 @@ class EmbedUidInMetadata implements ShouldQueue {use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;protected $filePath;-protected $uid;+ protected $taskId;+ protected $subTaskId;+/*** Create a new job instance.** @return void*/- public function __construct($filePath, $uid) {+ public function __construct($filePath, $uid, $taskId) {$this->filePath = $filePath;$this->uid = $uid;++ $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Embed UID in video file']); //+ DB::table('tasks')->where('id', $this->taskId)->update([+ 'sub_tasks_pending' => DB::raw('sub_tasks_pending + 1'),+ 'sub_tasks_total' => DB::raw('sub_tasks_total + 1'),+ ]);+ $this->taskId = $taskId;+ $this->subTaskId = $subTask->id;}/**@@ -35,19 +48,37 @@ class EmbedUidInMetadata implements ShouldQueue {* @return void*/public function handle() {+ DB::table('tasks')->where('id', $this->taskId)->decrement('sub_tasks_pending');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::PROCESSING, 'started_at' => now(), 'summary' => "Adding uuid to $this->filePath"]);++ try {+ $summary = $this->handleEmbed();+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_complete');+ SubTask::where('id', $this->subTaskId)->update([+ 'status' => TaskStatus::COMPLETED,+ 'summary' => $summary,+ 'ended_at' => now(),+ 'progress' => 100,+ ]);+ } catch (\Throwable $th) {+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_failed');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::FAILED, 'summary' => "Error: " . $th->getMessage(), 'ended_at' => now()]);+ }+ }++ private function handleEmbed() {$ext = pathinfo($this->filePath, PATHINFO_EXTENSION);dump("Adding uuid to $this->filePath");if (! file_exists($this->filePath)) {dump('UUID Fail file does not exist');-- return;+ throw new \Exception('UUID Fail file does not exist');}$tempFilePath = $this->filePath . '.tmp';- $formatMap = ['mp4' => 'mp4', 'mkv' => 'matroska'];+ $formatMap = ['mp4' => 'mp4', 'mkv' => 'matroska', 'mp3' => 'mp3'];$format = $formatMap[$ext] ?? $ext;$command = [diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.phpindex 71bde539..5fb7df55 100755--- a/app/Jobs/IndexFiles.php+++ b/app/Jobs/IndexFiles.php@@ -2,10 +2,12 @@namespace App\Jobs;+use App\Enums\TaskStatus;use App\Models\Category;use App\Models\Folder;use App\Models\Metadata;use App\Models\Series;+use App\Models\SubTask;use App\Models\Video;use Exception;use FFMpeg\FFProbe as FFMpegFFProbe;@@ -16,6 +18,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;+use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;use Ramsey\Uuid\Uuid;@@ -25,19 +28,47 @@ use Symfony\Component\Process\Process;class IndexFiles implements ShouldBeUnique, ShouldQueue {use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;+ protected $taskId;+ protected $subTaskId;+/*** Create a new job instance.*/- public function __construct() {- //+ public function __construct($taskId) {+ $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Index Files']); //+ $this->taskId = $taskId;+ $this->subTaskId = $subTask->id;}/*** Execute the job.*/public function handle(): void {+ if ($this->batch()->cancelled()) {+ // Determine if the batch has been cancelled...+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled']);+ return;+ }+dump('Starting Index Files');- $this->generateData();+++ DB::table('tasks')->where('id', $this->taskId)->decrement('sub_tasks_pending');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::PROCESSING, 'started_at' => now(), 'summary' => 'Starting Index Files']);++ try {+ $summary = $this->generateData();+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_complete');+ SubTask::where('id', $this->subTaskId)->update([+ 'status' => TaskStatus::COMPLETED,+ 'summary' => $summary,+ 'ended_at' => now(),+ 'progress' => 100,+ ]);+ } catch (\Throwable $th) {+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_failed');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::FAILED, 'summary' => "Error: " . $th->getMessage(), 'ended_at' => now()]);+ }}public function generateData() {@@ -47,7 +78,9 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {if (! Storage::disk('public')->exists($path)) {$error = 'Invalid Directory: "media"';- dd(json_encode(['success' => false, 'result' => '', 'error' => $error], JSON_UNESCAPED_SLASHES));+ throw new \Exception($error);++ // dd(json_encode(['success' => false, 'result' => '', 'error' => $error], JSON_UNESCAPED_SLASHES));}$realPath = Storage::disk('public')->path($path);@@ -194,7 +227,7 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {dump('Categories | Folders | Videos | Changes | SQL ', $directories, ['count' => count($subDirectories['data']['folderStructure'])], ['count' => count($files['data']['videoStructure'])], $data, $dbOut);} catch (\Throwable $th) {dump($th);- throw $th;+ throw new \Exception("Unable to index files, " . $th->getMessage());}}@@ -387,7 +420,7 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {$absolutePath = str_replace('\\', '/', Storage::disk('public')->path('')) . $file;$ext = pathinfo($file, PATHINFO_EXTENSION);- if (strtolower($ext) !== 'mp4' && strtolower($ext) !== 'mkv') {+ if (strtolower($ext) !== 'mp4' && strtolower($ext) !== 'mkv' && strtolower($ext) !== 'mp3') {continue;}diff --git a/app/Jobs/ScheduledIndexFiles.php b/app/Jobs/ScheduledIndexFiles.phpnew file mode 100644index 00000000..6165b373--- /dev/null+++ b/app/Jobs/ScheduledIndexFiles.php@@ -0,0 +1,50 @@+<?php++namespace App\Jobs;++use App\Enums\TaskStatus;+use App\Http\Controllers\DirectoryController;+use Illuminate\Contracts\Queue\ShouldQueue;+use Illuminate\Foundation\Bus\Dispatchable;+use Illuminate\Foundation\Queue\Queueable;+use Illuminate\Queue\InteractsWithQueue;+use Illuminate\Queue\SerializesModels;+use Illuminate\Support\Facades\Log;++class ScheduledIndexFiles implements ShouldQueue {+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;++ /**+ * Create a new job instance.+ */+ public function __construct() {+ //+ }++ /**+ * Execute the job.+ */+ public function handle(): void {+ $this->handleTask();+ }++ public function handleTask() {+ $name = "Scheduled Index Files";+ $description = "Looks for folder and video changes in in all Libraries.";+ try {+ $task = DirectoryController::setupTask(null, $name, $description, 2);+ $chain = [+ new SyncFiles($task->id),+ new IndexFiles($task->id),+ ];++ $batch = DirectoryController::setupBatch($chain, $task);+ $task->update(['batch_id' => $batch->id]);+ // return response()->json(['task_id' => $task->id, 'message' => 'Scheduled Task "INDEX FILES" was started.']);+ } catch (\Throwable $th) {+ if ($task) $task->update(['status' => TaskStatus::FAILED, 'ended_at' => now(), 'summary' => $th->getMessage()]);+ Log::error($th->getMessage());+ // return response()->json(['error' => 'Error cannot index files', 'details' => $th->getMessage()], 500);+ }+ }+}diff --git a/app/Jobs/SyncFiles.php b/app/Jobs/SyncFiles.phpindex 26905b28..7dcd3654 100755--- a/app/Jobs/SyncFiles.php+++ b/app/Jobs/SyncFiles.php@@ -7,7 +7,6 @@ use App\Models\Category;use App\Models\Folder;use App\Models\SubTask;use App\Models\Video;-use Error;use Illuminate\Bus\Batchable;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldBeUnique;@@ -40,7 +39,7 @@ class SyncFiles implements ShouldBeUnique, ShouldQueue {public function handle(): void {if ($this->batch() && $this->batch()->cancelled()) {// Determine if the batch has been cancelled...- SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::CANCELLED]);+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled']);return;}@@ -53,7 +52,7 @@ class SyncFiles implements ShouldBeUnique, ShouldQueue {SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::COMPLETED, 'summary' => '', 'ended_at' => now(), 'progress' => 100]);} catch (\Throwable $th) {DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_failed');- SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::FAILED, 'summary' => "Error: " . $th->getMessage(), 'ended_at' => now(), 'progress' => 100]);+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::FAILED, 'summary' => "Error: " . $th->getMessage(), 'ended_at' => now()]);//throw $th;}}@@ -69,7 +68,7 @@ class SyncFiles implements ShouldBeUnique, ShouldQueue {$error = 'Missing "media" directory in storage';dd(json_encode(['success' => false, 'result' => '', 'error' => $error], JSON_UNESCAPED_SLASHES));- throw new Error($error, 404);+ throw new \Exception($error, 404);}$directories = $this->generateCategories();diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.phpindex a63fa59f..567cde51 100755--- a/app/Jobs/VerifyFiles.php+++ b/app/Jobs/VerifyFiles.php@@ -13,6 +13,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;+use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Storage;use Illuminate\Support\Str;use Ramsey\Uuid\Uuid;@@ -22,7 +23,6 @@ use Symfony\Component\Process\Process;class VerifyFiles implements ShouldQueue {use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;-protected $taskId;protected $subTaskId;@@ -31,7 +31,7 @@ class VerifyFiles implements ShouldQueue {*/public function __construct(public $videos, $taskId) {//- $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Index ' . count($videos) . ' Files']); //+ $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Verify ' . count($videos) . ' Files']); //$this->taskId = $taskId;$this->subTaskId = $subTask->id;}@@ -58,19 +58,38 @@ class VerifyFiles implements ShouldQueue {public function handle(): void {if ($this->batch()->cancelled()) {// Determine if the batch has been cancelled...+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled']);return;}- if (count($this->videos) == 0) {- dump('Video Data Lost');+ DB::table('tasks')->where('id', $this->taskId)->decrement('sub_tasks_pending');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::PROCESSING, 'started_at' => now()]);- return;+ try {+ $summary = $this->verifyFiles();+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_complete');+ SubTask::where('id', $this->subTaskId)->update([+ 'status' => TaskStatus::COMPLETED,+ 'summary' => $summary,+ 'ended_at' => now(),+ 'progress' => 100,+ ]);+ } catch (\Throwable $th) {+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_failed');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::FAILED, 'summary' => "Error: " . $th->getMessage(), 'ended_at' => now()]);}+ }+ private function verifyFiles() {$transactions = [];$error = false;++ if (count($this->videos) == 0) {+ throw new \Exception('Video Data Lost');+ }+try {- foreach ($this->videos as $video) {+ foreach ($this->videos as $index => $video) {$stored = []; // Metadata from db$changes = []; // Changes -> stored + changes . length has to be the same for every video so must generate defaults@@ -84,7 +103,7 @@ class VerifyFiles implements ShouldQueue {if (! Uuid::isValid($uuid ?? '')) {if (! isset($fileMetaData['tags']['uid'])) {$uuid = Str::uuid()->toString();- EmbedUidInMetadata::dispatch($filePath, $uuid);+ EmbedUidInMetadata::dispatch($filePath, $uuid, $this->taskId);} else {$uuid = $fileMetaData['tags']['uid'];dump("Found UUID {$uuid}");@@ -97,8 +116,6 @@ class VerifyFiles implements ShouldQueue {if (! $metadata) {$metadata = Metadata::create(['uuid' => $uuid, 'composite_id' => $compositeId, 'video_id' => $video->id]);- // dump('new');- // $new = true;}$stored = $metadata->toArray();@@ -175,6 +192,8 @@ class VerifyFiles implements ShouldQueue {// dump($changes);// dump($video->name);}+ SubTask::where('id', $this->subTaskId)->update(['progress' => (int) (($index + 1) / count($this->videos) * 100)]);+// dump($metadata->toArray());}} catch (\Throwable $th) {@@ -182,27 +201,33 @@ class VerifyFiles implements ShouldQueue {return $transaction['id'];}, $transactions);- dump('Error cannot verify file metadata ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates with IDs ');- dump([...$ids]);$error = true;- throw $th;+ $errorMessage = 'cannot verify file metadata ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates and ' . count($this->videos) . ' checks with IDs ' . json_encode($ids);+ dump($errorMessage);++ throw new \Exception($errorMessage);}try {if (count($transactions) == 0 || $error == true) {- return;+ return 'No Changes Found';}+Metadata::upsert($transactions, 'id', ['video_id', 'title', 'description', 'duration', 'season', 'episode', 'view_count', 'uuid', 'file_size', 'date_scanned']);- // Video::upsert($transactions, 'id', ['title','duration','season','episode','view_count']);- dump('Updated ' . count($transactions) . ' videos from id ' . ($transactions[0]['video_id']) . ' to ' . ($transactions[count($transactions) - 1]['video_id']));++ $summary = 'Updated ' . count($transactions) . ' videos from id ' . ($transactions[0]['video_id']) . ' to ' . ($transactions[count($transactions) - 1]['video_id']);+ dump($summary);++ return $summary;} catch (\Throwable $th) {$ids = array_map(function ($transaction) {return $transaction['id'];}, $transactions);- dump('Error cannot insert verified file metadata ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates with IDs '); // . [...$ids]);- dump([...$ids]);- throw $th;+ $errorMessage = 'Error cannot insert verified file metadata ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates with IDs ' . json_encode($ids); // . [...$ids]);+ dump($errorMessage);++ throw new \Exception($errorMessage);}}diff --git a/app/Jobs/VerifyFolders.php b/app/Jobs/VerifyFolders.phpindex 437db82d..3b11d9d2 100644--- a/app/Jobs/VerifyFolders.php+++ b/app/Jobs/VerifyFolders.php@@ -2,7 +2,9 @@namespace App\Jobs;+use App\Enums\TaskStatus;use App\Models\Series;+use App\Models\SubTask;use App\Models\Video;use Illuminate\Bus\Batchable;use Illuminate\Bus\Queueable;@@ -10,15 +12,22 @@ use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue;use Illuminate\Queue\SerializesModels;+use Illuminate\Support\Facades\DB;class VerifyFolders implements ShouldQueue {use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;+ protected $taskId;+ protected $subTaskId;++/*** Create a new job instance.*/- public function __construct(public $folders) {- //+ public function __construct(public $folders, $taskId) {+ $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Verify ' . count($folders) . ' Folders']); //+ $this->taskId = $taskId;+ $this->subTaskId = $subTask->id;}/**@@ -27,18 +36,37 @@ class VerifyFolders implements ShouldQueue {public function handle(): void {if ($this->batch()->cancelled()) {// Determine if the batch has been cancelled...+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled']);return;}- if (count($this->folders) == 0) {- dump('Folder Data Lost');+ DB::table('tasks')->where('id', $this->taskId)->decrement('sub_tasks_pending');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::PROCESSING, 'started_at' => now()]);- return;+ try {+ $summary = $this->VerifyFolders();+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_complete');+ SubTask::where('id', $this->subTaskId)->update([+ 'status' => TaskStatus::COMPLETED,+ 'summary' => $summary,+ 'ended_at' => now(),+ 'progress' => 100,+ ]);+ } catch (\Throwable $th) {+ DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_failed');+ SubTask::where('id', $this->subTaskId)->update(['status' => TaskStatus::FAILED, 'summary' => "Error: " . $th->getMessage(), 'ended_at' => now()]);+ }+ }++ private function VerifyFolders() {+ if (count($this->folders) == 0) {+ throw new \Exception('Folder Data Lost');}$transactions = [];$error = false;- foreach ($this->folders as $folder) {++ foreach ($this->folders as $index => $folder) {try {$stored = [];$changes = [];@@ -61,24 +89,36 @@ class VerifyFolders implements ShouldQueue {// dump($changes);// dump($folder->name);}++ SubTask::where('id', $this->subTaskId)->update(['progress' => (int) (($index + 1) / count($this->folders)) * 100]);+// dump($series->toArray());} catch (\Throwable $th) {- //throw $th;- dump('Error cannot verify folder series data ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates');+ $errorMessage = 'Error cannot verify folder series data ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates and ' . count($this->folders) . ' checks';$error = true;- break;++ dump($errorMessage);++ throw new \Exception($errorMessage);}}try {if (count($transactions) == 0 || $error == true) {- return;+ return 'No Changes Found';}+Series::upsert($transactions, 'id', ['folder_id', 'title', 'episodes']);- // Video::upsert($transactions, 'id', ['title','duration','season','episode','view_count']);- dump('Updated ' . count($transactions) . ' folders from id ' . ($transactions[0]['folder_id']) . ' to ' . ($transactions[count($transactions) - 1]['folder_id']));++ $summary = 'Updated ' . count($transactions) . ' folders from id ' . ($transactions[0]['folder_id']) . ' to ' . ($transactions[count($transactions) - 1]['folder_id']);+ dump($summary);++ return $summary;} catch (\Throwable $th) {- dump('Error cannot insert verified folder series data ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates');+ $errorMessage = 'Error cannot insert verified folder series data ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates'; // . [...$ids]);+ dump($errorMessage);++ throw new \Exception($errorMessage);}}}diff --git a/database/migrations/2024_12_24_064632_create_activity_table.php b/database/migrations/2024_12_24_064632_create_activity_table.php.baksimilarity index 100%rename from database/migrations/2024_12_24_064632_create_activity_table.phprename to database/migrations/2024_12_24_064632_create_activity_table.php.bakdiff --git a/database/migrations/2024_12_28_180714_connect_tasks_to_jobs_and_batches.php b/database/migrations/2024_12_28_180714_connect_tasks_to_jobs_and_batches.phpdeleted file mode 100644index 9eb1c297..00000000--- a/database/migrations/2024_12_28_180714_connect_tasks_to_jobs_and_batches.php+++ /dev/null@@ -1,42 +0,0 @@-<?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('tasks', function (Blueprint $table) {- $table->string('batch_id')->nullable()->after('user_id');- $table->foreign('batch_id')->references('id')->on('job_batches')->nullOnDelete();- $table->unsignedSmallInteger('total_sub_tasks')->default(0)->after('status');- $table->dropColumn('sub_tasks');- // $table->dropColumn('sub_tasks_pending');- // $table->dropColumn('sub_tasks_complete');- // $table->dropColumn('sub_tasks_failed');- });-- Schema::table('sub_tasks', function (Blueprint $table) {- });- }-- /**- * Reverse the migrations.- */- public function down(): void {- Schema::table('tasks', function (Blueprint $table) {- $table->dropForeign(['batch_id']);- $table->dropColumn('batch_id');- $table->unsignedSmallInteger('sub_tasks')->default(0);- // $table->unsignedSmallInteger('sub_tasks_pending')->default(0);- // $table->unsignedSmallInteger('sub_tasks_complete')->default(0);- // $table->unsignedSmallInteger('sub_tasks_failed')->default(0);- });-- Schema::table('sub_tasks', function (Blueprint $table) {- });- }-};diff --git a/resources/js/components/cards/SubTaskCard.vue b/resources/js/components/cards/SubTaskCard.vueindex f3082b33..d3aa3acc 100644--- a/resources/js/components/cards/SubTaskCard.vue+++ b/resources/js/components/cards/SubTaskCard.vue@@ -31,17 +31,21 @@ const props = defineProps<{ data: SubTaskResource }>();<sectionclass="bg-white dark:bg-primary-dark-800/70 dark:hover:bg-primary-dark-600 hover:bg-primary-800 p-3 rounded-xl ring-1 ring-gray-900/5 flex gap-4 w-full items-center flex-wrap">- <div class="flex flex-col gap-2 sm:gap-1 flex-1">+ <div class="relative group flex flex-col gap-2 sm:gap-1 flex-1"><div class="flex gap-x-4 gap-y-2 items-center"><h2 class="truncate capitalize group" :title="data.name">{{ data.name }}</h2>- <p- v-if="data.summary"- class="flex justify-end gap-1 flex-1 line-clamp-3 sm:line-clamp-1 text-wrap text-ellipsis sm:text-nowrap text-neutral-500 dark:text-neutral-400"- >+ <p v-if="data.summary" class="truncate text-neutral-500 dark:text-neutral-400 max-w-64">{{ data.summary }}</p>+ <div+ v-if="(data.summary?.length ?? 0) > 0"+ class="flex z-30 left-20 bottom-10 absolute opacity-0 group-hover:opacity-100 transition-opacity ease-in-out duration-500 w-1/2 text-sm p-3 bg-white dark:odd:bg-primary-dark-600/70 dark:bg-neutral-800/70 backdrop-blur-lg border dark:border-none rounded-md shadow-md border-neutral-200/70 gap-2 items-center"+ >+ <ProiconsCommentExclamation class="h-4 w-4" />+ <p class="text-wrap">{{ data.summary }}</p>+ </div></div><div class="flex gap-x-8 gap-y-2 flex-wrap"><h4 class="text-xs text-neutral-500 dark:text-neutral-400 truncate line-clamp-1 capitalize" title="">diff --git a/resources/js/components/cards/TaskCard.vue b/resources/js/components/cards/TaskCard.vueindex 273706f0..49807853 100644--- a/resources/js/components/cards/TaskCard.vue+++ b/resources/js/components/cards/TaskCard.vue@@ -241,7 +241,7 @@ const expanded = ref(false);</section><section- :class="`flex flex-col overflow-hidden transition-all duration-300 ease-in-out ${expanded ? `py-1` : ''}`"+ :class="`flex flex-col transition-all duration-300 ease-in-out ${expanded ? `py-1` : 'overflow-hidden '}`":style="`height: ${expanded ? `${Math.max(52, (data?.sub_tasks?.length ?? 0) * (68 + 4))}px` : '0px'};`"><SubTaskCard v-for="subTask in data.sub_tasks" :key="subTask.id" :data="subTask" />diff --git a/routes/console.php b/routes/console.phpindex 62c8d504..f654987e 100755--- a/routes/console.php+++ b/routes/console.php@@ -1,6 +1,6 @@<?php-use App\Jobs\IndexFiles;+use App\Jobs\ScheduledIndexFiles;// use Illuminate\Foundation\Inspiring;// use Illuminate\Support\Facades\Artisan;use Illuminate\Support\Facades\Schedule;@@ -9,5 +9,5 @@ use Illuminate\Support\Facades\Schedule;// $this->comment(Inspiring::quote());// })->purpose('Display an inspiring quote')->hourly();-Schedule::job(new IndexFiles)->everySixHours()->environments(['staging', 'production']);+Schedule::job(new ScheduledIndexFiles)->everySixHours()->environments(['staging', 'production']);Schedule::command('sanctum:prune-expired --hours=2')->daily();diff --git a/vite.config.js.timestamp-1735501271331-455aa6932cfdb.mjs b/vite.config.js.timestamp-1735501271331-455aa6932cfdb.mjsnew file mode 100644index 00000000..7b691d95--- /dev/null+++ b/vite.config.js.timestamp-1735501271331-455aa6932cfdb.mjs@@ -0,0 +1,35 @@+// vite.config.js+import { defineConfig } from "file:///O:/Documents/Projects/mediaServer/node_modules/vite/dist/node/index.js";+import laravel from "file:///O:/Documents/Projects/mediaServer/node_modules/laravel-vite-plugin/dist/index.js";+import Icons from "file:///O:/Documents/Projects/mediaServer/node_modules/unplugin-icons/dist/vite.js";+import vue from "file:///O:/Documents/Projects/mediaServer/node_modules/@vitejs/plugin-vue/dist/index.mjs";+var vite_config_default = defineConfig({+ plugins: [+ laravel({+ input: ["resources/css/app.css", "resources/js/app.ts"],+ refresh: true+ }),+ vue({+ template: {+ transformAssetUrls: {+ base: null,+ includeAbsolute: false+ }+ }+ }),+ Icons({+ // experimental+ autoInstall: true+ })+ ],+ resolve: {+ alias: {+ vue: "vue/dist/vue.esm-bundler.js"+ // '@': fileURLToPath(new URL('./src', import.meta.url)),+ }+ }+});+export {+ vite_config_default as default+};+//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcuanMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCJPOlxcXFxEb2N1bWVudHNcXFxcUHJvamVjdHNcXFxcbWVkaWFTZXJ2ZXJcIjtjb25zdCBfX3ZpdGVfaW5qZWN0ZWRfb3JpZ2luYWxfZmlsZW5hbWUgPSBcIk86XFxcXERvY3VtZW50c1xcXFxQcm9qZWN0c1xcXFxtZWRpYVNlcnZlclxcXFx2aXRlLmNvbmZpZy5qc1wiO2NvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9pbXBvcnRfbWV0YV91cmwgPSBcImZpbGU6Ly8vTzovRG9jdW1lbnRzL1Byb2plY3RzL21lZGlhU2VydmVyL3ZpdGUuY29uZmlnLmpzXCI7Ly8gaW1wb3J0IHsgZmlsZVVSTFRvUGF0aCwgVVJMIH0gZnJvbSAnbm9kZTp1cmwnO1xuaW1wb3J0IHsgZGVmaW5lQ29uZmlnIH0gZnJvbSAndml0ZSc7XG5cbmltcG9ydCBsYXJhdmVsIGZyb20gJ2xhcmF2ZWwtdml0ZS1wbHVnaW4nO1xuaW1wb3J0IEljb25zIGZyb20gJ3VucGx1Z2luLWljb25zL3ZpdGUnO1xuaW1wb3J0IHZ1ZSBmcm9tICdAdml0ZWpzL3BsdWdpbi12dWUnO1xuXG5leHBvcnQgZGVmYXVsdCBkZWZpbmVDb25maWcoe1xuICAgIHBsdWdpbnM6IFtcbiAgICAgICAgbGFyYXZlbCh7XG4gICAgICAgICAgICBpbnB1dDogWydyZXNvdXJjZXMvY3NzL2FwcC5jc3MnLCAncmVzb3VyY2VzL2pzL2FwcC50cyddLFxuICAgICAgICAgICAgcmVmcmVzaDogdHJ1ZSxcbiAgICAgICAgfSksXG4gICAgICAgIHZ1ZSh7XG4gICAgICAgICAgICB0ZW1wbGF0ZToge1xuICAgICAgICAgICAgICAgIHRyYW5zZm9ybUFzc2V0VXJsczoge1xuICAgICAgICAgICAgICAgICAgICBiYXNlOiBudWxsLFxuICAgICAgICAgICAgICAgICAgICBpbmNsdWRlQWJzb2x1dGU6IGZhbHNlLFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB9LFxuICAgICAgICB9KSxcbiAgICAgICAgSWNvbnMoe1xuICAgICAgICAgICAgLy8gZXhwZXJpbWVudGFsXG4gICAgICAgICAgICBhdXRvSW5zdGFsbDogdHJ1ZSxcbiAgICAgICAgfSksXG4gICAgXSxcbiAgICByZXNvbHZlOiB7XG4gICAgICAgIGFsaWFzOiB7XG4gICAgICAgICAgICB2dWU6ICd2dWUvZGlzdC92dWUuZXNtLWJ1bmRsZXIuanMnLFxuICAgICAgICAgICAgLy8gJ0AnOiBmaWxlVVJMVG9QYXRoKG5ldyBVUkwoJy4vc3JjJywgaW1wb3J0Lm1ldGEudXJsKSksXG4gICAgICAgIH0sXG4gICAgfSxcbn0pO1xuIl0sCiAgIm1hcHBpbmdzIjogIjtBQUNBLFNBQVMsb0JBQW9CO0FBRTdCLE9BQU8sYUFBYTtBQUNwQixPQUFPLFdBQVc7QUFDbEIsT0FBTyxTQUFTO0FBRWhCLElBQU8sc0JBQVEsYUFBYTtBQUFBLEVBQ3hCLFNBQVM7QUFBQSxJQUNMLFFBQVE7QUFBQSxNQUNKLE9BQU8sQ0FBQyx5QkFBeUIscUJBQXFCO0FBQUEsTUFDdEQsU0FBUztBQUFBLElBQ2IsQ0FBQztBQUFBLElBQ0QsSUFBSTtBQUFBLE1BQ0EsVUFBVTtBQUFBLFFBQ04sb0JBQW9CO0FBQUEsVUFDaEIsTUFBTTtBQUFBLFVBQ04saUJBQWlCO0FBQUEsUUFDckI7QUFBQSxNQUNKO0FBQUEsSUFDSixDQUFDO0FBQUEsSUFDRCxNQUFNO0FBQUE7QUFBQSxNQUVGLGFBQWE7QUFBQSxJQUNqQixDQUFDO0FBQUEsRUFDTDtBQUFBLEVBQ0EsU0FBUztBQUFBLElBQ0wsT0FBTztBQUFBLE1BQ0gsS0FBSztBQUFBO0FBQUEsSUFFVDtBQUFBLEVBQ0o7QUFDSixDQUFDOyIsCiAgIm5hbWVzIjogW10KfQo=