Skip to content

A self-hosted media server and file management system

Fix job counts and uid to uuid

aminnausine86fa55d5704
diff --git a/app/Events/TaskUpdated.php b/app/Events/TaskUpdated.php
index f2df7fb1..b7a8ee47 100644
--- a/app/Events/TaskUpdated.php
+++ b/app/Events/TaskUpdated.php
@@ -9,6 +9,7 @@ use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
+use Illuminate\Support\Facades\Log;
class TaskUpdated implements ShouldBroadcast {
use Dispatchable, InteractsWithSockets, SerializesModels;
@@ -39,6 +40,8 @@ class TaskUpdated implements ShouldBroadcast {
];
} catch (\Throwable $th) {
dump($th->getMessage());
+ Log::error('Unable to broadcast task update', ['error' => $th->getMessage()]);
+ throw $th;
}
}
@@ -46,6 +49,12 @@ class TaskUpdated implements ShouldBroadcast {
* Get the data to broadcast.
*/
public function broadcastWith(): array {
- return ['task' => new TasksResource($this->task)];
+ try {
+ return ['task' => new TasksResource($this->task)];
+ } catch (\Throwable $th) {
+ dump($th->getMessage());
+ Log::error('Unable to broadcast task update', ['error' => $th->getMessage()]);
+ throw $th;
+ }
}
}
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php
index 2f834061..10b4779f 100755
--- a/app/Http/Controllers/DirectoryController.php
+++ b/app/Http/Controllers/DirectoryController.php
@@ -9,6 +9,7 @@ use App\Http\Resources\SeriesResource;
use App\Http\Resources\VideoResource;
use App\Jobs\CleanFolderPaths;
use App\Jobs\CleanVideoPaths;
+use App\Jobs\EmbedUidInMetadata;
use App\Jobs\IndexFiles;
use App\Jobs\SyncFiles;
use App\Jobs\VerifyFiles;
@@ -44,8 +45,7 @@ class DirectoryController extends Controller {
$folderName = trim(strtolower($request?->folderName ?? ''));
if (isset($privateCategories[$dir]) && (! $request->user('sanctum') || (Auth::user() && Auth::user()->id !== 1))) {
-
- return $this->error(null, "Access to this folder is forbidden", 403);
+ return $this->error(null, 'Access to this folder is forbidden', 403);
}
$dirRaw = Category::select('id', 'default_folder_id')->firstWhere('name', 'ilike', '%' . $dir . '%');
@@ -310,6 +310,39 @@ class DirectoryController extends Controller {
}
}
+ /**
+ * Embed UIDs in file metadata
+ * Unused?
+ *
+ * @param array<array{path: string, uuid: string}> $files
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function embedUIDs(int $taskId, string $name, array $files) {
+ $description = 'Embeds UIDs in file metadata.';
+ $lastTask = Task::find($taskId);
+ try {
+ $userId = $lastTask ? $lastTask->user_id : null;
+ $task = $this->setupTask($userId, $name, $description);
+
+ $chain = [];
+ foreach ($files as $key => $file) {
+ $chain[] = new EmbedUidInMetadata($file['path'], $file['uuid'], $task->id);
+ }
+
+ $batch = $this->setupBatch($chain, $task);
+ $task->update(['batch_id' => $batch->id, 'sub_tasks_total' => count($chain), 'sub_tasks_pending' => count($chain)]);
+
+ return response()->json(['task_id' => $task->id, 'message' => 'Async Task "EMBED UIDS" was started.']);
+ } catch (\Throwable $th) {
+ if ($task) {
+ $task->update(['status' => TaskStatus::FAILED, 'ended_at' => now()]);
+ }
+
+ return response()->json(['error' => 'Error cannot embed UIDs', 'details' => $th->getMessage()], 500);
+ // dump($th);
+ }
+ }
+
public function setupTask($userId, $name, $description = '', $taskCount = 0) {
return $this->taskService->createTask([
'user_id' => $userId,
@@ -336,7 +369,14 @@ class DirectoryController extends Controller {
Log::error('Batch failed', ['task_id' => $task->id, 'error' => $e->getMessage()]);
})->finally(function (Batch $batch) use ($task) {
$task->refresh();
- $status = $task->status !== TaskStatus::PROCESSING ? $task->status : ($batch->cancelled() ? TaskStatus::CANCELLED : ($batch->processedJobs() > $task->sub_tasks_total ? TaskStatus::INCOMPLETE : TaskStatus::COMPLETED));
+ // if task is not still processing, don't change what the current status is
+ // otherwise base status on batch info
+ $status = $task->status !== TaskStatus::PROCESSING || $task->sub_tasks_total !== $batch->totalJobs ?
+ $task->status : ($batch->cancelled() ?
+ TaskStatus::CANCELLED : ($batch->processedJobs() > $task->sub_tasks_total ?
+ TaskStatus::INCOMPLETE :
+ TaskStatus::COMPLETED
+ ));
$ended_at = now();
try {
diff --git a/app/Jobs/EmbedUidInMetadata.php b/app/Jobs/EmbedUidInMetadata.php
index 1b7ab166..a20c3688 100644
--- a/app/Jobs/EmbedUidInMetadata.php
+++ b/app/Jobs/EmbedUidInMetadata.php
@@ -3,15 +3,17 @@
namespace App\Jobs;
use App\Enums\TaskStatus;
-use App\Models\SubTask;
use App\Models\Task;
+use App\Models\Video;
use App\Services\TaskService;
+use Illuminate\Bus\Batchable;
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\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -19,16 +21,18 @@ use Symfony\Component\Process\Process;
#[DeleteWhenMissingModels]
class EmbedUidInMetadata implements ShouldQueue {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+ use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $filePath;
- protected $uid;
+ protected $uuid;
protected $taskId;
protected $subTaskId;
+ protected $videoId;
+
protected $startedAt;
protected $taskService;
@@ -38,33 +42,16 @@ class EmbedUidInMetadata implements ShouldQueue {
*
* @return void
*/
- public function __construct($filePath, $uid, $taskId) {
+ public function __construct($filePath, $uuid, $taskId, $videoId = null) {
$this->filePath = $filePath;
- $this->uid = $uid;
+ $this->uuid = $uuid;
+ $this->videoId = $videoId;
- $subTask = SubTask::create(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Embed UID in video file ' . basename($filePath)]); //
+ $this->taskService = App::make(TaskService::class);
+ $subTask = $this->taskService->createSubTask(['task_id' => $taskId, 'status' => TaskStatus::PENDING, 'name' => 'Embed UID in video file ' . basename($filePath)]);
$this->taskId = $taskId;
$this->subTaskId = $subTask->id;
-
- // Start a database transaction
- DB::beginTransaction();
-
- try {
- // Decrement the sub_tasks_pending only if it's greater than zero
- DB::table('tasks')
- ->where('id', $taskId)
- ->update([
- 'sub_tasks_pending' => DB::raw('sub_tasks_pending + 1'),
- 'sub_tasks_total' => DB::raw('sub_tasks_total + 1'),
- ]);
-
- // Commit the transaction
- DB::commit();
- } catch (\Exception $e) {
- DB::rollBack();
- throw $e;
- }
}
/**
@@ -73,42 +60,23 @@ class EmbedUidInMetadata implements ShouldQueue {
public function handle(TaskService $taskService): void {
$this->taskService = $taskService;
- $this->startedAt = now();
-
- DB::beginTransaction();
+ if ($this->batch()?->cancelled() || (($task = Task::find($this->taskId)) && $task->status == TaskStatus::CANCELLED)) {
+ // Determine if the batch or parent task has been cancelled...
+ $this->taskService->updateSubTask($this->subTaskId, ['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled']);
- try {
- DB::table('tasks')
- ->where('id', $this->taskId)
- ->where('sub_tasks_pending', '>', 0)
- ->decrement('sub_tasks_pending');
-
- DB::commit();
- } catch (\Exception $e) {
- DB::rollBack();
- Log::error($e);
+ return;
}
+ $this->startedAt = now();
+ $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_pending' => '--']);
$this->taskService->updateSubTask($this->subTaskId, ['status' => TaskStatus::PROCESSING, 'started_at' => $this->startedAt, 'summary' => "Adding uuid to $this->filePath"]);
try {
$summary = $this->handleEmbed();
$endedAt = now();
$duration = (int) $this->startedAt->diffInSeconds($endedAt);
- // $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++'], false);
- $task = Task::where('id', $this->taskId)->first();
-
- if ($task) {
- if ($task->sub_tasks_complete == $task->sub_tasks_total - 1) {
- $task->update([
- 'sub_tasks_complete' => DB::raw('sub_tasks_complete + 1'),
- 'status' => TaskStatus::COMPLETED,
- ]);
- } else {
- $task->increment('sub_tasks_complete');
- }
- }
+ $task = $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++'], false);
$this->taskService->updateSubTask($this->subTaskId, [
'status' => TaskStatus::COMPLETED,
'summary' => $summary,
@@ -116,26 +84,56 @@ class EmbedUidInMetadata implements ShouldQueue {
'ended_at' => $endedAt,
'duration' => $duration,
]);
+
+ if ($this->videoId) {
+ Video::where('id', $this->videoId)->update(['uuid' => $this->uuid]);
+ }
+
+ if ($this->batch()) {
+ return;
+ }
+
+ // Update the parent task if this was dispatched and not batched
+
+ // Task not found or there are still pending tasks
+ if (! $task || $task->sub_tasks_pending != 0) {
+ return;
+ }
+ if ($task->sub_tasks_complete < $task->sub_tasks_total) {
+ $this->taskService->updateTask($this->taskId, ['status' => TaskStatus::INCOMPLETE], true);
+ return;
+ }
+
+ $this->taskService->updateTask($this->taskId, ['status' => TaskStatus::COMPLETED], true);
} catch (\Throwable $th) {
$endedAt = now();
$duration = (int) $this->startedAt->diffInSeconds($endedAt);
dump($th->getMessage());
$this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_failed' => '++']);
$this->taskService->updateSubTask($this->subTaskId, ['status' => TaskStatus::FAILED, 'summary' => 'Error: ' . $th->getMessage(), 'ended_at' => $endedAt, 'duration' => $duration]);
- throw $th;
+ if ($this->batch()) {
+ throw $th;
+ }
+ $this->taskService->updateTask($this->taskId, ['status' => TaskStatus::FAILED], true);
+ Log::error('Task Failed', ['task_id' => $this->taskId, 'subtask_id' => $this->subTaskId, 'error' => $th->getMessage()]);
}
}
private function handleEmbed() {
$ext = pathinfo($this->filePath, PATHINFO_EXTENSION);
- dump("Adding uuid to $this->filePath");
+ dump("Adding uuid $this->uuid to $this->filePath");
if (! file_exists($this->filePath)) {
dump('UUID Fail file does not exist');
throw new \Exception('UUID Fail file does not exist');
}
+ if (! uuid_is_valid($this->uuid)) {
+ dump('Invalid UUID');
+ throw new \Exception('Invalid UUID');
+ }
+
$tempFilePath = $this->filePath . '.tmp';
$formatMap = ['mp4' => 'mp4', 'mkv' => 'matroska', 'mp3' => 'mp3', 'ogg' => 'opus', 'flac' => 'flac'];
@@ -150,7 +148,7 @@ class EmbedUidInMetadata implements ShouldQueue {
'-movflags',
'use_metadata_tags',
'-metadata',
- "uid=$this->uid",
+ "uuid=$this->uuid",
'-f',
$format,
$tempFilePath,
@@ -207,6 +205,9 @@ class EmbedUidInMetadata implements ShouldQueue {
}
dump($metadata);
- return isset($metadata['format']['tags']['uid']) ? $metadata['format']['tags']['uid'] : (isset($metadata['format']['tags']['UID']) ? $metadata['format']['tags']['UID'] : null);
+ // Tag was previously uid
+ $uid = isset($metadata['format']['tags']['uid']) ? $metadata['format']['tags']['uid'] : (isset($metadata['format']['tags']['UID']) ? $metadata['format']['tags']['UID'] : null);
+
+ return isset($metadata['format']['tags']['uuid']) ? $metadata['format']['tags']['uuid'] : $uid;
}
}
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index 2a10e5b3..02e64da6 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -11,7 +11,6 @@ use App\Models\SubTask;
use App\Models\Video;
use App\Services\TaskService;
use Exception;
-use FFMpeg\FFProbe as FFMpegFFProbe;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
@@ -19,9 +18,8 @@ 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\Bus;
use Illuminate\Support\Facades\File;
-use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Ramsey\Uuid\Uuid;
@@ -39,6 +37,8 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
protected $taskService;
+ protected $embedChain = [];
+
/**
* Create a new job instance.
*/
@@ -71,7 +71,18 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
$summary = $this->generateData();
$endedAt = now();
$duration = (int) $this->startedAt->diffInSeconds($endedAt);
- $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++'], false);
+
+ if (count($this->embedChain)) {
+ $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++', 'sub_tasks_total' => count($this->embedChain), 'sub_tasks_pending' => count($this->embedChain)]);
+ foreach ($this->embedChain as $key => $embedTask) {
+ Bus::dispatch($embedTask);
+ }
+ // $controller = new DirectoryController($this->taskService);
+ // $controller->embedUIDs($this->taskId, "Embed UIDs for task $this->taskId via Index Files", $this->embedChain);
+ } else {
+ $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++'], false);
+ }
+
$this->taskService->updateSubTask($this->subTaskId, [
'status' => TaskStatus::COMPLETED,
'summary' => $summary,
@@ -443,11 +454,15 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
continue;
}
- $fileMetaData = $this->getFileMetadata($absolutePath);
- $uuid = isset($fileMetaData['format']['tags']['uid']) ? $fileMetaData['format']['tags']['uid'] : (isset($fileMetaData['format']['tags']['UID']) ? $fileMetaData['format']['tags']['UID'] : null);
+ $fileMetaData = VerifyFiles::getFileMetadata($absolutePath);
+ $uuid = isset($fileMetaData['tags']['uuid']) ? $fileMetaData['tags']['uuid'] : (isset($fileMetaData['tags']['uid']) ? $fileMetaData['tags']['uid'] : null);
+ $embeddingUuid = false;
if (! $uuid || ! Uuid::isValid($uuid)) {
$uuid = Str::uuid()->toString();
- EmbedUidInMetadata::dispatch($absolutePath, $uuid, $this->taskId);
+ $this->embedChain[] = new EmbedUidInMetadata($absolutePath, $uuid, $this->taskId, $currentID);
+ $embeddingUuid = true;
+ // $this->embedChain[] = ["path" => $absolutePath, "uid" => $uuid];
+ // EmbedUidInMetadata::dispatch($absolutePath, $uuid, $this->taskId);
}
$name = basename($file);
@@ -460,8 +475,9 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
} else {
$mime_type = File::mimeType($absolutePath) ?? null;
- $generated = ['id' => $currentID, 'uuid' => $uuid, 'name' => $cleanName, 'path' => $key, 'folder_id' => $folderStructure[$folder]['id'], 'date' => date('Y-m-d h:i A', filemtime($rawFile)), 'action' => 'INSERT'];
- $metadata = ['video_id' => $currentID, 'composite_id' => "$folder/$name", 'uuid' => $uuid, 'file_size' => filesize($rawFile), 'duration' => isset($fileMetaData['format']['duration']) ? (int) $fileMetaData['format']['duration'] : null, 'mime_type' => $mime_type ?? null, 'date_scanned' => date('Y-m-d h:i:s A')];
+ // Dont add uuid to video if embedding job is to be scheduled. This prevents not knowing if the uuid was applied to the video in case a job fails.
+ $generated = ['id' => $currentID, 'uuid' => $embeddingUuid ? null : $uuid, 'name' => $cleanName, 'path' => $key, 'folder_id' => $folderStructure[$folder]['id'], 'date' => date('Y-m-d h:i A', filemtime($rawFile)), 'action' => 'INSERT'];
+ $metadata = ['video_id' => $currentID, 'composite_id' => "$folder/$name", 'uuid' => $uuid, 'file_size' => filesize($rawFile), 'duration' => isset($fileMetaData['duration']) ? (int) $fileMetaData['duration'] : null, 'mime_type' => $mime_type ?? null, 'date_scanned' => date('Y-m-d h:i:s A')];
$current[$key] = $currentID; // add to current
array_push($changes, $generated); // add to new (insert)
array_push($metadataChanges, $metadata); // create metadata (insert)
@@ -493,89 +509,6 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
return ['videoChanges' => $changes, 'data' => $data, 'cost' => $cost, 'updatedFolderStructure' => $foldersCopy, 'metadataChanges' => $metadataChanges];
}
- // Not Using
- private function getUidFromMetadata($filePath) {
- $command = [
- 'ffprobe',
- '-v',
- 'quiet',
- '-print_format',
- 'json',
- '-show_format',
- $filePath,
- ];
-
- try {
- // ? FFMPEG module with 6 test folders takes 35+ seconds but running the commands through shell takes 18 seconds
- // $ffprobe = FFMpegFFProbe::create();
- // $tags = $ffprobe->format($filePath)->get('tags'); // extracts file information
- // return isset($tags['uid']) ? $tags['uid'] : (isset($tags['UID']) ? $tags['UID'] : null);
-
- $process = new Process($command);
- $process->run();
-
- // Check if the process was successful
- if (! $process->isSuccessful()) {
- throw new ProcessFailedException($process);
- }
-
- $output = $process->getOutput(); // Decode JSON output
- // dd($output);
- $metadata = json_decode($output, true);
- dump($metadata);
- // dd($metadata);
- // dump(isset($metadata['format']['tags']['uid']) ? $metadata['format']['tags']['uid'] : 'help');
- } catch (\Throwable $th) {
- dump($th);
-
- return null;
- }
-
- return isset($metadata['format']['tags']['uid']) ? $metadata['format']['tags']['uid'] : (isset($metadata['format']['tags']['UID']) ? $metadata['format']['tags']['UID'] : null);
- }
-
- private function getFileMetadata($filePath) {
- try {
- // ? FFMPEG module with 6 test folders takes 35+ seconds but running the commands through shell takes 18 seconds
- // $ffprobe = FFMpegFFProbe::create();
- // $tags = $ffprobe->format($filePath)->get('tags'); // extracts file information
- // return isset($tags['uid']) ? $tags['uid'] : (isset($tags['UID']) ? $tags['UID'] : null);
-
- $ext = pathinfo($filePath, PATHINFO_EXTENSION);
-
- $command = [
- 'ffprobe',
- '-v',
- 'quiet',
- '-print_format',
- 'json',
- '-show_format',
- '-show_streams',
- $filePath,
- ];
-
- $process = new Process($command);
- $process->run();
-
- // Check if the process was successful
- if (! $process->isSuccessful()) {
- throw new ProcessFailedException($process);
- }
-
- $output = $process->getOutput(); // Decode JSON output
- $metadata = json_decode($output, true);
- if ($ext === 'ogg') {
- $metadata['format'] = $metadata['streams'][0] ?? [];
- }
-
- return $metadata;
- } catch (\Throwable $th) {
- dump($th);
-
- return [];
- }
- }
-
// Not Using
private function embedUidInMetadataDirect($filePath, $uid) {
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
@@ -623,9 +556,8 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {
}
}
- // Define the custom function to handle the upsert logic
public function upsertMetadata($data) {
- // Attempt to update by UUID first
+ // update by UUID first
try {
$metadata = Metadata::where('uuid', $data['uuid'])->first();
diff --git a/app/Jobs/ScheduledIndexFiles.php b/app/Jobs/ScheduledIndexFiles.php
index 2e8af036..9287bfa4 100644
--- a/app/Jobs/ScheduledIndexFiles.php
+++ b/app/Jobs/ScheduledIndexFiles.php
@@ -4,6 +4,7 @@ namespace App\Jobs;
use App\Enums\TaskStatus;
use App\Http\Controllers\DirectoryController;
+use App\Services\TaskService;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Queue\Queueable;
@@ -14,11 +15,11 @@ use Illuminate\Support\Facades\Log;
class ScheduledIndexFiles implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * Create a new job instance.
- */
+ protected $controller;
+
public function __construct() {
- //
+ $taskService = new TaskService;
+ $this->controller = new DirectoryController($taskService);
}
/**
@@ -32,13 +33,13 @@ class ScheduledIndexFiles implements ShouldQueue {
$name = 'Scheduled Index Files';
$description = 'Looks for folder and video changes in in all Libraries.';
try {
- $task = DirectoryController::setupTask(null, $name, $description, 2);
+ $task = $this->controller->setupTask(null, $name, $description, 2);
$chain = [
new SyncFiles($task->id),
new IndexFiles($task->id),
];
- $batch = DirectoryController::setupBatch($chain, $task);
+ $batch = $this->controller->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) {
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index 48017ce0..8fba200c 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -5,7 +5,6 @@ namespace App\Jobs;
use App\Enums\TaskStatus;
use App\Models\Metadata;
use App\Models\Record;
-use App\Models\SubTask;
use App\Services\TaskService;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
@@ -14,11 +13,11 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\App;
+use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
-use Livewire\Attributes\Title;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
@@ -55,6 +54,8 @@ class VerifyFiles implements ShouldQueue {
protected $taskService;
+ protected $embedChain = [];
+
/**
* Create a new job instance.
*/
@@ -73,7 +74,6 @@ class VerifyFiles implements ShouldQueue {
if ($this->batch()->cancelled()) {
// Determine if the batch has been cancelled...
- // SubTask::where('id', $this->subTaskId)->update();
$this->taskService->updateSubTask($this->subTaskId, ['status' => TaskStatus::CANCELLED, 'summary' => 'Parent Task was Cancelled']);
return;
@@ -88,7 +88,18 @@ class VerifyFiles implements ShouldQueue {
$endedAt = now();
$duration = (int) $this->startedAt->diffInSeconds($endedAt);
// DB::table('tasks')->where('id', $this->taskId)->increment('sub_tasks_complete');
- $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++'], false);
+
+ if (count($this->embedChain)) {
+ $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++', 'sub_tasks_total' => count($this->embedChain), 'sub_tasks_pending' => count($this->embedChain)]);
+ foreach ($this->embedChain as $key => $embedTask) {
+ Bus::dispatch($embedTask);
+ }
+ // $controller = new DirectoryController($this->taskService);
+ // $controller->embedUIDs($this->taskId, "Embed UIDs for task $this->taskId via Verify Files", $this->embedChain);
+ } else {
+ $this->taskService->updateTaskCounts($this->taskId, ['sub_tasks_complete' => '++'], false);
+ }
+
$this->taskService->updateSubTask($this->subTaskId, [
'status' => TaskStatus::COMPLETED,
'summary' => $summary,
@@ -127,15 +138,16 @@ class VerifyFiles implements ShouldQueue {
// if the video in db or file does not have a valid uuid, it will add it in both the db and on the file.
if (! Uuid::isValid($uuid ?? '')) {
- if (! isset($fileMetaData['tags']['uid'])) {
+ if (!isset($fileMetaData['tags']['uid']) && !isset($fileMetaData['tags']['uuid'])) {
$uuid = Str::uuid()->toString();
- EmbedUidInMetadata::dispatch($filePath, $uuid, $this->taskId);
+ $this->embedChain[] = new EmbedUidInMetadata($filePath, $uuid, $this->taskId, $video->id);
+ // $this->embedChain[] = ["path" => $filePath, "uuid" => $uuid];
+ // EmbedUidInMetadata::dispatch($filePath, $uuid, $this->taskId);
} else {
- $uuid = $fileMetaData['tags']['uid'];
+ $uuid = $fileMetaData['tags']['uuid'] ?? $fileMetaData['tags']['uid']; // Neet to use UUID everywhere instead of mismatching uuid with uid
dump("Found UUID {$uuid}");
+ $video->update(['uuid' => $uuid]); // If embedding, video is updated in the embed job
}
- $video->update(['uuid' => $uuid]);
- // if (isset($fileMetaData['tags']['uid']) ? $fileMetaData['tags']['uid'] : false) dump('Embed'); //EmbedUidInMetadata::dispatch($filePath, $uuid);
}
$metadata = Metadata::where('uuid', $uuid)->orWhere('composite_id', $compositeId)->first();
@@ -276,12 +288,11 @@ class VerifyFiles implements ShouldQueue {
}
}
- private function getFileMetadata($filePath) {
+ public static function getFileMetadata($filePath) {
try {
// ? FFMPEG module with 6 test folders takes 35+ seconds but running the commands through shell takes 18 seconds
// $ffprobe = FFMpegFFProbe::create();
// $tags = $ffprobe->format($filePath)->get('tags'); // extracts file information
- // return isset($tags['uid']) ? $tags['uid'] : (isset($tags['UID']) ? $tags['UID'] : null);
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
@@ -304,7 +315,7 @@ class VerifyFiles implements ShouldQueue {
throw new ProcessFailedException($process);
}
- $output = $process->getOutput(); // Decode JSON output
+ $output = $process->getOutput();
$metadata = json_decode($output, true);
if ($ext === 'ogg') {
$metadata['format'] = $metadata['streams'][0] ?? [];
@@ -313,7 +324,7 @@ class VerifyFiles implements ShouldQueue {
return $metadata['format'];
} catch (\Throwable $th) {
dump($th);
-
+ Log::error('Unable to get file metadata', ["error" => $th->getMessage()]);
return ['tags' => []];
}
}
@@ -345,7 +356,7 @@ class VerifyFiles implements ShouldQueue {
return $this->getPathUrl($coverArtPath);
}
- // If album art exists and the file was recently updated, overrite the old image
+ // If album art exists and the file was recently updated, overwrite the old image
$coverGenerated = $this->extractAlbumArt($filePath, $coverArtPath);
if ($coverGenerated) {
@@ -359,7 +370,6 @@ class VerifyFiles implements ShouldQueue {
private function extractAlbumArt($filePath, $outputPath) {
try {
- // code...'ffmpeg',
$tempPath = sys_get_temp_dir() . '/' . basename($outputPath);
$command = [
'ffmpeg',
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index 34c9ce93..381042a9 100755
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -21,7 +21,7 @@ class AppServiceProvider extends ServiceProvider {
*/
public function boot(): void {
//
- Pulse::user(fn($user) => [
+ Pulse::user(fn ($user) => [
'name' => $user->name,
'extra' => $user->email,
]);
diff --git a/app/Services/TaskService.php b/app/Services/TaskService.php
index 71507af5..db9d3dfa 100644
--- a/app/Services/TaskService.php
+++ b/app/Services/TaskService.php
@@ -56,7 +56,9 @@ class TaskService {
$subTask->{$key} = $value;
}
$subTask->save();
- // if ($broadcast === true) broadcast(new SubTaskUpdated($subTask));
+ if ($broadcast) {
+ broadcast(new SubTaskUpdated($subTask));
+ }
return $subTask;
}
@@ -71,12 +73,14 @@ class TaskService {
foreach ($attr as $key => $value) {
if ($value === '++') {
$task->{$key}++;
- } else {
+ } elseif ($value === '--') {
$task->{$key}--;
+ } elseif (is_numeric($value)) {
+ $task->{$key} += (int) $value;
}
}
$task->save();
- if ($broadcast === true) {
+ if ($broadcast) {
broadcast(new TaskUpdated($task));
}
diff --git a/package.json b/package.json
index 57ebd44e..80dcf961 100755
--- a/package.json
+++ b/package.json
@@ -14,7 +14,7 @@
"vite:dev": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold\" \"npm:php:serve\" \"npm:php:queue\" \"npm:dev\"",
"vite:dev2": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold\" \"npm:php:serve\" \"npm:php:pail\" \"npm:dev\"",
"vite:cron": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\"",
- "vite:cronws": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold,magenta.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\" \"npm:php:reverb\"",
+ "vite:cronws": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold,magenta.bold,yellow.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\" \"npm:php:reverb\" \"npm:php:queue-high\"",
"vite:cronwsd": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,red.bold,white.bold,magenta.bold,yellow.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:dev\" \"npm:php:pulse\" \"npm:php:reverb-debug\" \"npm:php:queue-high\"",
"vite:php": "concurrently -k -p \"[{name}]\" -c \"blue.bold,green.bold,white.bold,magenta.bold,yellow.bold\" \"npm:php:queue\" \"npm:php:scheduler\" \"npm:php:pulse\" \"npm:php:reverb\" \"npm:php:queue-high\"",
"build": "npm run pint && npm run type-check && npm run build-only",
diff --git a/resources/js/components/cards/CategoryCard.vue b/resources/js/components/cards/CategoryCard.vue
index 90abac54..212a968a 100644
--- a/resources/js/components/cards/CategoryCard.vue
+++ b/resources/js/components/cards/CategoryCard.vue
@@ -120,7 +120,7 @@ watch(
class="h-8"
:placeholder="'Select Default Folder'"
:default-item="data?.folders.findIndex((folder) => folder.id == defaultFolder?.id) ?? 0"
- :disabled="processing"
+ :disabled="processing || !data?.folders.length"
:title="'Select Default Folder'"
@selectItem="handleSetDefaultFolder"
:options="
diff --git a/resources/js/components/cards/SubTaskCard.vue b/resources/js/components/cards/SubTaskCard.vue
index a6702c5e..b63b0e1d 100644
--- a/resources/js/components/cards/SubTaskCard.vue
+++ b/resources/js/components/cards/SubTaskCard.vue
@@ -18,12 +18,12 @@ const emit = defineEmits(['clickAction']);
<template>
<span class="flex text-left rounded-xl dark:text-white w-full">
<section
- class="flex flex-wrap ring-1 ring-inset ring-gray-900/5 hover:ring-purple-700 rounded-md shadow-sm w-full bg-white dark:bg-primary-dark-800/70 dark:hover:bg-primary-dark-600 hover:bg-primary-800 p-3 gap-4 items-center flex-1"
+ class="flex flex-wrap flex-1 ring-1 truncate ring-inset ring-gray-900/5 hover:ring-purple-700 rounded-md shadow-sm w-full bg-white dark:bg-primary-dark-800/70 dark:hover:bg-primary-dark-600 hover:bg-primary-800 p-3 gap-4 items-center"
>
- <div class="relative group flex flex-col gap-1 flex-1">
- <HoverCard :content="data.summary ?? ''" class="flex gap-x-4 gap-y-2 items-center">
+ <div class="relative group flex flex-col gap-1 flex-1 truncate">
+ <HoverCard :content="data.summary ?? ''" class="flex gap-x-4 gap-y-2 items-center truncate">
<template #trigger>
- <h2 class="truncate capitalize group" :title="data.name">{{ data.id }} - {{ data.name }}</h2>
+ <h2 class="truncate capitalize group">{{ data.id }} - {{ data.name }}</h2>
<p v-if="data.summary" class="truncate text-neutral-500 dark:text-neutral-400 max-w-48 lg:max-w-20 xl:max-w-64 hidden md:block">
{{ data.summary }}
</p>
@@ -47,8 +47,8 @@ const emit = defineEmits(['clickAction']);
}}
</h4>
<h4 class="text-xs text-neutral-500 dark:text-neutral-400 truncate line-clamp-1 capitalize w-20 lg:w-fit hidden sm:block" title="Duration">
- {{ data.duration ? 'Duration:' : data.started_at ? 'Started: ' : 'Scheduled: ' }}
- {{ data.duration ? toFormattedDuration(data.duration, false) : toTimeSpan(data.started_at ?? data.created_at, ' UTC') }}
+ {{ data.duration || data.ended_at ? 'Duration:' : data.started_at ? 'Started: ' : 'Scheduled: ' }}
+ {{ data.duration || data.ended_at ? toFormattedDuration(data.duration, false) : toTimeSpan(data.started_at ?? data.created_at, ' UTC') }}
</h4>
</div>
</div>
@@ -63,7 +63,7 @@ const emit = defineEmits(['clickAction']);
</div>
</div>
- <div class="flex gap-1 items-center flex-1 sm:flex-none">
+ <div class="flex gap-1 items-center shrink-0 sm:flex-none">
<PulseDoughnutChart
v-if="isScreenLarge ?? false"
v-cloak
@@ -99,16 +99,14 @@ const emit = defineEmits(['clickAction']);
<ChipTag
:class="`h-6 shadow-sm`"
- :colour="` ${
- data.status === 'pending'
- ? 'bg-[#e4e4e4] dark:bg-white !text-neutral-900'
- : data.status === 'processing'
- ? 'bg-purple-600 dark:bg-purple-700 !text-white'
- : data.status === 'completed'
- ? 'bg-[#660099] !text-white'
- : data.status === 'incomplete' || data.status === 'cancelled'
- ? 'bg-amber-500 !text-neutral-900 '
- : 'bg-rose-600 dark:bg-rose-700 !text-white'
+ :colour="`${data.status === 'pending' ? 'bg-[#e4e4e4] dark:bg-white !text-neutral-900' : '!text-white'} ${
+ data.status === 'processing'
+ ? 'bg-purple-600 dark:bg-purple-700'
+ : data.status === 'completed'
+ ? 'bg-[#660099] '
+ : data.status === 'incomplete' || data.status === 'cancelled'
+ ? 'bg-amber-500 !text-neutral-900 '
+ : 'bg-rose-600 dark:bg-rose-700 '
}`"
:label="data.status"
/>
diff --git a/resources/js/components/cards/TaskCard.vue b/resources/js/components/cards/TaskCard.vue
index 7486c7d5..016e028b 100644
--- a/resources/js/components/cards/TaskCard.vue
+++ b/resources/js/components/cards/TaskCard.vue
@@ -85,7 +85,7 @@ watch(
<div class="flex flex-col gap-2 sm:gap-1 flex-1 relative">
<HoverCard :content="data.description ?? ''" class="flex gap-x-4 gap-y-2 items-center">
<template #trigger>
- <h2 class="truncate capitalize group" :title="data.name">{{ data.id }} - {{ data.name }}</h2>
+ <h2 class="truncate capitalize group">{{ data.id }} - {{ data.name }}</h2>
<p v-if="data.summary" class="truncate text-neutral-500 dark:text-neutral-400 max-w-64 hidden md:block">
{{ data.summary }}
</p>
@@ -202,16 +202,14 @@ watch(
<span class="w-24 flex items-center justify-end">
<ChipTag
:class="`h-6 shadow-sm`"
- :colour="`!text-white ${
- data.status === 'pending'
- ? 'bg-[#e4e4e4] dark:bg-white !text-neutral-900'
- : data.status === 'processing'
- ? 'bg-purple-600 dark:bg-purple-700'
- : data.status === 'completed'
- ? 'bg-[#660099] '
- : data.status === 'incomplete' || data.status === 'cancelled'
- ? 'bg-amber-500 !text-neutral-900 '
- : 'bg-rose-600 dark:bg-rose-700 '
+ :colour="`${data.status === 'pending' ? 'bg-[#e4e4e4] dark:bg-white !text-neutral-900' : '!text-white'} ${
+ data.status === 'processing'
+ ? 'bg-purple-600 dark:bg-purple-700'
+ : data.status === 'completed'
+ ? 'bg-[#660099] '
+ : data.status === 'incomplete' || data.status === 'cancelled'
+ ? 'bg-amber-500 !text-neutral-900 '
+ : 'bg-rose-600 dark:bg-rose-700 '
}`"
:label="data.status"
/>
diff --git a/resources/js/components/dashboard/DashboardTasks.vue b/resources/js/components/dashboard/DashboardTasks.vue
index 3d20527f..02ac77ea 100644
--- a/resources/js/components/dashboard/DashboardTasks.vue
+++ b/resources/js/components/dashboard/DashboardTasks.vue
@@ -82,7 +82,7 @@ const filteredTasks = computed(() => {
? stateTasks.value.filter((task: TaskResource) => {
{
try {
- let strRepresentation = [task.name, task.summary, task.description, task.created_at].join(' ').toLowerCase();
+ let strRepresentation = [task.name, task.summary, task.description, task.created_at, task.status].join(' ').toLowerCase();
return strRepresentation.includes(searchQuery.value.toLowerCase());
} catch (error) {
console.log(error);
@@ -122,7 +122,7 @@ const handleDelete = (id: number, type: '' | 'cancel' | 'subTask' = '', innerId?
else if (type == 'subTask') {
if (!innerId && innerId !== 0) return;
submitSubTaskDelete(innerId);
- } else deleteModal.toggleModal(true);
+ } else submitDelete();
};
const submitCancel = async () => {
diff --git a/resources/js/components/pinesUI/InputSelect.vue b/resources/js/components/pinesUI/InputSelect.vue
index a9301c37..2216beff 100755
--- a/resources/js/components/pinesUI/InputSelect.vue
+++ b/resources/js/components/pinesUI/InputSelect.vue
@@ -132,7 +132,9 @@ watch(
<button
ref="selectButton"
@click="select.toggleSelect()"
- :class="`${select.selectOpen && 'hocus:ring-0'} relative h-10 flex items-center justify-between w-full py-2 pl-3 pr-10 text-left rounded-md shadow-sm cursor-pointer text-sm border-none focus:outline-none ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 hocus:ring-[0.125rem] hover:ring-violet-400 hover:dark:ring-violet-700 focus:ring-indigo-400 dark:focus:ring-indigo-500 text-gray-900 dark:text-neutral-100 bg-white dark:bg-primary-dark-800 ${props.class}`"
+ :class="`${select.selectOpen && 'hocus:ring-0'} relative h-10 flex items-center justify-between w-full py-2 pl-3 pr-10 text-left rounded-md shadow-sm cursor-pointer text-sm border-none focus:outline-none ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 hocus:ring-[0.125rem] hover:ring-violet-400 hover:dark:ring-violet-700 focus:ring-indigo-400 dark:focus:ring-indigo-500 text-gray-900 dark:text-neutral-100 bg-white dark:bg-primary-dark-800 ${props.class}
+ disabled:cursor-not-allowed disabled:hover:ring-neutral-200 disabled:hover:dark:ring-neutral-700 disabled:opacity-60
+ `"
:disabled="disabled"
type="button"
:title="title ?? 'Make Selection'"