Skip to content

A self-hosted media server and file management system

chore: clean up url code, auto fill the default folder and add todo items

aminnausinbbc061140586
diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php
index a3f3e8e8..71931fe4 100755
--- a/app/Http/Controllers/DirectoryController.php
+++ b/app/Http/Controllers/DirectoryController.php
@@ -58,10 +58,9 @@ class DirectoryController extends Controller {
$folderList = Folder::with('series')->where('category_id', $dirRaw->id)->orderBy('name')->get(); // Folders in category
$data['dir'] = ['id' => $dirRaw->id, 'name' => $dir, 'folders' => FolderResource::collection($folderList)]; // Full category data
+ //TODO: Use extracted folder parsing
$folderRaw = isset($request->folderName)
? (
- // $folderList->firstWhere('name', $folderName)
- // $folderList->firstWhere('name', 'ilike', '%' . $folderName . '%')
$data['dir']['folders']->first(function ($folder) use ($folderName) {
return Str::lower($folder->name) === Str::lower($folderName);
})
@@ -91,6 +90,15 @@ class DirectoryController extends Controller {
}
}
+ private function parseCategory() {
+ //TODO: Extract category parsing and add support for id to name conversion
+ }
+
+ private function parseFolder() {
+ //TODO: Extract folder parsing and add support for id to name conversion
+ }
+
+ //TODO: Generate the verify jobs after the indexing job has completed with a callback in setup batch
public function scanFiles(Request $request, ?Category $category = null) {
$name = 'Scan Files';
$description = 'Scans for file changes and loads metadata from all Libraries.';
@@ -372,6 +380,7 @@ class DirectoryController extends Controller {
]);
}
+ //TODO: Add a callback feature to allow new jobs after the primary jobs have completed (verify after index)
public function setupBatch($chain, Task $task) {
return Bus::batch($chain)->progress(function (Batch $batch) {
// $task->refresh();
diff --git a/resources/js/router/index.ts b/resources/js/router/index.ts
index 3a9dcca7..460f193b 100644
--- a/resources/js/router/index.ts
+++ b/resources/js/router/index.ts
@@ -1,4 +1,4 @@
-import { createRouter, createWebHistory } from 'vue-router';
+import { createRouter, createWebHistory, type NavigationGuardNext, type RouteLocationNormalizedGeneric } from 'vue-router';
import { getCategories } from '@/service/mediaAPI';
import { useAuthStore } from '@/stores/AuthStore';
import { toTitleCase } from '@/service/util';
@@ -146,25 +146,7 @@ const router = createRouter({
],
});
-router.beforeEach(async (to, from, next) => {
- const meta = to.meta as { title?: string };
- if (to.name !== 'logout') document.title = meta?.title ?? toTitleCase(`${to.name?.toString()}`); // Update Page Title
-
- if (to.name === 'login' && !to.query.redirect && from.fullPath !== '/') {
- to.query = {
- redirect: from.name !== 'login' ? from.fullPath : null,
- };
-
- next();
- return;
- }
-
- if (!to.meta?.protected) {
- // Not protected route
- next();
- return;
- }
-
+const redirectAfterLogin = async (to: RouteLocationNormalizedGeneric, next: NavigationGuardNext) => {
const authStore = useAuthStore();
const { auth } = authStore;
@@ -181,6 +163,29 @@ router.beforeEach(async (to, from, next) => {
redirect: to.fullPath,
},
});
+};
+
+router.beforeEach(async (to, from, next) => {
+ const meta = to.meta as { title?: string };
+
+ if (to.name !== 'logout') document.title = meta?.title ?? toTitleCase(`${to.name?.toString()}`); // Update Page Title
+
+ if (to.name === 'login' && !to.query.redirect && from.fullPath !== '/') {
+ // what does this do???
+ to.query = {
+ redirect: from.name !== 'login' ? from.fullPath : null,
+ };
+
+ next();
+ return;
+ }
+
+ if (to.meta?.protected) {
+ // Not protected route
+ return redirectAfterLogin(to, next);
+ }
+
+ next();
});
router.afterEach((to) => {
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php
index 4702dcfa..5450cde9 100755
--- a/resources/views/layouts/app.blade.php
+++ b/resources/views/layouts/app.blade.php
@@ -7,6 +7,8 @@
<meta name="description" content="A self hosted web media server to keep everything in one place.">
<title>{{ config('app.name', 'Media Server') }}</title>
+
+ <meta property="og:title" content="{{ config('app.name', 'Media Server') }}" />
<script defer data-domain="{{ config('app.host') }}" src="{{ config('services.plausible.url') }}"></script>
<script>
window.plausible = window.plausible || function() {
diff --git a/routes/web.php b/routes/web.php
index 064ee7e1..42cfa4c0 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -4,6 +4,7 @@ use App\Events\TaskEnded;
use App\Http\Controllers\DirectoryController;
use App\Http\Controllers\MediaController;
use App\Models\Category;
+use App\Models\Folder;
use App\Models\Task;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
@@ -59,39 +60,40 @@ Route::get('/signed-url/{path}', function ($path) {
// broadcast(new TaskEnded($task));
// });
-Route::middleware(['web'])->group(function () {
+Route::middleware('web')->group(function () {
Route::get('/pulse', function () {
if (Gate::allows('viewPulse', Auth::user())) {
return view('vendor.pulse.dashboard');
}
abort(403);
});
-});
-Route::get('/welcome', function () {
- return view('welcome');
-});
+ Route::get('/welcome', function () {
+ return view('welcome');
+ });
-Route::get('/', function () {
- if (Auth::user()) {
- $category = Category::oldest('id')->first();
- } else {
- $category = Category::where('is_private', false)->oldest('id')->first();
- }
+ Route::get('/', function () {
+ if (Auth::user()) {
+ $category = Category::oldest('id')->first();
+ } else {
+ $category = Category::where('is_private', false)->oldest('id')->first();
+ }
- // If no category is found, redirect to /setup
- if (! $category) {
- return redirect('/setup');
- }
+ // If no category is found, redirect to /setup
+ if (! $category) {
+ return redirect('/setup');
+ }
- // Otherwise, redirect to the category's name route
- return redirect("/{$category->name}");
-});
+ $folder = $category->default_folder_id ? Folder::find($category->default_folder_id) : $category->folders()->first();
+ // Otherwise, redirect to the category's name route
+ return redirect("/{$category->name}/{$folder->name}");
+ });
-Route::get('/{dir?}/{folderName?}', function () {
- return view('home');
-})->name('root');
+ Route::get('/{dir?}/{folderName?}', function () {
+ return view('home');
+ })->name('root');
-Route::get('/{any}', function () {
- return view('home');
-})->where('any', '.*');
+ Route::get('/{any}', function () {
+ return view('home');
+ })->where('any', '.*');
+});