A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
chore: code smells
aminnausin1e1002e1d8fd
diff --git a/app/Exceptions/DataLostException.php b/app/Exceptions/DataLostException.phpnew file mode 100644index 00000000..66866429--- /dev/null+++ b/app/Exceptions/DataLostException.php@@ -0,0 +1,11 @@+<?php++namespace App\Exceptions;++use Exception;++class DataLostException extends Exception {+ public function __construct(string $message = 'Data Lost') {+ parent::__construct($message);+ }+}diff --git a/app/Http/Controllers/Api/V1/UserController.php b/app/Http/Controllers/Api/V1/UserController.phpindex aa49f1a0..7f4c8df1 100644--- a/app/Http/Controllers/Api/V1/UserController.php+++ b/app/Http/Controllers/Api/V1/UserController.php@@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;use App\Http\Resources\UserResource;use App\Models\User;use App\Traits\HttpResponses;-use Exception;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Log;@@ -22,6 +21,7 @@ class UserController extends Controller {$users = Auth::id() === 1? User::all()->sortBy('name'): User::where('id', Auth::id())->get();+return UserResource::collection($users);} catch (\Throwable $th) {return $this->error(null, 'Unable to get list of users. Error: ' . $th->getMessage(), 500);@@ -73,8 +73,8 @@ class UserController extends Controller {try {returnDB::table('sessions')- ->whereNotNull('user_id')- ->count();+ ->whereNotNull('user_id')+ ->count();} catch (\Throwable $th) {return $this->error(0, 'Unable to get count of logged in users. Error: ' . $th->getMessage(), 500);}diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.phpindex b47f6b66..20b3cb08 100755--- a/app/Http/Controllers/DirectoryController.php+++ b/app/Http/Controllers/DirectoryController.php@@ -102,5 +102,4 @@ class DirectoryController extends Controller {}}-class ForbiddenException extends Exception {-}+class ForbiddenException extends Exception {}diff --git a/app/Http/Middleware/UserLastActive.php b/app/Http/Middleware/UserLastActive.phpindex 8b84cf46..90ef3806 100644--- a/app/Http/Middleware/UserLastActive.php+++ b/app/Http/Middleware/UserLastActive.php@@ -2,7 +2,6 @@namespace App\Http\Middleware;-use App\Models\User;use Closure;use Illuminate\Support\Facades\Auth;diff --git a/app/Http/Requests/CategoryUpdateRequest.php b/app/Http/Requests/CategoryUpdateRequest.phpindex 19cdf443..821c561b 100644--- a/app/Http/Requests/CategoryUpdateRequest.php+++ b/app/Http/Requests/CategoryUpdateRequest.php@@ -10,7 +10,7 @@ class CategoryUpdateRequest extends FormRequest {* Determine if the user is authorized to make this request.*/public function authorize(): bool {- return Auth::id() === 1;;+ return Auth::id() === 1;}/**diff --git a/app/Http/Resources/SeriesResource.php b/app/Http/Resources/SeriesResource.phpindex e263d464..b23c62ca 100644--- a/app/Http/Resources/SeriesResource.php+++ b/app/Http/Resources/SeriesResource.php@@ -6,24 +6,12 @@ use Illuminate\Http\Request;use Illuminate\Http\Resources\Json\JsonResource;class SeriesResource extends JsonResource {- protected static $editorCache = [];-/*** Transform the resource into an array.** @return array<string, mixed>*/public function toArray(Request $request): array {- $editorId = $this->editor_id; // Assuming editor_id is the foreign key- $editor = null;-- if (isset(self::$editorCache[$editorId])) {- $editor = self::$editorCache[$editorId];- } else {- $editor = $this->editor;- self::$editorCache[$editorId] = $editor;- }-return ['id' => $this->id,'folder_id' => $this->folder_id,diff --git a/app/Http/Resources/VideoTagResource.php b/app/Http/Resources/VideoTagResource.phpindex 21fe0fb5..678559ef 100644--- a/app/Http/Resources/VideoTagResource.php+++ b/app/Http/Resources/VideoTagResource.php@@ -14,15 +14,6 @@ class VideoTagResource extends JsonResource {* @return array<string, mixed>*/public function toArray(Request $request): array {- // $tag_id = $this->tag_id;-- // if (isset(self::$tagCache[$tag_id])) {- // $tag = self::$tagCache[$tag_id];- // } else {- // $tag = $this->tag;- // self::$tagCache[$tag_id] = $tag;- // }-if (! $this->relationLoaded('tag')) {$this->loadMissing('tag');}diff --git a/app/Jobs/CleanFolderPaths.php b/app/Jobs/CleanFolderPaths.phpindex 620f4f8e..38c87d58 100644--- a/app/Jobs/CleanFolderPaths.php+++ b/app/Jobs/CleanFolderPaths.php@@ -3,6 +3,7 @@namespace App\Jobs;use App\Enums\TaskStatus;+use App\Exceptions\DataLostException;use App\Models\Folder;use App\Models\SubTask;use App\Services\TaskService;@@ -75,7 +76,7 @@ class CleanFolderPaths implements ShouldQueue {private function cleanFolderPaths() {if (count($this->folders) == 0) {- throw new \Exception('Folder Data Lost');+ throw new DataLostException('Folder Data Lost');}$transactions = [];diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.phpindex 2784e5e4..b2433eef 100755--- a/app/Jobs/IndexFiles.php+++ b/app/Jobs/IndexFiles.php@@ -107,7 +107,6 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {$error = 'Invalid Directory: "media"';throw new \Exception($error);- // dd(json_encode(['success' => false, 'result' => '', 'error' => $error], JSON_UNESCAPED_SLASHES));}$realPath = Storage::disk('public')->path($path);@@ -228,14 +227,10 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {Folder::destroy($folderDeletions);Category::destroy($categoryDeletions);- // Series::upsert(['folder_id'=>1,'composite_id'=>'anime/frieren'], 'composite_id', ['folder_id']);- // Metadata::upsert(['video_id'=>1,'composite_id'=>'anime/frieren/S1E02.mp4'], 'composite_id', ['video_id']);-Category::insert($categoryTransactions);Folder::insert($folderTransactions);Series::upsert($seriesTransactions, 'composite_id', ['folder_id']);Video::insert($videoTransactions);- // Metadata::upsert($metadataTransactions, ['composite_id', 'uuid'], ['video_id']);// Iterate through the metadata transactions and call upsertMetadataforeach ($metadataTransactions as $data) {$this->upsertMetadata($data);@@ -255,7 +250,6 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {// TODO: stop adding empty data cache entries if the last entry was also empty. Need to check last one but popping removes it and loses the key so I cannot add it back on if it wasnt empty.Storage::put('dataCache.json', json_encode($dataCache, JSON_UNESCAPED_SLASHES));- // dump('Categories | Folders | Videos | Data | SQL | DataCache', $directories, $subDirectories, $files, $data, $dbOut, $dataCache);dump('Categories | Folders | Videos | Changes | SQL ', $directories, ['count' => count($subDirectories['data']['folderStructure'])], ['count' => count($files['data']['videoStructure'])], $data, $dbOut);return 'Changed ' . count($data['categories']) . ' libraries, ' . count($data['folders']) . ' folders and ' . count($data['videos']) . " Videos. \n\n$dbOut";@@ -608,4 +602,5 @@ class IndexFiles implements ShouldBeUnique, ShouldQueue {return 'Generated ' . $count . ' ' . $type . ' Changes';}}-class BatchCancelledException extends \Exception {}+class BatchCancelledException extends \Exception {+}diff --git a/app/Jobs/VerifyFolders.php b/app/Jobs/VerifyFolders.phpindex 5278e136..dede1553 100644--- a/app/Jobs/VerifyFolders.php+++ b/app/Jobs/VerifyFolders.php@@ -3,6 +3,7 @@namespace App\Jobs;use App\Enums\TaskStatus;+use App\Exceptions\DataLostException;use App\Models\Series;use App\Models\SubTask;use App\Services\TaskService;@@ -76,7 +77,7 @@ class VerifyFolders implements ShouldQueue {private function verifyFolders() {if (count($this->folders) == 0) {- throw new \Exception('Folder Data Lost');+ throw new DataLostException('Folder Data Lost');}$transactions = [];