Skip to content

A self-hosted media server and file management system

php formatting

aminnausin036f47d1b045
diff --git a/app/Http/Controllers/Api/V1/AuthController.php b/app/Http/Controllers/Api/V1/AuthController.php
index 6465e94c..519fbe17 100755
--- a/app/Http/Controllers/Api/V1/AuthController.php
+++ b/app/Http/Controllers/Api/V1/AuthController.php
@@ -7,11 +7,10 @@ use App\Http\Requests\UserLoginRequest;
use App\Http\Requests\UserStoreRequest;
use App\Models\User;
use App\Traits\HttpResponses;
-use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
-use Illuminate\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
+use Illuminate\View\View;
class AuthController extends Controller {
use HttpResponses;
@@ -20,26 +19,25 @@ class AuthController extends Controller {
return view('auth.login');
}
-
public function generate(): View {
return view('auth.register');
}
+
/**
* Attempt to authenticate the request's credentials_me.
*/
public function login(UserLoginRequest $request) {
$validated = $request->validated();
- if (!Auth::attempt($request->only('email', 'password'), $request['remember'])) {
- return $request->expectsJson() ? $this->error('', 'Invalid Credentials', 401) : view('auth.login', array("error" => "Invalid Credentials"));
+ if (! Auth::attempt($request->only('email', 'password'), $request['remember'])) {
+ return $request->expectsJson() ? $this->error('', 'Invalid Credentials', 401) : view('auth.login', ['error' => 'Invalid Credentials']);
}
$user = User::where('email', $validated['email'])->first();
$token = $user->createToken('API token for ' . $user->name)->plainTextToken;
if ($request->expectsJson()) {
-
return $this->success([
'user' => $user,
- 'token' => $token
+ 'token' => $token,
]);
}
if (! $request->expectsJson()) {
@@ -58,15 +56,13 @@ class AuthController extends Controller {
'password' => Hash::make($validated['password']),
]);
-
if ($request->expectsJson()) {
-
Auth::login($user);
$token = $user->createToken('API token for ' . $user->name)->plainTextToken;
return $this->success([
'user' => $user,
- 'token' => $token
+ 'token' => $token,
]);
}
if (! $request->expectsJson()) {
@@ -77,7 +73,7 @@ class AuthController extends Controller {
public function authenticate() {
$user = Auth::user();
- return $this->success(array('user' => $user), 'Authenticated as ' . $user->name);
+ return $this->success(['user' => $user], 'Authenticated as ' . $user->name);
}
/**
diff --git a/app/Http/Controllers/Api/V1/CategoryController.php b/app/Http/Controllers/Api/V1/CategoryController.php
index 24394133..e11f81af 100755
--- a/app/Http/Controllers/Api/V1/CategoryController.php
+++ b/app/Http/Controllers/Api/V1/CategoryController.php
@@ -2,10 +2,10 @@
namespace App\Http\Controllers\Api\V1;
-use App\Http\Resources\CategoryResource;
use App\Http\Controllers\Controller;
-use App\Traits\HttpResponses;
+use App\Http\Resources\CategoryResource;
use App\Models\Category;
+use App\Traits\HttpResponses;
use Illuminate\Support\Facades\Auth;
class CategoryController extends Controller {
@@ -16,7 +16,7 @@ class CategoryController extends Controller {
*/
public function index() {
try {
- if (!Auth::user() || Auth::user()->id !== 1) {
+ if (! Auth::user() || Auth::user()->id !== 1) {
abort(403, 'Unauthorized action.');
}
@@ -34,7 +34,7 @@ class CategoryController extends Controller {
* Display the specified resource.
* Get Category with count of folders with the category id
*
- * @param int $category_id
+ * @param int $category_id
* @return \Illuminate\Http\Response
*/
public function show(Category $category) {
diff --git a/app/Http/Controllers/Api/V1/FolderController.php b/app/Http/Controllers/Api/V1/FolderController.php
index d14a78ad..51e16db1 100755
--- a/app/Http/Controllers/Api/V1/FolderController.php
+++ b/app/Http/Controllers/Api/V1/FolderController.php
@@ -7,18 +7,15 @@ use App\Http\Requests\FolderCollectionRequest;
use App\Http\Resources\FolderResource;
use App\Models\Folder;
use App\Traits\HttpResponses;
-use Illuminate\Http\Request;
-class FolderController extends Controller
-{
+class FolderController extends Controller {
use HttpResponses;
/**
* Display a listing of the resource.
* Get all folders with video counts from category ID
*/
- public function getFrom(FolderCollectionRequest $request)
- {
+ public function getFrom(FolderCollectionRequest $request) {
$validated = $request->validated();
try {
@@ -36,11 +33,10 @@ class FolderController extends Controller
* Display the specified resource.
* Get Folder with video count from folder ID
*
- * @param int $video_id
+ * @param int $video_id
* @return \Illuminate\Http\Response
*/
- public function show(Folder $folder)
- {
+ public function show(Folder $folder) {
return new FolderResource($folder);
}
}
diff --git a/app/Http/Controllers/Api/V1/MetadataController.php b/app/Http/Controllers/Api/V1/MetadataController.php
index 62718333..91438f37 100644
--- a/app/Http/Controllers/Api/V1/MetadataController.php
+++ b/app/Http/Controllers/Api/V1/MetadataController.php
@@ -2,12 +2,12 @@
namespace App\Http\Controllers\Api\V1;
-use App\Models\Metadata;
use App\Http\Controllers\Controller;
use App\Http\Requests\MetadataStoreRequest;
use App\Http\Requests\MetadataUpdateRequest;
use App\Http\Resources\MetadataResource;
use App\Http\Resources\VideoResource;
+use App\Models\Metadata;
use App\Models\Video;
use App\Models\VideoTag;
use App\Traits\HttpResponses;
@@ -26,7 +26,6 @@ class MetadataController extends Controller {
}
}
-
/**
* Store a newly created resource in storage.
*/
@@ -35,25 +34,30 @@ class MetadataController extends Controller {
$validated = $request->validated();
$video = Video::where('id', $request->video_id)->first();
- if (!$video) return $this->error(null, 'Video does not exist', 404);
+ if (! $video) {
+ return $this->error(null, 'Video does not exist', 404);
+ }
- $existing = Metadata::where('composite_id', $video->folder->path . "/" . basename($video->path))->first();
- if ($existing && $existing->video_id != $request->video_id) return $this->error($existing, 'Metadata with generated unique id already exists for another video!', 500);
+ $existing = Metadata::where('composite_id', $video->folder->path . '/' . basename($video->path))->first();
+ if ($existing && $existing->video_id != $request->video_id) {
+ return $this->error($existing, 'Metadata with generated unique id already exists for another video!', 500);
+ }
$validated['editor_id'] = Auth::id();
- $validated['composite_id'] = $video->folder->path . "/" . basename($video->path);
+ $validated['composite_id'] = $video->folder->path . '/' . basename($video->path);
if ($existing) {
$existing->update($validated);
$this->generateTags($existing->id, $request->video_tags, $request->deleted_tags);
+
return $this->success(new VideoResource($existing->video), $validated); // new MetadataResource($metadata)
}
-
$metadata = Metadata::create($validated);
$this->generateTags($metadata->id, $request->video_tags, $request->deleted_tags);
+
return $this->success(new VideoResource($metadata->video), $validated); // new MetadataResource($metadata)
} catch (\Throwable $th) {
return $this->error(null, 'Unable to create metadata. Error: ' . $th->getMessage(), 500);
@@ -70,13 +74,14 @@ class MetadataController extends Controller {
$metadata->update($validated);
$this->generateTags($metadata->id, $request->video_tags, $request->deleted_tags);
+
return $this->success(new VideoResource($metadata->video), $validated);
} catch (\Throwable $th) {
return $this->error($request, 'Unable to edit video metadata. Error: ' . $th->getMessage(), 500);
}
}
- function generateTags($metadata_id, $video_tags, $deleted_tags = []) {
+ public function generateTags($metadata_id, $video_tags, $deleted_tags = []) {
foreach ($video_tags as $tag) {
VideoTag::firstOrCreate(['tag_id' => $tag['id'], 'metadata_id' => $metadata_id]);
}
diff --git a/app/Http/Controllers/Api/V1/PlaybackController.php b/app/Http/Controllers/Api/V1/PlaybackController.php
index 489332ac..1b17bf4e 100644
--- a/app/Http/Controllers/Api/V1/PlaybackController.php
+++ b/app/Http/Controllers/Api/V1/PlaybackController.php
@@ -2,18 +2,16 @@
namespace App\Http\Controllers\Api\V1;
-use App\Models\Playback;
use App\Http\Controllers\Controller;
use App\Http\Requests\PlaybackStoreRequest;
use App\Models\Metadata;
+use App\Models\Playback;
use App\Traits\HttpResponses;
-class PlaybackController extends Controller
-{
+class PlaybackController extends Controller {
use HttpResponses;
- public function __construct()
- {
+ public function __construct() {
$this->middleware('throttle:200,1')->only(['store']);
}
@@ -21,8 +19,7 @@ class PlaybackController extends Controller
* Display a listing of the resource.
* Get all playback data points from metadata ID for a video
*/
- public function show(int $id)
- {
+ public function show(int $id) {
// $request->query('param');
try {
@@ -35,17 +32,18 @@ class PlaybackController extends Controller
/**
* Store a newly created resource in storage.
*/
- public function store(PlaybackStoreRequest $request)
- {
+ public function store(PlaybackStoreRequest $request) {
try {
$validated = $request->validated();
$playbackUpdates = 0;
$metadata = null;
foreach ($validated['entries'] as $entry) {
- if (is_Null($metadata) || $metadata->id != $entry['metadata_id']) {
+ if (is_null($metadata) || $metadata->id != $entry['metadata_id']) {
$metadata = Metadata::where('id', $entry['metadata_id'])->first();
- if (!$metadata || !$metadata->video()) return $this->error(null, 'Video metadata does not exist', 404);
+ if (! $metadata || ! $metadata->video()) {
+ return $this->error(null, 'Video metadata does not exist', 404);
+ }
}
$existing = Playback::where('metadata_id', $entry['metadata_id'])->where('progress', $entry['progress'])->first();
diff --git a/app/Http/Controllers/Api/V1/ProfileController.php b/app/Http/Controllers/Api/V1/ProfileController.php
index b7a6a115..e9619a39 100644
--- a/app/Http/Controllers/Api/V1/ProfileController.php
+++ b/app/Http/Controllers/Api/V1/ProfileController.php
@@ -3,9 +3,7 @@
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
-use Illuminate\Http\Request;
-class ProfileController extends Controller
-{
+class ProfileController extends Controller {
//
}
diff --git a/app/Http/Controllers/Api/V1/PulseDashboardController.php b/app/Http/Controllers/Api/V1/PulseDashboardController.php
new file mode 100644
index 00000000..0baf46bc
--- /dev/null
+++ b/app/Http/Controllers/Api/V1/PulseDashboardController.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Http\Resources\Pulse\DashboardResource;
+use Illuminate\Http\Request;
+
+class PulseDashboardController {
+ public function index(Request $request) {
+ $period = $request->query('period', '');
+
+ return new DashboardResource(null, $period);
+ }
+
+ public function show(Request $request, string $type) {
+ $period = $request->query('period', '');
+ if (array_key_exists($type, config('pulse-api.resources')->toArray())) {
+ return new (config('pulse-api.resources.' . $type))(null, $period);
+ }
+
+ return response()->json([
+ 'data' => [
+ 'message' => 'Metric type "' . $type . '" does not exist.',
+ ],
+ ], 404);
+ }
+}
diff --git a/app/Http/Controllers/Api/V1/RecordController.php b/app/Http/Controllers/Api/V1/RecordController.php
index 567bd3a9..5c900db0 100644
--- a/app/Http/Controllers/Api/V1/RecordController.php
+++ b/app/Http/Controllers/Api/V1/RecordController.php
@@ -42,13 +42,15 @@ class RecordController extends Controller {
->where('id', $validated['video_id'])
->first();
- if (!$video) return $this->error(null, 'Video does not exist', 404);
+ if (! $video) {
+ return $this->error(null, 'Video does not exist', 404);
+ }
$record = Record::create([
'user_id' => Auth::id(),
'video_id' => $validated['video_id'],
'metadata_id' => $video->metadata?->id,
- 'name' => $video->metadata ? $video->metadata->title : $video->name // should be like meta data id in a persistent table that doesnt delete that has name episode season if available and displays depending on what data exists
+ 'name' => $video->metadata ? $video->metadata->title : $video->name, // should be like meta data id in a persistent table that doesnt delete that has name episode season if available and displays depending on what data exists
]);
return $this->success(new RecordResource($record));
@@ -57,7 +59,7 @@ class RecordController extends Controller {
/**
* Remove the specified resource from storage.
*
- * @param int $id
+ * @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Record $record) {
@@ -68,6 +70,7 @@ class RecordController extends Controller {
if (Auth::id() != $record->user_id) {
return $this->error('', 'Unauthorised request.', 403);
}
+
return null;
}
}
diff --git a/app/Http/Controllers/Api/V1/SeriesController.php b/app/Http/Controllers/Api/V1/SeriesController.php
index b2389780..dcab4b92 100644
--- a/app/Http/Controllers/Api/V1/SeriesController.php
+++ b/app/Http/Controllers/Api/V1/SeriesController.php
@@ -2,12 +2,12 @@
namespace App\Http\Controllers\Api\V1;
-use App\Models\Series;
use App\Http\Controllers\Controller;
use App\Http\Requests\SeriesStoreRequest;
use App\Http\Requests\SeriesUpdateRequest;
use App\Http\Resources\SeriesResource;
use App\Models\Folder;
+use App\Models\Series;
use App\Traits\HttpResponses;
use Illuminate\Support\Facades\Auth;
@@ -48,20 +48,26 @@ class SeriesController extends Controller {
$validated = $request->validated();
$folder = Folder::where('id', $request->folder_id)->first();
- if (!$folder) return $this->error(null, 'Folder does not exist', 404);
+ if (! $folder) {
+ return $this->error(null, 'Folder does not exist', 404);
+ }
$existing = Series::where('composite_id', $folder->path)->first();
- if ($existing && $existing->folder_id != $request->folder_id) return $this->error($existing, 'Series already exists for another folder!', 500);
+ if ($existing && $existing->folder_id != $request->folder_id) {
+ return $this->error($existing, 'Series already exists for another folder!', 500);
+ }
$validated['editor_id'] = Auth::id();
$validated['composite_id'] = $folder->path;
if ($existing) {
$existing->update($validated);
+
return $this->success(new SeriesResource($existing), $validated); // new MetadataResource($metadata)
}
$series = Series::create($validated);
+
return $this->success(new SeriesResource($series));
} catch (\Throwable $th) {
return $this->error(null, 'Unable to create series. Error: ' . $th->getMessage(), 500);
diff --git a/app/Http/Controllers/Api/V1/SiteController.php b/app/Http/Controllers/Api/V1/SiteController.php
index a7c110db..619348a8 100644
--- a/app/Http/Controllers/Api/V1/SiteController.php
+++ b/app/Http/Controllers/Api/V1/SiteController.php
@@ -9,24 +9,23 @@ use App\Models\Record;
use App\Models\Tag;
use App\Models\User;
use App\Models\Video;
-use Illuminate\Http\Request;
-use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
class SiteController extends Controller {
public function index() {
try {
- if (!Auth::user()->id == 1) return Response("Forbidden", 403);
+ if (! Auth::user()->id == 1) {
+ return Response('Forbidden', 403);
+ }
-
- return array(
- array('title' => 'categories', "count" => Category::count()),
- array('title' => 'folders', "count" => Folder::count()),
- array('title' => 'videos', "count" => Video::count()),
- array('title' => 'users', "count" => User::count()),
- array('title' => 'tags', "count" => Tag::count()),
- array('title' => 'views', "count" => Record::count())
- );
+ return [
+ ['title' => 'categories', 'count' => Category::count()],
+ ['title' => 'folders', 'count' => Folder::count()],
+ ['title' => 'videos', 'count' => Video::count()],
+ ['title' => 'users', 'count' => User::count()],
+ ['title' => 'tags', 'count' => Tag::count()],
+ ['title' => 'views', 'count' => Record::count()],
+ ];
} catch (\Throwable $th) {
return $this->error(null, 'Unable to get stats. Error: ' . $th->getMessage(), 500);
}
diff --git a/app/Http/Controllers/Api/V1/TagController.php b/app/Http/Controllers/Api/V1/TagController.php
index 1fe2aaf0..19117c06 100644
--- a/app/Http/Controllers/Api/V1/TagController.php
+++ b/app/Http/Controllers/Api/V1/TagController.php
@@ -2,10 +2,10 @@
namespace App\Http\Controllers\Api\V1;
-use App\Models\Series;
use App\Http\Controllers\Controller;
use App\Http\Requests\TagStoreRequest;
use App\Http\Resources\TagResource;
+use App\Models\Series;
use App\Models\Tag;
use App\Traits\HttpResponses;
use Illuminate\Support\Facades\Auth;
@@ -46,12 +46,15 @@ class TagController extends Controller {
$validated = $request->validated();
$existing = Tag::where('name', $request->name)->first();
- if ($existing) return $this->error($existing, 'Tag already exists!', 500);
+ if ($existing) {
+ return $this->error($existing, 'Tag already exists!', 500);
+ }
$validated['name'] = strtolower($validated['name']);
$validated['creator_id'] = Auth::id();
$tag = Tag::create($validated);
+
return new TagResource($tag);
} catch (\Throwable $th) {
return $this->error(null, 'Unable to create tag. Error: ' . $th->getMessage() . $request, 500);
diff --git a/app/Http/Controllers/Api/V1/VideoController.php b/app/Http/Controllers/Api/V1/VideoController.php
index 64117909..66dcab13 100755
--- a/app/Http/Controllers/Api/V1/VideoController.php
+++ b/app/Http/Controllers/Api/V1/VideoController.php
@@ -11,17 +11,14 @@ use App\Traits\HttpResponses;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
-class VideoController extends Controller
-{
+class VideoController extends Controller {
use HttpResponses;
/**
* Display a listing of the resource.
*/
- public function getFrom(VideoCollectionRequest $request)
- {
+ public function getFrom(VideoCollectionRequest $request) {
try {
-
$result = VideoResource::collection(Video::where('folder_id', $request->folder_id)->get());
return $this->success($result);
@@ -33,22 +30,20 @@ class VideoController extends Controller
/**
* Display the specified resource.
*
- * @param int $video_id
+ * @param int $video_id
* @return \Illuminate\Http\Response
*/
- public function show(Video $video)
- {
+ public function show(Video $video) {
return new VideoResource($video);
}
/**
* Update the specified resource in storage.
*
- * @param int $id
+ * @param int $id
* @return \Illuminate\Http\Response
*/
- public function update(VideoUpdateRequest $request, Video $video)
- {
+ public function update(VideoUpdateRequest $request, Video $video) {
try {
if (Auth::check()) {
$validated = $request->validated();
@@ -66,15 +61,16 @@ class VideoController extends Controller
/**
* Update view counter
*
- * @param int $id
+ * @param int $id
* @return \Illuminate\Http\Response
*/
- public function watch(Request $request, Video $video)
- {
+ public function watch(Request $request, Video $video) {
$metadata = $video->metadata()->first();
if ($metadata) {
$metadata->update(['view_count' => ($metadata->view_count ?? 0) + 1]);
- } else $video->update(['view_count' => ($video->view_count ?? 0) + 1]);
+ } else {
+ $video->update(['view_count' => ($video->view_count ?? 0) + 1]);
+ }
return $this->success(new VideoResource($video));
}
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php
index d2979fb7..c469ff12 100755
--- a/app/Http/Controllers/DirectoryController.php
+++ b/app/Http/Controllers/DirectoryController.php
@@ -15,9 +15,9 @@ use App\Jobs\VerifyFolders;
use App\Models\Category;
use App\Models\Folder;
use App\Models\Video;
+use App\Traits\HttpResponses;
use ErrorException;
use Illuminate\Http\Request;
-use App\Traits\HttpResponses;
use Illuminate\Support\Facades\Bus;
class DirectoryController extends Controller {
@@ -25,25 +25,26 @@ class DirectoryController extends Controller {
public function showDirectory(Request $request) {
// aim -> return directory and folder id where exists so folder controller is usable
- $privateCategories = array("legacy" => 1);
+ $privateCategories = ['legacy' => 1];
- if (isset($privateCategories[strtolower($request->dir)]) && !$request->user('sanctum')) {
+ if (isset($privateCategories[strtolower($request->dir)]) && ! $request->user('sanctum')) {
$data['message'] = 'Unauthorized';
+
return view('error', $data);
}
$dirRaw = Category::select('id')->firstWhere('name', 'ilike', '%' . $request->dir . '%');
if (isset($dirRaw->id)) {
- $data['dir'] = array('id' => $dirRaw->id, 'name' => $request->dir);
+ $data['dir'] = ['id' => $dirRaw->id, 'name' => $request->dir];
if (isset($request->folder_name)) {
- $data['folder'] = array('id' => null, 'name' => $request->folder_name);
+ $data['folder'] = ['id' => null, 'name' => $request->folder_name];
} else {
$folderRaw = Folder::select('id', 'name')->firstWhere('category_id', $data['dir']['id']);
- $data['folder'] = array('id' => $folderRaw->id, 'name' => $folderRaw->name);
+ $data['folder'] = ['id' => $folderRaw->id, 'name' => $folderRaw->name];
}
} else {
- $data['dir'] = array('id' => null, 'name' => $request->dir);
- $data['folder'] = array('id' => null, 'name' => null);
+ $data['dir'] = ['id' => null, 'name' => $request->dir];
+ $data['folder'] = ['id' => null, 'name' => null];
}
// dump($data);
@@ -55,32 +56,33 @@ class DirectoryController extends Controller {
// IDEALLY it should also load data to prevent requiring more api requests
// It does exactly that now it feels fast
try {
- $privateCategories = array("legacy" => 1);
+ $privateCategories = ['legacy' => 1];
$dir = trim(strtolower($request?->dir ?? ''));
$folderName = trim(strtolower($request?->folderName ?? ''));
- if (isset($privateCategories[$dir]) && !$request->user('sanctum')) {
+ if (isset($privateCategories[$dir]) && ! $request->user('sanctum')) {
$data['message'] = 'Unauthorized';
+
return $this->error(null, 'Access to this folder is forbidden', 403);
}
$dirRaw = Category::select('id')->firstWhere('name', 'ilike', '%' . $dir . '%');
- $data = array('dir' => array('id' => null, 'name' => $dir, 'folders' => null), 'folder' => array('id' => null, 'name' => $folderName ?? null, 'videos' => null)); // Default null values
+ $data = ['dir' => ['id' => null, 'name' => $dir, 'folders' => null], 'folder' => ['id' => null, 'name' => $folderName ?? null, 'videos' => null]]; // Default null values
- if (!isset($dirRaw->id)) { // Cannot find category so return default nulls
- return $this->error(array('categoryName' => $dir), 'Cannot find specified category', 200);
+ if (! isset($dirRaw->id)) { // Cannot find category so return default nulls
+ return $this->error(['categoryName' => $dir], 'Cannot find specified category', 200);
}
$folderList = Folder::where('category_id', $dirRaw->id)->withCount(['videos']); // Folders in category
- $data['dir'] = array('id' => $dirRaw->id, 'name' => $dir, 'folders' => FolderResource::collection($folderList->get())); // Full category data
+ $data['dir'] = ['id' => $dirRaw->id, 'name' => $dir, 'folders' => FolderResource::collection($folderList->get())]; // Full category data
$folderRaw = isset($request->folderName) ? $folderList->firstWhere('name', 'ilike', '%' . $folderName . '%') : $folderList->first(); // Folder in request ? search by name else select first in category
- if (!isset($folderRaw->id)) { // no folder found
- return $this->error(array('categoryName' => $dir, 'folderName' => $folderName), 'Cannot find folder in specified category', 200);
+ if (! isset($folderRaw->id)) { // no folder found
+ return $this->error(['categoryName' => $dir, 'folderName' => $folderName], 'Cannot find folder in specified category', 200);
}
$videoList = VideoResource::collection(Video::where('folder_id', $folderRaw->id)->get());
- $data['folder'] = array('id' => $folderRaw->id, 'name' => $folderRaw->name, 'videos' => $videoList, 'series' => (isset($folderRaw->series) ? new SeriesResource($folderRaw->series) : null));
+ $data['folder'] = ['id' => $folderRaw->id, 'name' => $folderRaw->name, 'videos' => $videoList, 'series' => (isset($folderRaw->series) ? new SeriesResource($folderRaw->series) : null)];
return $this->success($data, '', 200);
} catch (\Throwable $th) {
@@ -98,11 +100,11 @@ class DirectoryController extends Controller {
$firstFolder_id = $folders->first()->id;
$videos = Video::select('name', 'path', 'date')->where('folder_id', $firstFolder_id)->get();
- dump(json_encode(array("success" => true, "result" => array("folders" => $folders->toArray(), "videos" => $videos->toArray()), "error" => ""), JSON_UNESCAPED_SLASHES));
+ dump(json_encode(['success' => true, 'result' => ['folders' => $folders->toArray(), 'videos' => $videos->toArray()], 'error' => ''], JSON_UNESCAPED_SLASHES));
//return json_encode(array("success"=>true, "result"=>array("folders"=>$folders->toArray(),"videos"=>$videos->toArray()), "error"=>""), JSON_UNESCAPED_SLASHES);
} catch (\Throwable $th) {
//throw $th;
- return json_encode(array("success" => false, "result" => array("folders" => array(), "videos" => array()), "error" => $th->getMessage()), JSON_UNESCAPED_SLASHES);
+ return json_encode(['success' => false, 'result' => ['folders' => [], 'videos' => []], 'error' => $th->getMessage()], JSON_UNESCAPED_SLASHES);
}
}
@@ -114,31 +116,30 @@ class DirectoryController extends Controller {
$category_id = Category::select('id')->firstWhere('name', $dir)->id;
$folders = Folder::select('id', 'name')->where('category_id', $category_id)->get();
- return (json_encode(array("success" => true, "result" => $folders->toArray(), "error" => ""), JSON_UNESCAPED_SLASHES));
+ return json_encode(['success' => true, 'result' => $folders->toArray(), 'error' => ''], JSON_UNESCAPED_SLASHES);
} catch (\Throwable $th) {
- return (json_encode(array("success" => false, "result" => array(), "error" => $th->getMessage()), JSON_UNESCAPED_SLASHES));
+ return json_encode(['success' => false, 'result' => [], 'error' => $th->getMessage()], JSON_UNESCAPED_SLASHES);
}
}
public function getFolderContents(VideoCollectionRequest $request) {
try {
- $folder_id = isset($request->folder_id) ? $request->folder_id : throw new ErrorException("No folder id or invalid folder name provided. Cannot generate videos.");
+ $folder_id = isset($request->folder_id) ? $request->folder_id : throw new ErrorException('No folder id or invalid folder name provided. Cannot generate videos.');
$videos = Video::select('id', 'name', 'path', 'date')->where('folder_id', $folder_id)->get();
- return (json_encode(array("success" => true, "result" => $videos->toArray(), "error" => ""), JSON_UNESCAPED_SLASHES));
+ return json_encode(['success' => true, 'result' => $videos->toArray(), 'error' => ''], JSON_UNESCAPED_SLASHES);
} catch (\Throwable $th) {
- return (json_encode(array("success" => false, "result" => array(), "error" => $th->getMessage()), JSON_UNESCAPED_SLASHES));
+ return json_encode(['success' => false, 'result' => [], 'error' => $th->getMessage()], JSON_UNESCAPED_SLASHES);
}
}
-
public function indexFiles(Request $request) {
try {
// IndexFiles::dispatchSync();
$chain = [
- new SyncFiles(),
- new IndexFiles()
+ new SyncFiles,
+ new IndexFiles,
];
Bus::batch($chain)->dispatch();
dump('This job now uses ffprobe so it must be async');
@@ -164,7 +165,7 @@ class DirectoryController extends Controller {
$chunks = [];
Video::orderBy('id')->chunk(20, function ($videos) use (&$chunks) {
- $chunks[] = $videos;
+ $chunks[] = $videos;
});
foreach ($chunks as $chunk) {
@@ -184,7 +185,7 @@ class DirectoryController extends Controller {
$chunks = [];
Folder::orderBy('id')->chunk(20, function ($folders) use (&$chunks) {
- $chunks[] = $folders;
+ $chunks[] = $folders;
});
foreach ($chunks as $chunk) {
@@ -206,7 +207,7 @@ class DirectoryController extends Controller {
$chunks = [];
Folder::orderBy('id')->chunk(20, function ($folders) use (&$chunks) {
- $chunks[] = $folders;
+ $chunks[] = $folders;
});
foreach ($chunks as $chunk) {
@@ -229,7 +230,7 @@ class DirectoryController extends Controller {
$chunks = [];
Video::orderBy('id')->chunk(20, function ($videos) use (&$chunks) {
- $chunks[] = $videos;
+ $chunks[] = $videos;
});
foreach ($chunks as $chunk) {
@@ -245,7 +246,7 @@ class DirectoryController extends Controller {
$chunks = [];
Folder::orderBy('id')->chunk(20, function ($folders) use (&$chunks) {
- $chunks[] = $folders;
+ $chunks[] = $folders;
});
foreach ($chunks as $chunk) {
@@ -257,7 +258,7 @@ class DirectoryController extends Controller {
dump($th);
}
- $jobs[] = new SyncFiles();
+ $jobs[] = new SyncFiles;
Bus::batch($jobs)->dispatch();
dump('This job has no web output. Check queue listener console for updates.');
diff --git a/app/Http/Controllers/MediaController.php b/app/Http/Controllers/MediaController.php
index d23ef9ab..e76e8cde 100644
--- a/app/Http/Controllers/MediaController.php
+++ b/app/Http/Controllers/MediaController.php
@@ -2,16 +2,16 @@
namespace App\Http\Controllers;
-use Illuminate\Support\Facades\Response;
-use Illuminate\Support\Facades\Storage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Response;
+use Illuminate\Support\Facades\Storage;
class MediaController extends Controller {
public function show(Request $request, $path) {
Log::info('Request path: ' . $path);
Log::info('Request full URL: ' . $request->fullUrl());
- if (!$request->hasValidSignature()) {
+ if (! $request->hasValidSignature()) {
Log::warning('Invalid signature for URL: ' . $request->fullUrl());
abort(403);
}
diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php
index 7ec1bb67..ae2affb4 100755
--- a/app/Http/Middleware/TrustProxies.php
+++ b/app/Http/Middleware/TrustProxies.php
@@ -5,8 +5,7 @@ namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
-class TrustProxies extends Middleware
-{
+class TrustProxies extends Middleware {
/**
* The trusted proxies for this application.
*
@@ -24,7 +23,7 @@ class TrustProxies extends Middleware
* @var int
*/
protected $headers =
- Request::HEADER_X_FORWARDED_FOR |
+ Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
diff --git a/app/Http/Requests/CategoryRequest.php b/app/Http/Requests/CategoryRequest.php
index b6609813..c5094234 100755
--- a/app/Http/Requests/CategoryRequest.php
+++ b/app/Http/Requests/CategoryRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class CategoryRequest extends FormRequest
-{
+class CategoryRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -20,11 +18,10 @@ class CategoryRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'category' => ['required'],
- 'dir' => []
+ 'dir' => [],
];
}
}
diff --git a/app/Http/Requests/FolderCollectionRequest.php b/app/Http/Requests/FolderCollectionRequest.php
index 3b9fb717..5551bf78 100755
--- a/app/Http/Requests/FolderCollectionRequest.php
+++ b/app/Http/Requests/FolderCollectionRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class FolderCollectionRequest extends FormRequest
-{
+class FolderCollectionRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,11 +17,10 @@ class FolderCollectionRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'category_id' => ['required'],
- 'dir' => []
+ 'dir' => [],
];
}
}
diff --git a/app/Http/Requests/MetadataStoreRequest.php b/app/Http/Requests/MetadataStoreRequest.php
index 8aa5b183..b0a5e190 100644
--- a/app/Http/Requests/MetadataStoreRequest.php
+++ b/app/Http/Requests/MetadataStoreRequest.php
@@ -5,13 +5,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
-class MetadataStoreRequest extends FormRequest
-{
+class MetadataStoreRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return Auth::check();
}
@@ -20,8 +18,7 @@ class MetadataStoreRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'video_id' => 'required|integer',
'title' => 'required|max:255',
diff --git a/app/Http/Requests/MetadataUpdateRequest.php b/app/Http/Requests/MetadataUpdateRequest.php
index fa636744..d53b1de5 100644
--- a/app/Http/Requests/MetadataUpdateRequest.php
+++ b/app/Http/Requests/MetadataUpdateRequest.php
@@ -5,13 +5,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
-class MetadataUpdateRequest extends FormRequest
-{
+class MetadataUpdateRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return Auth::check();
}
@@ -20,8 +18,7 @@ class MetadataUpdateRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'title' => 'required|max:255',
'description' => 'nullable|max:512',
diff --git a/app/Http/Requests/PlaybackCollectionRequest.php b/app/Http/Requests/PlaybackCollectionRequest.php
index 0806488a..552fb9e7 100644
--- a/app/Http/Requests/PlaybackCollectionRequest.php
+++ b/app/Http/Requests/PlaybackCollectionRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class PlaybackCollectionRequest extends FormRequest
-{
+class PlaybackCollectionRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,8 +17,7 @@ class PlaybackCollectionRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'metadata_id' => ['required'],
];
diff --git a/app/Http/Requests/PlaybackStoreRequest.php b/app/Http/Requests/PlaybackStoreRequest.php
index 586eb258..f1f5d2fd 100644
--- a/app/Http/Requests/PlaybackStoreRequest.php
+++ b/app/Http/Requests/PlaybackStoreRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class PlaybackStoreRequest extends FormRequest
-{
+class PlaybackStoreRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,12 +17,11 @@ class PlaybackStoreRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'entries' => 'array|required|min:1',
'entries.*.metadata_id' => 'required|integer',
- 'entries.*.progress' => 'required|numeric|between:0,1000'
+ 'entries.*.progress' => 'required|numeric|between:0,1000',
];
}
}
diff --git a/app/Http/Requests/RecordStoreRequest.php b/app/Http/Requests/RecordStoreRequest.php
index 65273416..7e612332 100755
--- a/app/Http/Requests/RecordStoreRequest.php
+++ b/app/Http/Requests/RecordStoreRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class RecordStoreRequest extends FormRequest
-{
+class RecordStoreRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,10 +17,9 @@ class RecordStoreRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
- 'video_id' => 'required|integer'
+ 'video_id' => 'required|integer',
];
}
}
diff --git a/app/Http/Requests/SeriesStoreRequest.php b/app/Http/Requests/SeriesStoreRequest.php
index f32caa1e..a108b53c 100644
--- a/app/Http/Requests/SeriesStoreRequest.php
+++ b/app/Http/Requests/SeriesStoreRequest.php
@@ -5,13 +5,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
-class SeriesStoreRequest extends FormRequest
-{
+class SeriesStoreRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return Auth::check();
}
@@ -20,8 +18,7 @@ class SeriesStoreRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'folder_id' => 'required|integer',
'title' => 'required|max:255',
@@ -33,7 +30,7 @@ class SeriesStoreRequest extends FormRequest
'films' => 'nullable|integer|min:0',
'date_start' => 'nullable|date|date_format:"F d, Y"',
'date_end' => 'nullable|date|date_format:"F d, Y"',
- 'thumbnail_url' => 'nullable|url'
+ 'thumbnail_url' => 'nullable|url',
];
}
}
diff --git a/app/Http/Requests/SeriesUpdateRequest.php b/app/Http/Requests/SeriesUpdateRequest.php
index e7c4abba..477e1b01 100644
--- a/app/Http/Requests/SeriesUpdateRequest.php
+++ b/app/Http/Requests/SeriesUpdateRequest.php
@@ -5,13 +5,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
-class SeriesUpdateRequest extends FormRequest
-{
+class SeriesUpdateRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return Auth::check();
}
@@ -20,8 +18,7 @@ class SeriesUpdateRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'title' => 'required|max:255',
'description' => 'nullable|max:512',
@@ -32,7 +29,7 @@ class SeriesUpdateRequest extends FormRequest
'films' => 'nullable|integer|min:0',
'date_start' => 'nullable|date|date_format:"F d, Y"',
'date_end' => 'nullable|date|date_format:"F d, Y"',
- 'thumbnail_url' => 'nullable|url'
+ 'thumbnail_url' => 'nullable|url',
];
}
}
diff --git a/app/Http/Requests/TagStoreRequest.php b/app/Http/Requests/TagStoreRequest.php
index 3c794b36..4192f76d 100644
--- a/app/Http/Requests/TagStoreRequest.php
+++ b/app/Http/Requests/TagStoreRequest.php
@@ -5,13 +5,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
-class TagStoreRequest extends FormRequest
-{
+class TagStoreRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return Auth::check();
}
@@ -20,10 +18,9 @@ class TagStoreRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
- 'name' => ['required', 'min:1']
+ 'name' => ['required', 'min:1'],
];
}
}
diff --git a/app/Http/Requests/UserLoginRequest.php b/app/Http/Requests/UserLoginRequest.php
index 20354243..b3ccd716 100644
--- a/app/Http/Requests/UserLoginRequest.php
+++ b/app/Http/Requests/UserLoginRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class UserLoginRequest extends FormRequest
-{
+class UserLoginRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,12 +17,11 @@ class UserLoginRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'email' => ['required', 'string', 'email'],
'password' => ['required', 'string', 'min:6'],
- 'remember' => ['boolean']
+ 'remember' => ['boolean'],
];
}
}
diff --git a/app/Http/Requests/UserStoreRequest.php b/app/Http/Requests/UserStoreRequest.php
index ea332cee..492ae336 100644
--- a/app/Http/Requests/UserStoreRequest.php
+++ b/app/Http/Requests/UserStoreRequest.php
@@ -5,13 +5,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules;
-class UserStoreRequest extends FormRequest
-{
+class UserStoreRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -20,12 +18,11 @@ class UserStoreRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'name' => ['required', 'string', 'max:255', 'unique:users'],
'email' => ['required', 'string', 'max:255', 'unique:users'],
- 'password' => ['required', 'confirmed', Rules\Password::defaults()]
+ 'password' => ['required', 'confirmed', Rules\Password::defaults()],
];
}
}
diff --git a/app/Http/Requests/VideoCollectionRequest.php b/app/Http/Requests/VideoCollectionRequest.php
index 0ffcf909..dfa92ab3 100755
--- a/app/Http/Requests/VideoCollectionRequest.php
+++ b/app/Http/Requests/VideoCollectionRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class VideoCollectionRequest extends FormRequest
-{
+class VideoCollectionRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,10 +17,9 @@ class VideoCollectionRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
- 'folder_id' => ['required']
+ 'folder_id' => ['required'],
];
}
}
diff --git a/app/Http/Requests/VideoUpdateRequest.php b/app/Http/Requests/VideoUpdateRequest.php
index fb457e0e..d2b34300 100755
--- a/app/Http/Requests/VideoUpdateRequest.php
+++ b/app/Http/Requests/VideoUpdateRequest.php
@@ -4,13 +4,11 @@ namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
-class VideoUpdateRequest extends FormRequest
-{
+class VideoUpdateRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*/
- public function authorize(): bool
- {
+ public function authorize(): bool {
return true;
}
@@ -19,8 +17,7 @@ class VideoUpdateRequest extends FormRequest
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
- public function rules(): array
- {
+ public function rules(): array {
return [
'title' => 'required|max:255',
'description' => 'max:512',
diff --git a/app/Http/Resources/CategoryResource.php b/app/Http/Resources/CategoryResource.php
index dc994baf..bf240bc1 100755
--- a/app/Http/Resources/CategoryResource.php
+++ b/app/Http/Resources/CategoryResource.php
@@ -13,7 +13,7 @@ class CategoryResource extends JsonResource {
*/
public function toArray(Request $request): array {
return [
- 'id' => (string)$this->id,
+ 'id' => (string) $this->id,
'name' => $this->name,
'folders_count' => $this->folders_count ?? 0,
'folders' => FolderResource::collection($this->folders),
diff --git a/app/Http/Resources/FolderResource.php b/app/Http/Resources/FolderResource.php
index f4e337fb..ad52255a 100755
--- a/app/Http/Resources/FolderResource.php
+++ b/app/Http/Resources/FolderResource.php
@@ -6,7 +6,6 @@ use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class FolderResource extends JsonResource {
-
/**
* Transform the resource into an array.
*
@@ -23,7 +22,7 @@ class FolderResource extends JsonResource {
'videos' => $this->when($request->videos, function () {
return VideoResource::collection($this->videos);
}),
- 'series' => new SeriesResource($this->series)
+ 'series' => new SeriesResource($this->series),
];
}
}
diff --git a/app/Http/Resources/MetadataResource.php b/app/Http/Resources/MetadataResource.php
index de42a712..e3203fe6 100644
--- a/app/Http/Resources/MetadataResource.php
+++ b/app/Http/Resources/MetadataResource.php
@@ -23,14 +23,14 @@ class MetadataResource extends JsonResource {
'view_count' => $this->view_count,
'file_size' => $this->file_size,
'date_released' => $this->date_released,
- 'date_updated' => $this->updated_at
+ 'date_updated' => $this->updated_at,
],
'relationships' => [
'video_id' => $this->video_id,
'editor_id' => $this->editor_id,
// 'playback_data' => PlaybackResource::collection($this->playbacks),
'video_tags' => VideoTagResource::collection($this->videoTags),
- ]
+ ],
];
}
}
diff --git a/app/Http/Resources/PlaybackResource.php b/app/Http/Resources/PlaybackResource.php
index 563c78ec..747a6e17 100644
--- a/app/Http/Resources/PlaybackResource.php
+++ b/app/Http/Resources/PlaybackResource.php
@@ -15,12 +15,12 @@ class PlaybackResource extends JsonResource {
return [
'id' => $this->id,
'attributes' => [
- 'progress' => $this->progress
+ 'progress' => $this->progress,
],
'relationships' => [
'metadata_id' => $this->metadata_id,
// 'video_id' => $this->metadata ? $this->metadata->video_id : null, ?? dont need ??
- ]
+ ],
];
}
}
diff --git a/app/Http/Resources/Pulse/DashboardResource.php b/app/Http/Resources/Pulse/DashboardResource.php
new file mode 100644
index 00000000..44646b97
--- /dev/null
+++ b/app/Http/Resources/Pulse/DashboardResource.php
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Resources\Pulse;
+
+use Illuminate\Http\Request;
+
+class DashboardResource extends PulseResource {
+ public function toArray(Request $request): array {
+ $resources = config('pulse-api.resources');
+
+ $result = $resources->mapWithKeys(function (string $resource, string $key) use ($request) {
+ return (new $resource(null, $this->period))->toArray($request);
+ });
+
+ return $result->toArray();
+ }
+}
diff --git a/app/Http/Resources/Pulse/PulseResource.php b/app/Http/Resources/Pulse/PulseResource.php
new file mode 100644
index 00000000..ad6d2258
--- /dev/null
+++ b/app/Http/Resources/Pulse/PulseResource.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace App\Http\Resources\Pulse;
+
+use Illuminate\Http\Resources\Json\JsonResource;
+use Illuminate\Support\Collection;
+use Laravel\Pulse\Facades\Pulse;
+use Laravel\Pulse\Livewire\Concerns\HasPeriod;
+use Laravel\Pulse\Livewire\Concerns\RemembersQueries;
+
+class PulseResource extends JsonResource {
+ use HasPeriod, RemembersQueries;
+
+ public function __construct($resource, $period) {
+ parent::__construct($resource);
+ $this->period = $period;
+ }
+
+ /**
+ * Retrieve values for the given type.
+ *
+ * @param list<string> $keys
+ * @return \Illuminate\Support\Collection<string, object{
+ * timestamp: int,
+ * key: string,
+ * value: string
+ * }>
+ */
+ protected function values(string $type, ?array $keys = null): Collection {
+ return Pulse::values($type, $keys);
+ }
+
+ /**
+ * Retrieve aggregate values for plotting on a graph.
+ *
+ * @param list<string> $types
+ * @param 'count'|'min'|'max'|'sum'|'avg' $aggregate
+ * @return \Illuminate\Support\Collection<string, \Illuminate\Support\Collection<string, \Illuminate\Support\Collection<string, int|null>>>
+ */
+ protected function graph(array $types, string $aggregate): Collection {
+ return Pulse::graph($types, $aggregate, $this->periodAsInterval());
+ }
+
+ /**
+ * Retrieve aggregate values for the given type.
+ *
+ * @param 'count'|'min'|'max'|'sum'|'avg'|list<'count'|'min'|'max'|'sum'|'avg'> $aggregates
+ * @return \Illuminate\Support\Collection<int, mixed>
+ */
+ protected function aggregate(
+ string $type,
+ string|array $aggregates,
+ ?string $orderBy = null,
+ string $direction = 'desc',
+ int $limit = 101,
+ ): Collection {
+ return Pulse::aggregate($type, $aggregates, $this->periodAsInterval(), $orderBy, $direction, $limit);
+ }
+
+ /**
+ * Retrieve aggregate values for the given types.
+ *
+ * @param string|list<string> $types
+ * @param 'count'|'min'|'max'|'sum'|'avg' $aggregate
+ * @return \Illuminate\Support\Collection<int, mixed>
+ */
+ protected function aggregateTypes(
+ string|array $types,
+ string $aggregate,
+ ?string $orderBy = null,
+ string $direction = 'desc',
+ int $limit = 101,
+ ): Collection {
+ return Pulse::aggregateTypes($types, $aggregate, $this->periodAsInterval(), $orderBy, $direction, $limit);
+ }
+
+ /**
+ * Retrieve an aggregate total for the given types.
+ *
+ * @param string|list<string> $types
+ * @param 'count'|'min'|'max'|'sum'|'avg' $aggregate
+ * @return float|\Illuminate\Support\Collection<string, int>
+ */
+ protected function aggregateTotal(
+ array|string $types,
+ string $aggregate,
+ ): float|Collection {
+ return Pulse::aggregateTotal($types, $aggregate, $this->periodAsInterval());
+ }
+}
diff --git a/app/Http/Resources/RecordResource.php b/app/Http/Resources/RecordResource.php
index 540b1a98..9fbd5466 100755
--- a/app/Http/Resources/RecordResource.php
+++ b/app/Http/Resources/RecordResource.php
@@ -6,11 +6,13 @@ use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class RecordResource extends JsonResource {
-
// Mega Yikes AI code
protected static $categoryCache = [];
+
protected static $folderCache = [];
+
protected static $metadataCache = [];
+
protected static $videoCache = [];
/**
@@ -44,7 +46,6 @@ class RecordResource extends JsonResource {
$folderId = $video?->folder_id;
-
if ($folderId) {
if (isset(self::$folderCache[$folderId])) {
$folder = self::$folderCache[$folderId];
@@ -63,19 +64,19 @@ class RecordResource extends JsonResource {
}
return [
- 'id' => (string)$this->id,
+ 'id' => (string) $this->id,
'attributes' => [
'created_at' => $this->created_at,
- 'updated_at' => $this->updated_at
+ 'updated_at' => $this->updated_at,
],
'relationships' => [
- 'folder' => $folder ?? array("name" => 'Unknown'),
+ 'folder' => $folder ?? ['name' => 'Unknown'],
'metadata' => $metadata,
'category' => $category,
'video_id' => $videoId,
'video_name' => $metadata->title ?? $this->name ?? 'Deleted',
'file_name' => $this->name,
- ]
+ ],
];
}
}
diff --git a/app/Http/Resources/SeriesResource.php b/app/Http/Resources/SeriesResource.php
index 23eaac23..8386a86f 100644
--- a/app/Http/Resources/SeriesResource.php
+++ b/app/Http/Resources/SeriesResource.php
@@ -6,8 +6,8 @@ use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class SeriesResource extends JsonResource {
-
protected static $editorCache = [];
+
/**
* Transform the resource into an array.
*
@@ -23,6 +23,7 @@ class SeriesResource extends JsonResource {
$editor = $this->editor;
self::$editorCache[$editorId] = $editor;
}
+
return [
'id' => $this->id,
'folder_id' => $this->folder_id,
diff --git a/app/Http/Resources/TagResource.php b/app/Http/Resources/TagResource.php
index 903253e1..b182a296 100644
--- a/app/Http/Resources/TagResource.php
+++ b/app/Http/Resources/TagResource.php
@@ -17,7 +17,7 @@ class TagResource extends JsonResource {
'name' => $this->name,
'relationships' => [
'creator_id' => $this->creator_id,
- ]
+ ],
];
}
}
diff --git a/app/Http/Resources/VideoResource.php b/app/Http/Resources/VideoResource.php
index 1c99295d..3a8d5f9b 100755
--- a/app/Http/Resources/VideoResource.php
+++ b/app/Http/Resources/VideoResource.php
@@ -13,8 +13,9 @@ class VideoResource extends JsonResource {
*/
public function toArray(Request $request): array {
$metadata = $this->metadata;
+
return [
- 'id' => (string)$this->id,
+ 'id' => (string) $this->id,
// 'path' => $this->path,
// 'name' => $this->name,
// 'date' => $this->date,
@@ -22,7 +23,6 @@ class VideoResource extends JsonResource {
// 'folder_id' => (string)$this->folder->id,
// 'metadata' => new MetadataResource($metadata),
-
// 'attributes' => [
'name' => $this->name,
'path' => $this->path,
diff --git a/app/Jobs/CleanFolderPaths.php b/app/Jobs/CleanFolderPaths.php
index d54bce63..0c7dd640 100644
--- a/app/Jobs/CleanFolderPaths.php
+++ b/app/Jobs/CleanFolderPaths.php
@@ -32,15 +32,16 @@ class CleanFolderPaths implements ShouldQueue {
if (count($this->folders) == 0) {
dump('Folder Data Lost');
+
return;
}
- $transactions = array();
+ $transactions = [];
$error = false;
foreach ($this->folders as $folder) {
try {
- $stored = array();
- $changes = array();
+ $stored = [];
+ $changes = [];
$stored = $folder->toArray();
@@ -60,18 +61,20 @@ class CleanFolderPaths implements ShouldQueue {
}
}
- if (count($transactions) == 0 || $error == true) return;
+ if (count($transactions) == 0 || $error == true) {
+ return;
+ }
Folder::upsert($transactions, 'id', ['path']);
$msg = 'Updated ' . count($transactions) . ' folder path(s) from id ' . ($transactions[0]['id']) . ' to ' . ($transactions[count($transactions) - 1]['id']);
dump($msg);
- $dataCache = Storage::json('dataCache.json') ?? array();
- $dataCache[date("Y-m-d-h:i:sa")] = array(
- "job" => "cleanFolderPaths",
- "message" => $msg,
- "data" => $transactions,
- );
+ $dataCache = Storage::json('dataCache.json') ?? [];
+ $dataCache[date('Y-m-d-h:i:sa')] = [
+ 'job' => 'cleanFolderPaths',
+ 'message' => $msg,
+ 'data' => $transactions,
+ ];
Storage::put('dataCache.json', json_encode($dataCache, JSON_UNESCAPED_SLASHES));
}
}
diff --git a/app/Jobs/CleanVideoPaths.php b/app/Jobs/CleanVideoPaths.php
index 7d29c65b..8868c7f5 100644
--- a/app/Jobs/CleanVideoPaths.php
+++ b/app/Jobs/CleanVideoPaths.php
@@ -32,15 +32,16 @@ class CleanVideoPaths implements ShouldQueue {
if (count($this->videos) == 0) {
dump('Video Data Lost');
+
return;
}
- $transactions = array();
+ $transactions = [];
$error = false;
foreach ($this->videos as $video) {
try {
- $stored = array();
- $changes = array();
+ $stored = [];
+ $changes = [];
$stored = $video->toArray();
@@ -60,18 +61,20 @@ class CleanVideoPaths implements ShouldQueue {
}
}
- if (count($transactions) == 0 || $error == true) return;
+ if (count($transactions) == 0 || $error == true) {
+ return;
+ }
Video::upsert($transactions, 'id', ['path']);
$msg = 'Updated ' . count($transactions) . ' video path(s) from id ' . ($transactions[0]['id']) . ' to ' . ($transactions[count($transactions) - 1]['id']);
dump($msg);
- $dataCache = Storage::json('dataCache.json') ?? array();
- $dataCache[date("Y-m-d-h:i:sa")] = array(
- "job" => "cleanVideoPaths",
- "message" => $msg,
- "data" => $transactions,
- );
+ $dataCache = Storage::json('dataCache.json') ?? [];
+ $dataCache[date('Y-m-d-h:i:sa')] = [
+ 'job' => 'cleanVideoPaths',
+ 'message' => $msg,
+ 'data' => $transactions,
+ ];
Storage::put('dataCache.json', json_encode($dataCache, JSON_UNESCAPED_SLASHES));
}
}
diff --git a/app/Jobs/EmbedUidInMetadata.php b/app/Jobs/EmbedUidInMetadata.php
index baf60b8a..dea5583f 100644
--- a/app/Jobs/EmbedUidInMetadata.php
+++ b/app/Jobs/EmbedUidInMetadata.php
@@ -8,14 +8,15 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\Attributes\DeleteWhenMissingModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
-use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
+use Symfony\Component\Process\Process;
#[DeleteWhenMissingModels]
class EmbedUidInMetadata implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $filePath;
+
protected $uid;
/**
@@ -38,8 +39,9 @@ class EmbedUidInMetadata implements ShouldQueue {
dump("Adding uuid to $this->filePath");
- if (!file_exists($this->filePath)) {
- dump("UUID Fail file does not exist");
+ if (! file_exists($this->filePath)) {
+ dump('UUID Fail file does not exist');
+
return;
}
@@ -60,13 +62,13 @@ class EmbedUidInMetadata implements ShouldQueue {
"uid=$this->uid",
'-f',
$format,
- $tempFilePath
+ $tempFilePath,
];
$process = new Process($command);
$process->run();
- if (!$process->isSuccessful()) {
+ if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
@@ -100,7 +102,7 @@ class EmbedUidInMetadata implements ShouldQueue {
$process->run();
// Check if the process was successful
- if (!$process->isSuccessful()) {
+ if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
diff --git a/app/Jobs/IndexFiles.php b/app/Jobs/IndexFiles.php
index ddfb09ac..71bde539 100755
--- a/app/Jobs/IndexFiles.php
+++ b/app/Jobs/IndexFiles.php
@@ -2,30 +2,27 @@
namespace App\Jobs;
+use App\Models\Category;
+use App\Models\Folder;
+use App\Models\Metadata;
+use App\Models\Series;
+use App\Models\Video;
+use Exception;
+use FFMpeg\FFProbe as FFMpegFFProbe;
+use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
-use Illuminate\Bus\Batchable;
-
+use Ramsey\Uuid\Uuid;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
-use FFMpeg\FFProbe as FFMpegFFProbe;
-use Ramsey\Uuid\Uuid;
-
-use App\Models\Category;
-use App\Models\Folder;
-use App\Models\Metadata;
-use App\Models\Series;
-use App\Models\Video;
-use Exception;
-
-class IndexFiles implements ShouldQueue, ShouldBeUnique {
+class IndexFiles implements ShouldBeUnique, ShouldQueue {
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
@@ -44,55 +41,54 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
}
public function generateData() {
- $path = "media/";
- $dbOut = "";
+ $path = 'media/';
+ $dbOut = '';
- if (!Storage::disk('public')->exists($path)) {
+ if (! Storage::disk('public')->exists($path)) {
$error = 'Invalid Directory: "media"';
- dd(json_encode(array("success" => false, "result" => "", "error" => $error), JSON_UNESCAPED_SLASHES));
+ dd(json_encode(['success' => false, 'result' => '', 'error' => $error], JSON_UNESCAPED_SLASHES));
}
$realPath = Storage::disk('public')->path($path);
$directories = $this->generateCategories($realPath);
- $subDirectories = $this->generateFolders($path, $directories["data"]["categoryStructure"]);
- $files = $this->generateVideos($path, $subDirectories["data"]["folderStructure"], $directories["data"]["categoryStructure"]);
-
- if (isset($files["updatedFolderStructure"])) $subDirectories["data"]["folderStructure"] = $files["updatedFolderStructure"];
+ $subDirectories = $this->generateFolders($path, $directories['data']['categoryStructure']);
+ $files = $this->generateVideos($path, $subDirectories['data']['folderStructure'], $directories['data']['categoryStructure']);
+ if (isset($files['updatedFolderStructure'])) {
+ $subDirectories['data']['folderStructure'] = $files['updatedFolderStructure'];
+ }
- $categories = $directories["categoryChanges"];
- $folders = $subDirectories["folderChanges"];
- $videos = $files["videoChanges"];
-
- $seriesEntries = $subDirectories["seriesChanges"];
- $metaDataEntries = $files["metadataChanges"];
-
+ $categories = $directories['categoryChanges'];
+ $folders = $subDirectories['folderChanges'];
+ $videos = $files['videoChanges'];
- $categoryTransactions = array();
- $folderTransactions = array();
- $videoTransactions = array();
+ $seriesEntries = $subDirectories['seriesChanges'];
+ $metaDataEntries = $files['metadataChanges'];
- $seriesTransactions = array();
- $metadataTransactions = array();
+ $categoryTransactions = [];
+ $folderTransactions = [];
+ $videoTransactions = [];
- $categoryDeletions = array();
- $folderDeletions = array();
- $videoDeletions = array();
+ $seriesTransactions = [];
+ $metadataTransactions = [];
+ $categoryDeletions = [];
+ $folderDeletions = [];
+ $videoDeletions = [];
foreach ($categories as $categoryChange) { // for each in stored, remove from new (delete)
$changeID = $categoryChange['id'];
- $changeName = $categoryChange["name"];
- $changeMediaContent = $categoryChange["media_content"] ?? 'False';
- $changeAction = $categoryChange["action"];
+ $changeName = $categoryChange['name'];
+ $changeMediaContent = $categoryChange['media_content'] ?? 'False';
+ $changeAction = $categoryChange['action'];
- if ($changeAction === "INSERT") {
+ if ($changeAction === 'INSERT') {
$dbOut .= "INSERT INTO [Categories] VALUES ($changeID, $changeName, $changeMediaContent );\n"; // insert
$transaction = $categoryChange;
- unset($transaction["action"]);
+ unset($transaction['action']);
array_push($categoryTransactions, $transaction);
} else {
$dbOut .= "DELETE FROM [Categories] WHERE [Categories].[ID] = {$changeID};\n";
@@ -102,16 +98,16 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
foreach ($folders as $folderChange) { // for each in stored, remove from new (delete)
$changeID = $folderChange['id'];
- $changeName = $folderChange["name"];
- $changePath = $folderChange["path"];
- $changeCategoryID = $folderChange["category_id"];
- $changeAction = $folderChange["action"];
+ $changeName = $folderChange['name'];
+ $changePath = $folderChange['path'];
+ $changeCategoryID = $folderChange['category_id'];
+ $changeAction = $folderChange['action'];
- if ($changeAction === "INSERT") {
+ if ($changeAction === 'INSERT') {
$dbOut .= "INSERT INTO [Folders] VALUES ({$changeID}, {$changeName}, {$changePath}, {$changeCategoryID} );\n"; // insert
$transaction = $folderChange;
- unset($transaction["action"]);
+ unset($transaction['action']);
array_push($folderTransactions, $transaction);
} else {
$dbOut .= "DELETE FROM [Folders] WHERE [Folder].[ID] = {$changeID};\n";
@@ -121,7 +117,7 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
foreach ($seriesEntries as $seriesChange) { // log series additions
$folderID = $seriesChange['folder_id'];
- $compositeID = $seriesChange["composite_id"];
+ $compositeID = $seriesChange['composite_id'];
$dbOut .= "INSERT INTO [series] VALUES ({$folderID}, {$compositeID});\n"; // insert
@@ -130,18 +126,18 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
foreach ($videos as $videoChange) { // for each in stored, remove from new (delete)
$changeID = $videoChange['id'];
- $changeUUID = $videoChange["uuid"];
- $changeName = $videoChange["name"];
- $changePath = $videoChange["path"];
- $changeFolderID = $videoChange["folder_id"];
- $changeDate = $videoChange["date"];
- $changeAction = $videoChange["action"];
-
- if ($changeAction === "INSERT") {
+ $changeUUID = $videoChange['uuid'];
+ $changeName = $videoChange['name'];
+ $changePath = $videoChange['path'];
+ $changeFolderID = $videoChange['folder_id'];
+ $changeDate = $videoChange['date'];
+ $changeAction = $videoChange['action'];
+
+ if ($changeAction === 'INSERT') {
$dbOut .= "INSERT INTO [Videos] VALUES ({$changeID}, {$changeUUID}, {$changeName}, {$changePath}, {$changeFolderID}, {$changeDate});\n"; // insert
$transaction = $videoChange;
- unset($transaction["action"]);
+ unset($transaction['action']);
array_push($videoTransactions, $transaction);
} else {
$dbOut .= "DELETE FROM [Videos] WHERE [Video].[ID] = {$changeID};\n";
@@ -151,18 +147,17 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
foreach ($metaDataEntries as $metadataChange) { // log metadata additions
$videoID = $metadataChange['video_id'];
- $compositeID = $metadataChange["composite_id"];
+ $compositeID = $metadataChange['composite_id'];
$uuid = $metadataChange['uuid'];
- $file_size = $metadataChange["file_size"];
- $duration = $metadataChange["duration"];
- $date_scanned = $metadataChange["date_scanned"];
+ $file_size = $metadataChange['file_size'];
+ $duration = $metadataChange['duration'];
+ $date_scanned = $metadataChange['date_scanned'];
$dbOut .= "INSERT INTO [metadata] VALUES ({$videoID}, {$compositeID}, {$uuid}, {$file_size}, {$duration}, {$date_scanned});\n"; // insert
array_push($metadataTransactions, $metadataChange);
}
-
try {
Video::destroy($videoDeletions);
Folder::destroy($folderDeletions);
@@ -181,23 +176,22 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$this->upsertMetadata($data);
}
-
// One day logging should be put in the database
- Storage::put('categories.json', json_encode($directories["data"], JSON_UNESCAPED_SLASHES));
- Storage::put('folders.json', json_encode($subDirectories["data"], JSON_UNESCAPED_SLASHES));
- Storage::put('videos.json', json_encode($files["data"], JSON_UNESCAPED_SLASHES));
+ Storage::put('categories.json', json_encode($directories['data'], JSON_UNESCAPED_SLASHES));
+ Storage::put('folders.json', json_encode($subDirectories['data'], JSON_UNESCAPED_SLASHES));
+ Storage::put('videos.json', json_encode($files['data'], JSON_UNESCAPED_SLASHES));
- $data = array("categories" => $categories, "folders" => $folders, "videos" => $videos);
+ $data = ['categories' => $categories, 'folders' => $folders, 'videos' => $videos];
- $dataCache = Storage::json('dataCache.json') ?? array();
- $dataCache[date("Y-m-d-h:i:sa")] = array("job" => "index", "data" => $data);
+ $dataCache = Storage::json('dataCache.json') ?? [];
+ $dataCache[date('Y-m-d-h:i:sa')] = ['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::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);
+ 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;
@@ -205,13 +199,13 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
}
private function generateCategories($path) {
- $data = Storage::json('categories.json') ?? array("next_ID" => 1, "categoryStructure" => array()); //array("anime"=>1,"tv"=>2,"yogscast"=>3); // read from json
- $scanned = array_map("htmlspecialchars", scandir($path)); // read folder structure
+ $data = Storage::json('categories.json') ?? ['next_ID' => 1, 'categoryStructure' => []]; //array("anime"=>1,"tv"=>2,"yogscast"=>3); // read from json
+ $scanned = array_map('htmlspecialchars', scandir($path)); // read folder structure
- $currentID = $data["next_ID"];
- $stored = $data["categoryStructure"];
- $changes = array(); // send to db
- $current = array(); // save into json
+ $currentID = $data['next_ID'];
+ $stored = $data['categoryStructure'];
+ $changes = []; // send to db
+ $current = []; // save into json
/*
If scanned is in stored, add to current, remove from stored
@@ -226,7 +220,9 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
save current to json
*/
foreach ($scanned as $local) { // O(n) where n = number of already known categories
- if (is_dir($local)) continue; //? . and .. are dirs
+ if (is_dir($local)) {
+ continue;
+ } //? . and .. are dirs
$name = basename($local);
@@ -234,7 +230,7 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$current[$name] = $stored[$name]; // add to current
unset($stored[$name]); // remove from stored
} else { // If scanned not in stored, add to current, add to new (insert), id++
- $generated = array("id" => $currentID, "name" => $name, "media_content" => 'False', "action" => "INSERT");
+ $generated = ['id' => $currentID, 'name' => $name, 'media_content' => 'False', 'action' => 'INSERT'];
$current[$name] = $currentID; // add to current
array_push($changes, $generated); // add to new (insert)
$currentID++;
@@ -242,27 +238,27 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
}
foreach ($stored as $remainingID) {
- $generated = array("id" => $remainingID, "name" => null, "media_content" => null, "action" => "DELETE"); // delete by id
+ $generated = ['id' => $remainingID, 'name' => null, 'media_content' => null, 'action' => 'DELETE']; // delete by id
array_push($changes, $generated); // add to new (delete)
}
- $data["next_ID"] = $currentID;
- $data["categoryStructure"] = $current;
+ $data['next_ID'] = $currentID;
+ $data['categoryStructure'] = $current;
- return array("categoryChanges" => $changes, "data" => $data);
+ return ['categoryChanges' => $changes, 'data' => $data];
}
private function generateFolders($path, $categoryStructure) {
- $data = Storage::json('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
+ $data = Storage::json('folders.json') ?? ['next_ID' => 1, 'folderStructure' => []]; //array("anime/frieren"=>array("id"=>0,"name"=>"frieren"),"starwars/andor"=>array("id"=1,"name"="andor")); // read from json
$scannedCategories = array_keys($categoryStructure);
$cost = 0;
- $currentID = $data["next_ID"];
- $stored = $data["folderStructure"];
- $changes = array(); // send to db
- $current = array(); // save into json into json
+ $currentID = $data['next_ID'];
+ $stored = $data['folderStructure'];
+ $changes = []; // send to db
+ $current = []; // save into json into json
- $seriesChanges = array();
+ $seriesChanges = [];
/*foreach ($stored as $savedFolder){ // O(n) where n = number of already known categories
$currentID = max($currentID, $savedFolder["id"] + 1); // gets max currently used id
@@ -300,15 +296,17 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$name = basename($folder);
$key = "$category/$name";
- if ($name === ".thumbs") continue;
+ if ($name === '.thumbs') {
+ continue;
+ }
if (isset($stored[$key])) {
$current[$key] = $stored[$key]; // add to current
unset($stored[$key]); // remove from stored
} else {
- $generated = array("id" => $currentID, "name" => $name, "path" => $key, "category_id" => $categoryStructure[$category], "action" => "INSERT");
- $series = array("folder_id" => $currentID, "composite_id" => $key);
- $current[$key] = array("id" => $currentID, "last_scan" => -1); // add to current
+ $generated = ['id' => $currentID, 'name' => $name, 'path' => $key, 'category_id' => $categoryStructure[$category], 'action' => 'INSERT'];
+ $series = ['folder_id' => $currentID, 'composite_id' => $key];
+ $current[$key] = ['id' => $currentID, 'last_scan' => -1]; // add to current
array_push($changes, $generated);
array_push($seriesChanges, $series); // add to new (insert)
$currentID++;
@@ -316,30 +314,31 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
}
}
foreach ($stored as $remainingFolder) {
- $generated = array("id" => $remainingFolder['id'], "name" => null, "path" => null, "category_id" => null, "action" => "DELETE"); // delete by id -> Used to store just ID -> Now store id and last_scan
+ $generated = ['id' => $remainingFolder['id'], 'name' => null, 'path' => null, 'category_id' => null, 'action' => 'DELETE']; // delete by id -> Used to store just ID -> Now store id and last_scan
array_push($changes, $generated); // add to new (delete)
$cost++;
}
- $data["next_ID"] = $currentID;
- $data["folderStructure"] = $current;
- return array("folderChanges" => $changes, "data" => $data, "cost" => $cost, "seriesChanges" => $seriesChanges);
+ $data['next_ID'] = $currentID;
+ $data['folderStructure'] = $current;
+
+ return ['folderChanges' => $changes, 'data' => $data, 'cost' => $cost, 'seriesChanges' => $seriesChanges];
}
private function generateVideos($path, $folderStructure) {
- $data = Storage::json('videos.json') ?? array("next_ID" => 1, "videoStructure" => array()); //array("anime/frieren/S1E01.mp4"=>array("id"=>0,"name"=>"S1E01"),"starwars/andor/S1E01.mkv"=>array("id"=1,"name"="S1E01.mkv")); // read from json
+ $data = Storage::json('videos.json') ?? ['next_ID' => 1, 'videoStructure' => []]; //array("anime/frieren/S1E01.mp4"=>array("id"=>0,"name"=>"S1E01"),"starwars/andor/S1E01.mkv"=>array("id"=1,"name"="S1E01.mkv")); // read from json
$scannedFolders = array_keys($folderStructure);
$cost = 0;
- $currentID = $data["next_ID"];
- $stored = $data["videoStructure"];
- $changes = array(); // send to db
- $current = array(); // save into json into json
+ $currentID = $data['next_ID'];
+ $stored = $data['videoStructure'];
+ $changes = []; // send to db
+ $current = []; // save into json into json
- $metadataChanges = array();
+ $metadataChanges = [];
$foldersCopy = $folderStructure;
- $unModefiedFolders = array();
+ $unModefiedFolders = [];
$rawPath = Storage::disk('public')->path('');
/*foreach ($stored as $savedVideo){ // O(n) where n = number of already known categories
@@ -371,8 +370,9 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$cost++;
$folderAccessTime = filemtime("$rawPath" . "media/$folder");
- if ($folderAccessTime <= $folderStructure[$folder]["last_scan"]) {
- $unModefiedFolders["storage/" . basename($path) . "/$folder"] = 1;
+ if ($folderAccessTime <= $folderStructure[$folder]['last_scan']) {
+ $unModefiedFolders['storage/' . basename($path) . "/$folder"] = 1;
+
continue;
}
@@ -387,11 +387,13 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$absolutePath = str_replace('\\', '/', Storage::disk('public')->path('')) . $file;
$ext = pathinfo($file, PATHINFO_EXTENSION);
- if (strtolower($ext) !== 'mp4' && strtolower($ext) !== 'mkv') continue;
+ if (strtolower($ext) !== 'mp4' && strtolower($ext) !== 'mkv') {
+ 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);
- if (!$uuid || !Uuid::isValid($uuid)) {
+ if (! $uuid || ! Uuid::isValid($uuid)) {
// dd('F');
$uuid = Str::uuid()->toString();
// if ($count < 1) {
@@ -402,14 +404,14 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$name = basename($file);
$cleanName = basename($file, ".$ext");
- $key = "storage/" . basename($path) . "/$folder/$name";
+ $key = 'storage/' . basename($path) . "/$folder/$name";
$rawFile = "$rawPath$file";
if (isset($stored[$key])) {
$current[$key] = $stored[$key]; // add to current
unset($stored[$key]); // remove from stored
} else {
- $generated = array("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 = array("video_id" => $currentID, "composite_id" => "$folder/$name", "uuid" => $uuid, "file_size" => filesize($rawFile), "duration" => isset($fileMetaData['duration']) ? $fileMetaData['duration'] : null, "date_scanned" => date("Y-m-d h:i:s A"));
+ $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['duration']) ? $fileMetaData['duration'] : 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)
@@ -421,18 +423,22 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
foreach ($stored as $video => $remainingID) { // unseen videos
if (isset($unModefiedFolders[dirname($video)])) { // if folder was not modefied
$current[$video] = $stored[$video]; // see video
+
continue;
}
- $generated = array("id" => $remainingID, "uuid" => null, "name" => null, "path" => null, "folder_id" => null, "date" => null, "action" => "DELETE"); // delete by id
+ $generated = ['id' => $remainingID, 'uuid' => null, 'name' => null, 'path' => null, 'folder_id' => null, 'date' => null, 'action' => 'DELETE']; // delete by id
array_push($changes, $generated); // add to new (delete)
$cost++;
}
- if ($foldersCopy === $folderStructure) $foldersCopy = null;
+ if ($foldersCopy === $folderStructure) {
+ $foldersCopy = null;
+ }
+
+ $data['next_ID'] = $currentID;
+ $data['videoStructure'] = $current;
- $data["next_ID"] = $currentID;
- $data["videoStructure"] = $current;
- return array("videoChanges" => $changes, "data" => $data, "cost" => $cost, "updatedFolderStructure" => $foldersCopy, "metadataChanges" => $metadataChanges);
+ return ['videoChanges' => $changes, 'data' => $data, 'cost' => $cost, 'updatedFolderStructure' => $foldersCopy, 'metadataChanges' => $metadataChanges];
}
private function getUidFromMetadata($filePath) {
@@ -456,7 +462,7 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$process->run();
// Check if the process was successful
- if (!$process->isSuccessful()) {
+ if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
@@ -468,8 +474,10 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
// 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);
}
@@ -494,22 +502,23 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
$process->run();
// Check if the process was successful
- if (!$process->isSuccessful()) {
+ if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$output = $process->getOutput(); // Decode JSON output
$metadata = json_decode($output, true);
+
return $metadata;
} catch (\Throwable $th) {
dump($th);
+
return [];
}
}
// Not Using
private function embedUidInMetadataDirect($filePath, $uid) {
-
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
// Define a temporary file path with the correct extension
$tempFilePath = $filePath . '.tmp';
@@ -531,14 +540,14 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
"uid=$uid",
'-f',
$format,
- $tempFilePath
+ $tempFilePath,
];
// Execute the FFmpeg command
$process = new Process($command);
$process->run();
// Check if the process was successful
- if (!$process->isSuccessful()) {
+ if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
// Replace the original file with the temporary file
@@ -556,7 +565,7 @@ class IndexFiles implements ShouldQueue, ShouldBeUnique {
}
// Define the custom function to handle the upsert logic
- function upsertMetadata($data) {
+ public function upsertMetadata($data) {
// Attempt to update by UUID first
try {
$metadata = Metadata::where('uuid', $data['uuid'])->first();
diff --git a/app/Jobs/SyncFiles.php b/app/Jobs/SyncFiles.php
index 47ecd466..817aeba8 100755
--- a/app/Jobs/SyncFiles.php
+++ b/app/Jobs/SyncFiles.php
@@ -2,19 +2,19 @@
namespace App\Jobs;
+use App\Models\Category;
+use App\Models\Folder;
+use App\Models\Video;
+use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
-use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Queue\ShouldBeUnique;
+use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
-use App\Models\Category;
-use App\Models\Folder;
-use App\Models\Video;
-use Illuminate\Bus\Batchable;
-class SyncFiles implements ShouldQueue, ShouldBeUnique {
+class SyncFiles implements ShouldBeUnique, ShouldQueue {
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
@@ -40,46 +40,50 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique {
// Idea: Compare categories folders and videos json files with data on sql server. Sync local copies with sql server if this is master storage (ie all files should be available)
// -> then if you index files, it should delete sql entries correctly if anything there does not exist locally
- $path = "media/";
+ $path = 'media/';
// $path = "private/media/";
- if (!Storage::disk('public')->exists($path)) {
+ if (! Storage::disk('public')->exists($path)) {
$error = 'Missing "media" directory in storage';
- dd(json_encode(array("success" => false, "result" => "", "error" => $error), JSON_UNESCAPED_SLASHES));
+ dd(json_encode(['success' => false, 'result' => '', 'error' => $error], JSON_UNESCAPED_SLASHES));
}
$directories = $this->generateCategories();
$subDirectories = $this->generateFolders($path);
- $files = $this->generateVideos($path, $subDirectories["data"]["folderStructure"], $directories["data"]["categoryStructure"]);
+ $files = $this->generateVideos($path, $subDirectories['data']['folderStructure'], $directories['data']['categoryStructure']);
- if (isset($files["updatedFolderStructure"])) $subDirectories["data"]["folderStructure"] = $files["updatedFolderStructure"];
+ if (isset($files['updatedFolderStructure'])) {
+ $subDirectories['data']['folderStructure'] = $files['updatedFolderStructure'];
+ }
- $categories = $directories["categoryChanges"];
- $folders = $subDirectories["folderChanges"];
- $videos = $files["videoChanges"];
+ $categories = $directories['categoryChanges'];
+ $folders = $subDirectories['folderChanges'];
+ $videos = $files['videoChanges'];
- Storage::put('categories.json', json_encode($directories["data"], JSON_UNESCAPED_SLASHES));
- Storage::put('folders.json', json_encode($subDirectories["data"], JSON_UNESCAPED_SLASHES));
- Storage::put('videos.json', json_encode($files["data"], JSON_UNESCAPED_SLASHES));
+ Storage::put('categories.json', json_encode($directories['data'], JSON_UNESCAPED_SLASHES));
+ Storage::put('folders.json', json_encode($subDirectories['data'], JSON_UNESCAPED_SLASHES));
+ Storage::put('videos.json', json_encode($files['data'], JSON_UNESCAPED_SLASHES));
- $data = array("categories" => $categories, "folders" => $folders, "videos" => $videos);
+ $data = ['categories' => $categories, 'folders' => $folders, 'videos' => $videos];
- $dataCache = Storage::json('dataCache.json') ?? array();
- $dataCache[date("Y-m-d-h:i:sa")] = array("job" => "sync", "data" => $data);
+ $dataCache = Storage::json('dataCache.json') ?? [];
+ $dataCache[date('Y-m-d-h:i:sa')] = ['job' => 'sync', 'data' => $data];
Storage::put('dataCache.json', json_encode($dataCache, JSON_UNESCAPED_SLASHES));
- if (!$this->batch()) dump('Categories | Folders | Videos | Data | dataCache', $directories, $subDirectories, $files, $data, $dataCache);
+ if (! $this->batch()) {
+ dump('Categories | Folders | Videos | Data | dataCache', $directories, $subDirectories, $files, $data, $dataCache);
+ }
}
private function generateCategories() {
- $data = Storage::json('categories.json') ?? array("next_ID" => 1, "categoryStructure" => array()); //array("anime"=>1,"tv"=>2,"yogscast"=>3); // read from json
+ $data = Storage::json('categories.json') ?? ['next_ID' => 1, 'categoryStructure' => []]; //array("anime"=>1,"tv"=>2,"yogscast"=>3); // read from json
$scanned = Category::all(); // read folder structure
- $currentID = $data["next_ID"];
- $stored = $data["categoryStructure"];
- $changes = array(); // send to db
- $current = array(); // save into json
+ $currentID = $data['next_ID'];
+ $stored = $data['categoryStructure'];
+ $changes = []; // send to db
+ $current = []; // save into json
foreach ($scanned as $category) {
// from database with each category
@@ -89,39 +93,41 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique {
$id = $category->id;
$current[$name] = $id;
- if (!isset($stored[$name])) {
+ if (! isset($stored[$name])) {
// category is not cached locally
// add
- array_push($changes, array("id" => $id, "name" => $name, "action" => "ADD"));
- } else if (isset($stored[$name])) {
+ array_push($changes, ['id' => $id, 'name' => $name, 'action' => 'ADD']);
+ } elseif (isset($stored[$name])) {
if ($stored[$name] != $id) {
// category is cached locally but id is not the same
// overwrite
- array_push($changes, array("id" => $id, "name" => $name, "action" => "OVERWRITE"));
+ array_push($changes, ['id' => $id, 'name' => $name, 'action' => 'OVERWRITE']);
}
// else category is cached locally and id is correct
// no action
unset($stored[$name]);
}
- if ($id >= $currentID) $currentID = $id + 1;
+ if ($id >= $currentID) {
+ $currentID = $id + 1;
+ }
}
- $data["next_ID"] = $currentID;
- $data["categoryStructure"] = $current;
+ $data['next_ID'] = $currentID;
+ $data['categoryStructure'] = $current;
- return array("categoryChanges" => $changes, "data" => $data);
+ return ['categoryChanges' => $changes, 'data' => $data];
}
private function generateFolders($path) {
- $data = Storage::json('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
+ $data = Storage::json('folders.json') ?? ['next_ID' => 1, 'folderStructure' => []]; //array("anime/frieren"=>array("id"=>0,"name"=>"frieren"),"starwars/andor"=>array("id"=1,"name"="andor")); // read from json
$cost = 0;
$scanned = Folder::all();
- $currentID = $data["next_ID"];
- $stored = $data["folderStructure"];
- $changes = array(); // send to db
- $current = array(); // save into json into json
+ $currentID = $data['next_ID'];
+ $stored = $data['folderStructure'];
+ $changes = []; // send to db
+ $current = []; // save into json into json
foreach ($scanned as $folder) {
// from database with each folder
// if that exists locally in stored, overwrite with db data (add to current) if different else add to current
@@ -129,18 +135,18 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique {
$path = $folder->path;
$name = $folder->name;
$id = $folder->id;
- $current[$path] = array("id" => $id, "last_scan" => -1);
+ $current[$path] = ['id' => $id, 'last_scan' => -1];
- if (!isset($stored[$path])) {
+ if (! isset($stored[$path])) {
// folder is not cached locally
// add
// no last scan
- array_push($changes, array("id" => $id, "name" => $name, "last_scan" => -1, "action" => "ADD"));
+ array_push($changes, ['id' => $id, 'name' => $name, 'last_scan' => -1, 'action' => 'ADD']);
} else {
- if ($stored[$path]['id'] != $id || !isset($stored[$path]['last_scan'])) {
+ if ($stored[$path]['id'] != $id || ! isset($stored[$path]['last_scan'])) {
// folder is cached locally but id is not the same
// overwrite
- array_push($changes, array("id" => $id, "name" => $name, "last_scan" => -1, "action" => "OVERWRITE"));
+ array_push($changes, ['id' => $id, 'name' => $name, 'last_scan' => -1, 'action' => 'OVERWRITE']);
}
// else folder is cached locally and is correct
// no action
@@ -154,20 +160,21 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique {
}
}
- $data["next_ID"] = $currentID;
- $data["folderStructure"] = $current;
- return array("folderChanges" => $changes, "data" => $data, "cost" => $cost);
+ $data['next_ID'] = $currentID;
+ $data['folderStructure'] = $current;
+
+ return ['folderChanges' => $changes, 'data' => $data, 'cost' => $cost];
}
private function generateVideos($path, $folderStructure) {
- $data = Storage::json('videos.json') ?? array("next_ID" => 1, "videoStructure" => array()); //array("anime/frieren/S1E01.mp4"=>array("id"=>0,"name"=>"S1E01"),"starwars/andor/S1E01.mkv"=>array("id"=1,"name"="S1E01.mkv")); // read from json
+ $data = Storage::json('videos.json') ?? ['next_ID' => 1, 'videoStructure' => []]; //array("anime/frieren/S1E01.mp4"=>array("id"=>0,"name"=>"S1E01"),"starwars/andor/S1E01.mkv"=>array("id"=1,"name"="S1E01.mkv")); // read from json
$scanned = Video::all();
$cost = 0;
- $currentID = $data["next_ID"];
- $stored = $data["videoStructure"];
- $changes = array(); // send to db
- $current = array(); // save into json into json
+ $currentID = $data['next_ID'];
+ $stored = $data['videoStructure'];
+ $changes = []; // send to db
+ $current = []; // save into json into json
$foldersCopy = $folderStructure;
@@ -176,19 +183,19 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique {
// if that exists locally in stored, overwrite with db data (add to current) if different else add to current
// if not exists, add db directly to current
$name = $video->name;
- $path = dirname($video->path) . "/" . basename($video->path);
+ $path = dirname($video->path) . '/' . basename($video->path);
$id = $video->id;
$current[$path] = $id;
- if (!isset($stored[$path])) {
+ if (! isset($stored[$path])) {
// video is not cached locally
// add
- array_push($changes, array("id" => $id, "name" => $name, "action" => "ADD"));
- } else if (isset($stored[$path])) {
+ array_push($changes, ['id' => $id, 'name' => $name, 'action' => 'ADD']);
+ } elseif (isset($stored[$path])) {
if ($stored[$path] != $id) {
// video is cached locally but id is not the same
// overwrite
- array_push($changes, array("id" => $id, "name" => $name, "action" => "OVERWRITE"));
+ array_push($changes, ['id' => $id, 'name' => $name, 'action' => 'OVERWRITE']);
}
// else video is cached locally and id is correct
// no action
@@ -196,11 +203,14 @@ class SyncFiles implements ShouldQueue, ShouldBeUnique {
}
$cost += 1;
- if ($id >= $currentID) $currentID = $id + 1;
+ if ($id >= $currentID) {
+ $currentID = $id + 1;
+ }
}
- $data["next_ID"] = $currentID;
- $data["videoStructure"] = $current;
- return array("videoChanges" => $changes, "data" => $data, "cost" => $cost, "updatedFolderStructure" => $foldersCopy);
+ $data['next_ID'] = $currentID;
+ $data['videoStructure'] = $current;
+
+ return ['videoChanges' => $changes, 'data' => $data, 'cost' => $cost, 'updatedFolderStructure' => $foldersCopy];
}
}
diff --git a/app/Jobs/VerifyFiles.php b/app/Jobs/VerifyFiles.php
index 4d26de92..e3f2ab98 100755
--- a/app/Jobs/VerifyFiles.php
+++ b/app/Jobs/VerifyFiles.php
@@ -4,18 +4,18 @@ namespace App\Jobs;
use App\Models\Metadata;
use App\Models\Record;
+use FFMpeg\FFProbe as FFMpegFFProbe;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
-use Illuminate\Support\Str;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
-use FFMpeg\FFProbe as FFMpegFFProbe;
use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Str;
+use Ramsey\Uuid\Uuid;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
-use Ramsey\Uuid\Uuid;
class VerifyFiles implements ShouldQueue {
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@@ -54,26 +54,26 @@ class VerifyFiles implements ShouldQueue {
if (count($this->videos) == 0) {
dump('Video Data Lost');
+
return;
}
- $transactions = array();
+ $transactions = [];
$error = false;
try {
foreach ($this->videos as $video) {
+ $stored = []; // Metadata from db
+ $changes = []; // Changes -> stored + changes . length has to be the same for every video so must generate defaults
- $stored = array(); // Metadata from db
- $changes = array(); // Changes -> stored + changes . length has to be the same for every video so must generate defaults
-
- $compositeId = $video->folder->path . "/" . basename($video->path);
- $filePath = str_replace('\\', '/', Storage::disk('public')->path('')) . 'media/' . $video->folder->path . "/" . basename($video->path);
+ $compositeId = $video->folder->path . '/' . basename($video->path);
+ $filePath = str_replace('\\', '/', Storage::disk('public')->path('')) . 'media/' . $video->folder->path . '/' . basename($video->path);
// $filePath = str_replace('\\', '/', Storage::path('app/private/')) . 'media/' . $video->folder->path . "/" . basename($video->path);
$fileMetaData = is_null($video->uuid) ? $this->getFileMetadata($filePath) : []; // Empty unless uuid is missing or duration is missing
$uuid = $video->uuid ?? ''; // video has ? file has
// 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 (! Uuid::isValid($uuid ?? '')) {
+ if (! isset($fileMetaData['tags']['uid'])) {
$uuid = Str::uuid()->toString();
EmbedUidInMetadata::dispatch($filePath, $uuid);
} else {
@@ -86,7 +86,7 @@ class VerifyFiles implements ShouldQueue {
$metadata = Metadata::where('uuid', $uuid)->orWhere('composite_id', $compositeId)->first();
- if (!$metadata) {
+ if (! $metadata) {
$metadata = Metadata::create(['uuid' => $uuid, 'composite_id' => $compositeId, 'video_id' => $video->id]);
// dump('new');
// $new = true;
@@ -110,10 +110,11 @@ class VerifyFiles implements ShouldQueue {
preg_match('![0-9]+!', $seasonRaw[0] ?? '', $season);
preg_match('![0-9]+!', $episodeRaw[0] ?? '', $episode);
-
if (is_null($metadata->duration)) {
// dump(str_replace('\\', '/', Storage::disk('public')->path('')) . substr($video->path, 8));
- if (!isset($fileMetaData['duration'])) $fileMetaData = $this->getFileMetadata($filePath);
+ if (! isset($fileMetaData['duration'])) {
+ $fileMetaData = $this->getFileMetadata($filePath);
+ }
// $ffprobe = FFMpegFFProbe::create();
// $duration = floor($ffprobe
@@ -124,15 +125,22 @@ class VerifyFiles implements ShouldQueue {
$changes['duration'] = $duration;
}
- if (is_null($metadata->episode)) $changes['episode'] = count($episode) == 1 ? (int)$episode[0] : null;
- if (is_null($metadata->season)) $changes['season'] = count($season) == 1 ? (int)$season[0] : null;
+ if (is_null($metadata->episode)) {
+ $changes['episode'] = count($episode) == 1 ? (int) $episode[0] : null;
+ }
+ if (is_null($metadata->season)) {
+ $changes['season'] = count($season) == 1 ? (int) $season[0] : null;
+ }
if (is_null($metadata->title)) {
$newTitle = count($season) == 1 ? 'S' . $season[0] : '';
$newTitle .= count($episode) == 1 ? 'E' . $episode[0] : '';
- if ($newTitle != '') $changes['title'] = $newTitle;
- else $changes['title'] = $video->name;
+ if ($newTitle != '') {
+ $changes['title'] = $newTitle;
+ } else {
+ $changes['title'] = $video->name;
+ }
}
if (is_null($metadata->description)) {
@@ -150,7 +158,7 @@ class VerifyFiles implements ShouldQueue {
is_null($metadata->view_count) ? $changes['view_count'] = Record::where('video_id', $video->id)->count() + ($metadata->id ? Record::where('metadata_id', $metadata->id)->count() : 0) : $stored['view_count'] = $metadata->view_count;
if (count($changes) > 0) {
- $changes['date_scanned'] = date("Y-m-d h:i:s A");
+ $changes['date_scanned'] = date('Y-m-d h:i:s A');
array_push($transactions, [...$stored, ...$changes]);
// dump(count([...$stored, ...$changes]));
// if ($new) dump([...$stored, ...$changes]);
@@ -172,12 +180,13 @@ class VerifyFiles implements ShouldQueue {
}
try {
- if (count($transactions) == 0 || $error == true) return;
+ if (count($transactions) == 0 || $error == true) {
+ return;
+ }
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']));
} catch (\Throwable $th) {
-
$ids = array_map(function ($transaction) {
return $transaction['id'];
}, $transactions);
@@ -209,16 +218,18 @@ class VerifyFiles implements ShouldQueue {
$process->run();
// Check if the process was successful
- if (!$process->isSuccessful()) {
+ if (! $process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$output = $process->getOutput(); // Decode JSON output
$metadata = json_decode($output, true);
- return $metadata["format"];
+
+ return $metadata['format'];
} catch (\Throwable $th) {
dump($th);
- return array("tags" => array());
+
+ return ['tags' => []];
}
}
}
diff --git a/app/Jobs/VerifyFolders.php b/app/Jobs/VerifyFolders.php
index 5a483e8e..437db82d 100644
--- a/app/Jobs/VerifyFolders.php
+++ b/app/Jobs/VerifyFolders.php
@@ -11,23 +11,20 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
-class VerifyFolders implements ShouldQueue
-{
+class VerifyFolders implements ShouldQueue {
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
- public function __construct(public $folders)
- {
+ public function __construct(public $folders) {
//
}
/**
* Execute the job.
*/
- public function handle(): void
- {
+ public function handle(): void {
if ($this->batch()->cancelled()) {
// Determine if the batch has been cancelled...
return;
@@ -35,21 +32,24 @@ class VerifyFolders implements ShouldQueue
if (count($this->folders) == 0) {
dump('Folder Data Lost');
+
return;
}
- $transactions = array();
+ $transactions = [];
$error = false;
foreach ($this->folders as $folder) {
try {
- $stored = array();
- $changes = array();
+ $stored = [];
+ $changes = [];
$series = Series::firstOrCreate(['composite_id' => $folder->path], ['folder_id' => $folder->id]);
$stored = $series->toArray();
- if (is_null($series->episodes)) $changes['episodes'] = Video::where('folder_id', $folder->id)->count();
+ if (is_null($series->episodes)) {
+ $changes['episodes'] = Video::where('folder_id', $folder->id)->count();
+ }
if (is_null($series->title)) {
$changes['title'] = $folder->name;
@@ -62,7 +62,6 @@ class VerifyFolders implements ShouldQueue
// dump($folder->name);
}
// dump($series->toArray());
-
} catch (\Throwable $th) {
//throw $th;
dump('Error cannot verify folder series data ' . $th->getMessage() . ' Cancelling ' . count($transactions) . ' updates');
@@ -72,7 +71,9 @@ class VerifyFolders implements ShouldQueue
}
try {
- if (count($transactions) == 0 || $error == true) return;
+ if (count($transactions) == 0 || $error == true) {
+ return;
+ }
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']));
diff --git a/app/Models/Playback.php b/app/Models/Playback.php
index 455e2ab2..1d300c38 100644
--- a/app/Models/Playback.php
+++ b/app/Models/Playback.php
@@ -6,8 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
-class Playback extends Model
-{
+class Playback extends Model {
use HasFactory;
protected $fillable = [
@@ -16,8 +15,7 @@ class Playback extends Model
'count',
];
- public function metadata(): BelongsTo
- {
+ public function metadata(): BelongsTo {
return $this->belongsTo(Metadata::class);
}
}
diff --git a/app/Models/Record.php b/app/Models/Record.php
index c0e2b776..49c86623 100755
--- a/app/Models/Record.php
+++ b/app/Models/Record.php
@@ -5,29 +5,25 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
-class Record extends Model
-{
+class Record extends Model {
use HasFactory;
protected $fillable = [
'user_id',
'video_id',
'name',
- 'metadata_id'
+ 'metadata_id',
];
- public function user()
- {
+ public function user() {
return $this->belongsTo(User::class);
}
- public function video()
- {
+ public function video() {
return $this->belongsTo(Video::class);
}
- public function metadata()
- {
+ public function metadata() {
return $this->belongsTo(Metadata::class);
}
}
diff --git a/app/Models/Series.php b/app/Models/Series.php
index 52a35530..bdf7858b 100644
--- a/app/Models/Series.php
+++ b/app/Models/Series.php
@@ -6,8 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
-class Series extends Model
-{
+class Series extends Model {
use HasFactory;
protected $fillable = [
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index dd9355ef..bd2d5d2c 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -5,22 +5,19 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
-class Tag extends Model
-{
+class Tag extends Model {
use HasFactory;
protected $fillable = [
'name',
- 'creator_id'
+ 'creator_id',
];
- public function creator()
- {
+ public function creator() {
return $this->belongsTo(User::class);
}
- public function metadata()
- {
+ public function metadata() {
return $this->belongsTo(Metadata::class);
}
}
diff --git a/app/Models/User.php b/app/Models/User.php
index a45428f6..099f8e9e 100755
--- a/app/Models/User.php
+++ b/app/Models/User.php
@@ -46,7 +46,10 @@ class User extends Authenticatable {
}
public function isAdmin(): bool {
- if ($this->name == 'aminushki') return true;
+ if ($this->name == 'aminushki') {
+ return true;
+ }
+
return false;
}
}
diff --git a/app/Models/Video.php b/app/Models/Video.php
index 9b45a04d..29aa2318 100755
--- a/app/Models/Video.php
+++ b/app/Models/Video.php
@@ -7,8 +7,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
-class Video extends Model
-{
+class Video extends Model {
use HasFactory;
public $timestamps = false;
@@ -23,13 +22,11 @@ class Video extends Model
'uuid',
];
- public function folder(): BelongsTo
- {
+ public function folder(): BelongsTo {
return $this->belongsTo(Folder::class);
}
- public function metadata(): HasOne
- {
+ public function metadata(): HasOne {
return $this->hasOne(Metadata::class);
}
}
diff --git a/app/Models/VideoTag.php b/app/Models/VideoTag.php
index 1c2b836f..0e21e5af 100644
--- a/app/Models/VideoTag.php
+++ b/app/Models/VideoTag.php
@@ -5,8 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
-class VideoTag extends Model
-{
+class VideoTag extends Model {
use HasFactory;
protected $fillable = [
@@ -14,13 +13,11 @@ class VideoTag extends Model
'tag_id',
];
- public function metadata()
- {
+ public function metadata() {
return $this->belongsTo(Metadata::class);
}
- public function tag()
- {
+ public function tag() {
return $this->belongsTo(Tag::class);
}
}
diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php
index cf6ec30b..60e3f319 100755
--- a/app/Providers/AppServiceProvider.php
+++ b/app/Providers/AppServiceProvider.php
@@ -2,10 +2,9 @@
namespace App\Providers;
-use Illuminate\Support\ServiceProvider;
use App\Models\User;
-use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
+use Illuminate\Support\ServiceProvider;
use Laravel\Pulse\Facades\Pulse;
class AppServiceProvider extends ServiceProvider {
@@ -21,7 +20,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/Traits/HttpResponses.php b/app/Traits/HttpResponses.php
index 00feb27c..47de66c3 100755
--- a/app/Traits/HttpResponses.php
+++ b/app/Traits/HttpResponses.php
@@ -2,25 +2,22 @@
namespace App\Traits;
-trait HttpResponses
-{
- protected function success($data, $message = null, $code = 200)
- {
+trait HttpResponses {
+ protected function success($data, $message = null, $code = 200) {
return response()->json([
'success' => true,
'status' => 'success',
'message' => $message,
- 'data' => $data
+ 'data' => $data,
], $code);
}
- protected function error($data, $message = null, $code)
- {
+ protected function error($data, $message, $code) {
return response()->json([
'success' => false,
'status' => 'failure',
'message' => $message,
- 'data' => $data
+ 'data' => $data,
], $code);
}
}
diff --git a/app/View/Components/AppLayout.php b/app/View/Components/AppLayout.php
index de0d46f5..70bc9f71 100755
--- a/app/View/Components/AppLayout.php
+++ b/app/View/Components/AppLayout.php
@@ -5,13 +5,11 @@ namespace App\View\Components;
use Illuminate\View\Component;
use Illuminate\View\View;
-class AppLayout extends Component
-{
+class AppLayout extends Component {
/**
* Get the view / contents that represents the component.
*/
- public function render(): View
- {
+ public function render(): View {
return view('layouts.app');
}
}
diff --git a/config/app.php b/config/app.php
index 7785c8a5..67407cbb 100755
--- a/config/app.php
+++ b/config/app.php
@@ -166,6 +166,6 @@ return [
'aliases' => Facade::defaultAliases()->merge([
// 'Example' => App\Facades\Example::class,
- 'FFMpeg' => ProtoneMedia\LaravelFFMpeg\Support\FFMpeg::class
+ 'FFMpeg' => ProtoneMedia\LaravelFFMpeg\Support\FFMpeg::class,
])->toArray(),
];
diff --git a/config/cache.php b/config/cache.php
index 925f7d2e..2dbc452c 100755
--- a/config/cache.php
+++ b/config/cache.php
@@ -103,6 +103,6 @@ return [
|
*/
- 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
+ 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_cache_'),
];
diff --git a/config/filesystems.php b/config/filesystems.php
index b564035a..cf2c5c89 100755
--- a/config/filesystems.php
+++ b/config/filesystems.php
@@ -40,7 +40,7 @@ return [
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
- 'url' => env('APP_URL').'/storage',
+ 'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
'throw' => false,
],
diff --git a/config/logging.php b/config/logging.php
index 8d94292b..54bb171e 100755
--- a/config/logging.php
+++ b/config/logging.php
@@ -89,7 +89,7 @@ return [
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
- 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
+ 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'),
],
'processors' => [PsrLogMessageProcessor::class],
],
diff --git a/config/session.php b/config/session.php
index f0b6541e..4683a9b1 100755
--- a/config/session.php
+++ b/config/session.php
@@ -129,7 +129,7 @@ return [
'cookie' => env(
'SESSION_COOKIE',
- Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
+ Str::slug(env('APP_NAME', 'laravel'), '_') . '_session'
),
/*
diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php
index 584104c9..ec652d1a 100755
--- a/database/factories/UserFactory.php
+++ b/database/factories/UserFactory.php
@@ -9,8 +9,7 @@ use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
-class UserFactory extends Factory
-{
+class UserFactory extends Factory {
/**
* The current password being used by the factory.
*/
@@ -21,8 +20,7 @@ class UserFactory extends Factory
*
* @return array<string, mixed>
*/
- public function definition(): array
- {
+ public function definition(): array {
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
@@ -35,8 +33,7 @@ class UserFactory extends Factory
/**
* Indicate that the model's email address should be unverified.
*/
- public function unverified(): static
- {
+ public function unverified(): static {
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
diff --git a/database/migrations/2024_02_10_211928_create_categories_table.php b/database/migrations/2024_02_10_211928_create_categories_table.php
index 355564bd..320d263e 100755
--- a/database/migrations/2024_02_10_211928_create_categories_table.php
+++ b/database/migrations/2024_02_10_211928_create_categories_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('categories', function (Blueprint $table) {
$table->id();
$table->string('name')->unique();
@@ -21,8 +19,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('categories');
}
};
diff --git a/database/migrations/2024_02_10_212124_create_folders_table.php b/database/migrations/2024_02_10_212124_create_folders_table.php
index 7627bd5f..be3f065f 100755
--- a/database/migrations/2024_02_10_212124_create_folders_table.php
+++ b/database/migrations/2024_02_10_212124_create_folders_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('folders', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('category_id');
@@ -26,8 +24,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('folders');
}
};
diff --git a/database/migrations/2024_02_10_212508_create_videos_table.php b/database/migrations/2024_02_10_212508_create_videos_table.php
index ad09b975..1f64df3f 100755
--- a/database/migrations/2024_02_10_212508_create_videos_table.php
+++ b/database/migrations/2024_02_10_212508_create_videos_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('videos', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('folder_id');
@@ -27,8 +25,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('videos');
}
};
diff --git a/database/migrations/2024_02_27_183528_create_records_table.php b/database/migrations/2024_02_27_183528_create_records_table.php
index c638cdd0..7693e9b9 100755
--- a/database/migrations/2024_02_27_183528_create_records_table.php
+++ b/database/migrations/2024_02_27_183528_create_records_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('records', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('user_id');
@@ -31,8 +29,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('records');
}
};
diff --git a/database/migrations/2024_07_28_222604_add_meta_data_to_videos_table.php b/database/migrations/2024_07_28_222604_add_meta_data_to_videos_table.php
index e5f4bfc0..8a56ad1d 100755
--- a/database/migrations/2024_07_28_222604_add_meta_data_to_videos_table.php
+++ b/database/migrations/2024_07_28_222604_add_meta_data_to_videos_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('videos', function (Blueprint $table) {
//
$table->string('title')->nullable()->after('date');
@@ -24,8 +22,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('videos', function (Blueprint $table) {
//
$table->dropColumn('title');
diff --git a/database/migrations/2024_07_29_212739_add_description_to_videos_table.php b/database/migrations/2024_07_29_212739_add_description_to_videos_table.php
index 03baec92..91049ac8 100755
--- a/database/migrations/2024_07_29_212739_add_description_to_videos_table.php
+++ b/database/migrations/2024_07_29_212739_add_description_to_videos_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('videos', function (Blueprint $table) {
$table->string('description')->nullable()->after('title');
});
@@ -19,8 +17,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn('description');
});
diff --git a/database/migrations/2024_08_14_013845_create_video_meta_data_table.php b/database/migrations/2024_08_14_013845_create_video_meta_data_table.php
index cac1e581..6bb75afc 100644
--- a/database/migrations/2024_08_14_013845_create_video_meta_data_table.php
+++ b/database/migrations/2024_08_14_013845_create_video_meta_data_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('metadata', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('video_id')->nullable()->unique();
@@ -39,8 +37,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('metadata');
}
};
diff --git a/database/migrations/2024_08_14_013922_add_meta_data_link_to_records_table.php b/database/migrations/2024_08_14_013922_add_meta_data_link_to_records_table.php
index ed6abc99..71202d75 100644
--- a/database/migrations/2024_08_14_013922_add_meta_data_link_to_records_table.php
+++ b/database/migrations/2024_08_14_013922_add_meta_data_link_to_records_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('records', function (Blueprint $table) {
$table->unsignedBigInteger('metadata_id')->nullable()->after('user_id');
$table->foreign('metadata_id')
@@ -23,8 +21,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('records', function (Blueprint $table) {
$table->dropColumn('metadata_id');
});
diff --git a/database/migrations/2024_08_14_044416_create_series_table.php b/database/migrations/2024_08_14_044416_create_series_table.php
index b38471a8..ea85dc41 100644
--- a/database/migrations/2024_08_14_044416_create_series_table.php
+++ b/database/migrations/2024_08_14_044416_create_series_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('series', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('folder_id')->nullable()->unique();
@@ -41,8 +39,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('series');
}
};
diff --git a/database/migrations/2024_08_15_043043_create_playback_table.php b/database/migrations/2024_08_15_043043_create_playback_table.php
index 8d9c9018..df96533e 100644
--- a/database/migrations/2024_08_15_043043_create_playback_table.php
+++ b/database/migrations/2024_08_15_043043_create_playback_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('playbacks', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('metadata_id')->nullable();
@@ -26,8 +24,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('playbacks');
}
};
diff --git a/database/migrations/2024_11_09_221140_create_tags_table.php b/database/migrations/2024_11_09_221140_create_tags_table.php
index f0024f10..679bf6e3 100644
--- a/database/migrations/2024_11_09_221140_create_tags_table.php
+++ b/database/migrations/2024_11_09_221140_create_tags_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('tags', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('creator_id')->nullable();
@@ -26,8 +24,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('tags');
}
};
diff --git a/database/migrations/2024_11_09_221201_create_video_tags_table.php b/database/migrations/2024_11_09_221201_create_video_tags_table.php
index 049c68c5..fad970da 100644
--- a/database/migrations/2024_11_09_221201_create_video_tags_table.php
+++ b/database/migrations/2024_11_09_221201_create_video_tags_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::create('video_tags', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tag_id');
@@ -30,8 +28,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::dropIfExists('video_tags');
}
};
diff --git a/database/migrations/2024_11_10_185246_add_count_to_playbacks.php b/database/migrations/2024_11_10_185246_add_count_to_playbacks.php
index ab5d31e3..03ebc437 100644
--- a/database/migrations/2024_11_10_185246_add_count_to_playbacks.php
+++ b/database/migrations/2024_11_10_185246_add_count_to_playbacks.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('playbacks', function (Blueprint $table) {
$table->unsignedBigInteger('count')->default(1);
});
@@ -19,8 +17,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('playbacks', function (Blueprint $table) {
//
$table->dropColumn('count');
diff --git a/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php b/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php
index 562aa33d..9909cc86 100644
--- a/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php
+++ b/database/migrations/2024_11_17_175621_add_uuid_to_videos_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('videos', function (Blueprint $table) {
$table->uuid('uuid')->after('folder_id')->unique()->nullable();
});
@@ -19,8 +17,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('videos', function (Blueprint $table) {
$table->dropColumn('uuid');
});
diff --git a/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php b/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php
index c3897fae..d620d159 100644
--- a/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php
+++ b/database/migrations/2024_11_17_175631_add_uuid_to_metadata_table.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('metadata', function (Blueprint $table) {
$table->uuid('uuid')->after('composite_id')->unique()->nullable();
});
@@ -19,8 +17,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('metadata', function (Blueprint $table) {
$table->dropColumn('uuid');
});
diff --git a/database/migrations/2024_12_01_035119_add_filesize_to_metadata.php b/database/migrations/2024_12_01_035119_add_filesize_to_metadata.php
index 29784840..21aa34ee 100644
--- a/database/migrations/2024_12_01_035119_add_filesize_to_metadata.php
+++ b/database/migrations/2024_12_01_035119_add_filesize_to_metadata.php
@@ -4,13 +4,11 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-return new class extends Migration
-{
+return new class extends Migration {
/**
* Run the migrations.
*/
- public function up(): void
- {
+ public function up(): void {
Schema::table('metadata', function (Blueprint $table) {
$table->unsignedBigInteger('file_size')->nullable();
$table->date('date_scanned')->nullable();
@@ -20,8 +18,7 @@ return new class extends Migration
/**
* Reverse the migrations.
*/
- public function down(): void
- {
+ public function down(): void {
Schema::table('metadata', function (Blueprint $table) {
$table->dropColumn('file_size');
$table->dropColumn('date_end');
diff --git a/pint.json b/pint.json
new file mode 100644
index 00000000..8ad291ba
--- /dev/null
+++ b/pint.json
@@ -0,0 +1,24 @@
+{
+ "preset": "laravel",
+ "rules": {
+ "braces": {
+ "allow_single_line_anonymous_class_with_empty_body": true,
+ "allow_single_line_closure": true,
+ "position_after_control_structures": "same",
+ "position_after_functions_and_oop_constructs": "same",
+ "position_after_anonymous_constructs": "same"
+ },
+ "curly_braces_position": {
+ "control_structures_opening_brace": "same_line",
+ "functions_opening_brace": "same_line",
+ "anonymous_functions_opening_brace": "same_line",
+ "classes_opening_brace": "same_line",
+ "anonymous_classes_opening_brace": "same_line",
+ "allow_single_line_empty_anonymous_classes": true,
+ "allow_single_line_anonymous_functions": true
+ },
+ "concat_space": {
+ "spacing": "one"
+ }
+ }
+}
diff --git a/public/index.php b/public/index.php
index 947d9896..74a0960e 100755
--- a/public/index.php
+++ b/public/index.php
@@ -5,13 +5,13 @@ use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...
-if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
+if (file_exists($maintenance = __DIR__ . '/../storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
-require __DIR__.'/../vendor/autoload.php';
+require __DIR__ . '/../vendor/autoload.php';
// Bootstrap Laravel and handle the request...
-(require_once __DIR__.'/../bootstrap/app.php')
+(require_once __DIR__ . '/../bootstrap/app.php')
->handleRequest(Request::capture());
diff --git a/resources/js/components/pinesUI/DropdownMenu.vue b/resources/js/components/pinesUI/DropdownMenu.vue
index 41f75732..68e402fb 100755
--- a/resources/js/components/pinesUI/DropdownMenu.vue
+++ b/resources/js/components/pinesUI/DropdownMenu.vue
@@ -39,7 +39,7 @@ const dropDownItemsAuth = [
[
{ ...defaults, name: 'friends', url: '/friends', text: 'Friends', icon: LucideUsers, disabled: true },
{ ...defaults, name: 'history', url: '/history', text: 'Full History', icon: LucideHistory },
- { ...defaults, name: 'dashboard', url: '/Dashboard', text: 'Dashboard', icon: LucideLayoutDashboard },
+ { ...defaults, name: 'dashboard', url: '/dashboard', text: 'Dashboard', icon: LucideLayoutDashboard },
],
[
{ ...defaults, name: 'index', url: '/jobs/indexFiles', text: 'Index Files', external: true, icon: LucideFolderSearch },
diff --git a/resources/js/components/pulseCards/PulseServers.vue b/resources/js/components/pulseCards/PulseServers.vue
index d16a095c..67041cd8 100644
--- a/resources/js/components/pulseCards/PulseServers.vue
+++ b/resources/js/components/pulseCards/PulseServers.vue
@@ -10,7 +10,7 @@ import IconServer from '../icons/IconServer.vue';
import PulseLineChart from '../charts/PulseLineChart.vue';
import PulseDoughnutChart from '../charts/PulseDoughnutChart.vue';
-const { data, isLoading } = useGetPulse('servers');
+const { data, isLoading } = useGetPulse({ type: 'servers', period: '24_hours' });
const pulseData = ref<PulseResponse>();
const servers = ref<{ [key: string]: PulseServerResponse }>();
@@ -43,11 +43,9 @@ watch(
() => {
if (data.value.data) {
pulseData.value = data.value.data;
- console.log(data.value.data);
}
if (data.value.data.servers) {
servers.value = data.value.data.servers.servers;
- console.log(data.value.data.servers.servers);
}
},
);
diff --git a/resources/js/service/queries.ts b/resources/js/service/queries.ts
index 88ec83c1..15fad0c1 100644
--- a/resources/js/service/queries.ts
+++ b/resources/js/service/queries.ts
@@ -26,11 +26,11 @@ export const useVideoPlayback = (idRef: Ref<number, number>) => {
});
};
-export const useGetPulse = (type?: string) => {
+export const useGetPulse = (req?: { type?: string; period?: '' | '1_hour' | '6_hours' | '24_hours' | '7_days' }) => {
return useQuery<{ data: PulseResponse }>({
queryKey: ['pulse'],
queryFn: async () => {
- const { data: response } = await getPulse(type);
+ const { data: response } = await getPulse(req);
return response;
},
});
diff --git a/resources/js/service/siteAPI.ts b/resources/js/service/siteAPI.ts
index 8705b223..89a28651 100644
--- a/resources/js/service/siteAPI.ts
+++ b/resources/js/service/siteAPI.ts
@@ -11,6 +11,6 @@ export function getStats() {
return API.get(`/site/`);
}
-export function getPulse(type?: string) {
- return API.get(`/pulse/${type ?? ''}`);
+export function getPulse(req?: { type?: string; period?: '' | '1_hour' | '6_hours' | '24_hours' | '7_days' }) {
+ return API.get(`/pulse${req?.type ? `/${req?.type}` : ''}${req?.period ? `?period=${req?.period}` : ''}`);
}
diff --git a/resources/js/views/DashboardView.vue b/resources/js/views/DashboardView.vue
index ead603e2..dbeb4ce9 100644
--- a/resources/js/views/DashboardView.vue
+++ b/resources/js/views/DashboardView.vue
@@ -59,16 +59,12 @@ async function cycleSideBar(state: string) {
onMounted(async () => {
pageTitle.value = 'Dashboard';
- selectedSideBar.value = '';
- // (async () => {
- // await getRecords();
- // loading.value = false;
- // })();
+ selectedSideBar.value = 'dashboard';
+
const { data } = await getStats();
stats.value = data;
const { data: rawCategories } = await getCategories();
- console.log(rawCategories.data);
categories.value = rawCategories?.data;
});
diff --git a/routes/api.php b/routes/api.php
index 9eaa6da7..ba953e79 100755
--- a/routes/api.php
+++ b/routes/api.php
@@ -5,17 +5,16 @@ use App\Http\Controllers\Api\V1\CategoryController;
use App\Http\Controllers\Api\V1\FolderController;
use App\Http\Controllers\Api\V1\MetadataController;
use App\Http\Controllers\Api\V1\PlaybackController;
-use App\Http\Controllers\Api\V1\SeriesController;
-use App\Http\Controllers\Api\V1\VideoController;
use App\Http\Controllers\Api\V1\ProfileController;
+use App\Http\Controllers\Api\V1\PulseDashboardController;
use App\Http\Controllers\Api\V1\RecordController;
+use App\Http\Controllers\Api\V1\SeriesController;
use App\Http\Controllers\Api\V1\SiteController;
use App\Http\Controllers\Api\V1\TagController;
+use App\Http\Controllers\Api\V1\VideoController;
use App\Http\Controllers\DirectoryController;
-
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
-use Robertogallea\PulseApi\Http\Controllers\DashboardController;
Route::get('/user', function (Request $request) {
return $request->user();
@@ -33,11 +32,13 @@ Route::group(['middleware' => ['auth:sanctum']], function () {
Route::resource('/tags', TagController::class)->only(['index', 'store']);
Route::resource('/site', SiteController::class)->only(['index']);
Route::resource('/categories', CategoryController::class)->only(['index']);
+ // Route::get('/pulse', [PulseDashboardController::class, 'index'])->name('dashboard');
+ // Route::get('/pulse/{type}', [PulseDashboardController::class, 'show'])->name('resource');
});
Route::prefix('pulse')->group(function () {
- Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
- Route::get('/{type}', [DashboardController::class, 'show'])->name('resource');
+ Route::get('/', [PulseDashboardController::class, 'index'])->name('dashboard');
+ Route::get('/{type}', [PulseDashboardController::class, 'show'])->name('resource');
})->middleware('auth');
// Route::prefix(config('pulse-api.route_prefix') . '/' . config('pulse-api.path'))
diff --git a/routes/console.php b/routes/console.php
index e1936feb..62c8d504 100755
--- a/routes/console.php
+++ b/routes/console.php
@@ -1,7 +1,6 @@
<?php
use App\Jobs\IndexFiles;
-
// use Illuminate\Foundation\Inspiring;
// use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;
diff --git a/routes/web.php b/routes/web.php
index 8efb134b..06ef4add 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -1,9 +1,8 @@
<?php
-use Illuminate\Support\Facades\Route;
-use App\Http\Controllers\Api\V1\AuthController;
use App\Http\Controllers\DirectoryController;
use App\Http\Controllers\MediaController;
+use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;
// private
diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php
index 8364a84e..3ca96505 100755
--- a/tests/Feature/ExampleTest.php
+++ b/tests/Feature/ExampleTest.php
@@ -5,13 +5,11 @@ namespace Tests\Feature;
// use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
-class ExampleTest extends TestCase
-{
+class ExampleTest extends TestCase {
/**
* A basic test example.
*/
- public function test_the_application_returns_a_successful_response(): void
- {
+ public function test_the_application_returns_a_successful_response(): void {
$response = $this->get('/');
$response->assertStatus(200);
diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php
index 5773b0ce..7d80b3c7 100755
--- a/tests/Unit/ExampleTest.php
+++ b/tests/Unit/ExampleTest.php
@@ -4,13 +4,11 @@ namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
-class ExampleTest extends TestCase
-{
+class ExampleTest extends TestCase {
/**
* A basic test example.
*/
- public function test_that_true_is_true(): void
- {
+ public function test_that_true_is_true(): void {
$this->assertTrue(true);
}
}