Skip to content

A self-hosted media server and file management system

Clean up job code

aminnausin9be3cc1cb4d1
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index 1f1aa65f..3f8e15ea 100644
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -159,6 +159,8 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique
$dataCache = Storage::json('public\dataCache.json') ?? array();
$dataCache[date("Y-m-d-h:i:sa")] = array("job"=>"index", "data"=>$data);
+ // 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::disk('public')->put('dataCache.json', json_encode($dataCache, JSON_UNESCAPED_SLASHES));
dump('Categories | Folders | Videos | Data | SQL | DataCache', $directories, $subDirectories, $files, $data, $dbOut, $dataCache);
}
diff --git a/app/Jobs/SyncFiles.php b/app/Jobs/SyncFiles.php
index 730ebf8a..a0f1fd90 100644
--- a/app/Jobs/SyncFiles.php
+++ b/app/Jobs/SyncFiles.php
@@ -9,11 +9,9 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
-use Illuminate\Support\Facades\File;
use App\Models\Category;
use App\Models\Folder;
use App\Models\Video;
-use Illuminate\Database\Eloquent\Collection;
class SyncFiles implements ShouldQueue, ShouldBeUnique
{
@@ -47,10 +45,8 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique
dd(json_encode(array("success"=>false, "result"=>"", "error"=>$error), JSON_UNESCAPED_SLASHES));
}
- $realPath = Storage::path($path);
-
- $directories = $this->generateCategories($realPath);
- $subDirectories = $this->generateFolders($path, $directories["data"]["categoryStructure"]);
+ $directories = $this->generateCategories();
+ $subDirectories = $this->generateFolders($path);
$files = $this->generateVideos($path, $subDirectories["data"]["folderStructure"], $directories["data"]["categoryStructure"]);
if(isset($files["updatedFolderStructure"])) $subDirectories["data"]["folderStructure"] = $files["updatedFolderStructure"];
@@ -72,7 +68,7 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique
dump('Categories | Folders | Videos | Data | dataCache', $directories, $subDirectories, $files, $data, $dataCache);
}
- private function generateCategories($path){
+ private function generateCategories(){
$data = Storage::json('public\categories.json') ?? array("next_ID"=>1, "categoryStructure" => array()); //array("anime"=>1,"tv"=>2,"yogscast"=>3); // read from json
$scanned = Category::all(); // read folder structure
@@ -114,7 +110,7 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique
return array("categoryChanges"=> $changes, "data" => $data);
}
- private function generateFolders($path, $categoryStructure){
+ private function generateFolders($path){
$data = Storage::json('public\folders.json') ?? array("next_ID"=>1,"folderStructure"=>array()); //array("anime/frieren"=>array("id"=>0,"name"=>"frieren"),"starwars/andor"=>array("id"=1,"name"="andor")); // read from json
$cost = 0;
$scanned = Folder::all();