Skip to content

A self-hosted media server and file management system

fix: route fuzzy search issues and video search

aminnausin993dfeb16267
diff --git a/app/Services/PathResolverService.php b/app/Services/PathResolverService.php
index cdd5660a..2a11e3d9 100644
--- a/app/Services/PathResolverService.php
+++ b/app/Services/PathResolverService.php
@@ -25,15 +25,15 @@ class PathResolverService {
public function resolveCategory(string $identifier, array $select = ['id', 'name', 'default_folder_id', 'is_private']): Category {
return $this->firstSuccessful([
- fn () => $this->resolveCategoryByName($identifier, $select),
- fn () => $this->resolveCategoryById($identifier, $select),
+ fn() => $this->resolveCategoryByName($identifier, $select),
+ fn() => $this->resolveCategoryById($identifier, $select),
], "No category found matching '{$identifier}'");
}
private function resolveCategoryByName(string $identifier, array $select): ?Category {
return $this->addPrivacyFilter(Category::query())
- ->select(...$select)
- ->whereRaw('LOWER(name) = ?', [strtolower($identifier)])
+ ->select(...$select)->where('name', 'ilike', '%' . $identifier . '%')
+ ->orderByRaw("POSITION(lower(?) in lower(name))", [$identifier])
->first();
}
@@ -52,8 +52,8 @@ class PathResolverService {
}
return $this->firstSuccessful([
- fn () => $this->resolveFolderByName($identifier, $category, $folders),
- fn () => $this->resolveFolderById($identifier, $category, $folders),
+ fn() => $this->resolveFolderByName($identifier, $category, $folders),
+ fn() => $this->resolveFolderById($identifier, $category, $folders),
], "No folder found in category '{$category->name}' matching '{$identifier}'");
}
diff --git a/resources/js/components/table/TableBase.vue b/resources/js/components/table/TableBase.vue
index e7f7e970..8d54b839 100755
--- a/resources/js/components/table/TableBase.vue
+++ b/resources/js/components/table/TableBase.vue
@@ -42,11 +42,17 @@ const props = withDefaults(
itemsPerPage: 12,
selectedID: null,
startAscending: true,
+ searchQuery: '',
},
);
const tableData = useTable(props);
const sortAscending = ref(props.startAscending);
const lastSortKey = ref('');
+const emit = defineEmits(['search']);
+const model = defineModel<string | undefined>({
+ required: false,
+ default: undefined,
+});
const handleSortChange = (sortKey?: { title?: string; value?: string; disabled?: boolean }) => {
if (sortKey?.value) {
@@ -57,6 +63,21 @@ const handleSortChange = (sortKey?: { title?: string; value?: string; disabled?:
props.sortAction(lastSortKey.value, sortAscending.value ? 1 : -1);
};
+const handleSearch = (event: Event) => {
+ const target = event.target as HTMLInputElement | null;
+
+ if (!target) return;
+
+ const value = target.value;
+
+ if (model.value !== undefined) {
+ model.value = value;
+ } else {
+ tableData.fields.searchQuery = value;
+ }
+ emit('search', value);
+};
+
onMounted(() => {
if (props.useToolbar && props.sortAction) props.sortAction(lastSortKey.value, props.startAscending ? 1 : -1);
});
@@ -67,14 +88,24 @@ onMounted(() => {
<section class="flex flex-col gap-4">
<section v-if="props.useToolbar" class="flex justify-center sm:justify-between flex-col sm:flex-row gap-2">
<TextInputLabelled
- v-model="tableData.fields.searchQuery"
+ :value="model ?? tableData.fields.searchQuery"
:text="'Search:'"
:placeholder="'Enter Search Query...'"
:id="'table-search'"
class="w-full sm:w-80"
- @input="$emit('search', tableData.fields.searchQuery)"
title="Search Here"
+ @input="handleSearch"
/>
+ <!-- <TextInputLabelled
+ v-else
+ v-model="tableData.fields.searchQuery"
+ :text="'Search:'"
+ :placeholder="'Enter Search Query...'"
+ :id="'table-search'"
+ class="w-full sm:w-80"
+ title="Search Here"
+ @input="$emit('search', tableData.fields.searchQuery)"
+ /> -->
<span class="flex items-end gap-2 flex-wrap">
<div class="flex gap-2 flex-col w-full sm:w-40 flex-1">
<FormInputLabel :field="{ name: 'sort', text: 'Sort by:' }" />
diff --git a/resources/js/stores/ContentStore.js b/resources/js/stores/ContentStore.js
index 178982e6..e1b0e8eb 100755
--- a/resources/js/stores/ContentStore.js
+++ b/resources/js/stores/ContentStore.js
@@ -1,8 +1,8 @@
import { defineStore, storeToRefs } from 'pinia';
import { computed, ref } from 'vue';
import { useAuthStore } from '@/stores/AuthStore';
-import { sortObject } from '@/service/util';
-import { useRoute } from 'vue-router';
+import { formatFileSize, sortObject, toFormattedDate, toFormattedDuration } from '@/service/util';
+import { useRoute, useRouter } from 'vue-router';
import { toast } from '@/service/toaster/toastService';
import recordsAPI from '@/service/recordsAPI';
@@ -11,6 +11,7 @@ import mediaAPI from '@/service/mediaAPI.ts';
export const useContentStore = defineStore('Content', () => {
const AuthStore = useAuthStore();
const route = useRoute();
+ const router = useRouter();
const fullRecordsLoaded = ref(false);
const stateRecords = ref([]);
@@ -34,16 +35,18 @@ export const useContentStore = defineStore('Content', () => {
let strRepresentation = [
video.name,
video.title,
- video.date,
+ toFormattedDate(new Date(video?.date_uploaded ?? video.date + ' GMT')),
video.description,
video.episode ?? '',
video.season ?? '',
video.views,
+ toFormattedDuration(video.duration) ?? 'N/A',
video.video_tags?.length ? video.video_tags.reduce((tags, tag) => `${tags} ${tag?.name ?? ''}`, '') : '',
+ formatFileSize(video.file_size),
]
.join(' ')
.toLowerCase();
- // console.log(strRepresentation);
+ console.log(strRepresentation);
return strRepresentation.includes(searchQuery.value.toLowerCase());
} catch (error) {
@@ -154,13 +157,26 @@ export const useContentStore = defineStore('Content', () => {
stateDirectory.value = response.data.dir;
stateFolder.value = response.data.folder;
- // folders.value = data.data.dir.folders;
if (!stateFolder.value.id) {
toast.add('Invalid folder', { type: 'danger', description: `The folder '${stateFolder.value.name}' does not exist.` });
return false;
}
+ const correctCategory = stateDirectory.value.name;
+ const correctFolder = stateFolder.value.name;
+
+ if (route.params.category !== correctCategory || route.params.folder !== correctFolder) {
+ router.replace({
+ name: route.name,
+ params: {
+ category: correctCategory,
+ folder: correctFolder,
+ },
+ query: route.query,
+ });
+ }
+
searchQuery.value = '';
playlistFind(route.query?.video);
@@ -199,6 +215,8 @@ export const useContentStore = defineStore('Content', () => {
stateFolder.value = { ...data.data };
+ searchQuery.value = '';
+
playlistFind(route.query?.video);
return Promise.resolve(true);
}
diff --git a/resources/js/views/VideoView.vue b/resources/js/views/VideoView.vue
index 3b115c96..cb0404d5 100755
--- a/resources/js/views/VideoView.vue
+++ b/resources/js/views/VideoView.vue
@@ -19,7 +19,7 @@ import EditVideo from '@/components/forms/EditVideo.vue';
import useModal from '@/composables/useModal';
const route = useRoute();
-const loading = ref(false);
+const isLoading = ref(false);
const editVideoModal = useModal({ title: 'Edit Video Details', submitText: 'Submit Details' });
const shareVideoModal = useModal({ title: 'Share Video' });
@@ -52,13 +52,13 @@ async function cycleSideBar(state: string) {
}
async function reload() {
- if (loading.value) return;
+ if (isLoading.value) return;
try {
const URL_CATEGORY = route.params.category;
const URL_FOLDER = route.params.folder;
- loading.value = true;
+ isLoading.value = true;
if (stateDirectory.value?.name && stateDirectory.value.name === URL_CATEGORY && URL_FOLDER) {
await getFolder(URL_FOLDER);
@@ -68,7 +68,7 @@ async function reload() {
} catch (error) {
console.log(error);
}
- loading.value = false;
+ isLoading.value = false;
setFolderAsPageTitle();
}
@@ -167,8 +167,19 @@ watch(
},
{ immediate: false },
);
-watch(() => route.params.folder, reload, { immediate: false });
-watch(() => route.params.category, reload, { immediate: false });
+
+watch(
+ () => [route.params.category, route.params.folder],
+ async ([newCategory, newFolder]) => {
+ // if (newCategory === stateDirectory.value?.name && newFolder === stateFolder.value.name) {
+ // setVideoAsDocumentTitle();
+ // return;
+ // }
+
+ await reload();
+ },
+ { immediate: false },
+);
watch(() => selectedSideBar.value, cycleSideBar, { immediate: false });
watch(() => stateFolder.value, setFolderAsPageTitle);
watch(() => stateVideo.value, setVideoAsDocumentTitle, { immediate: true });
@@ -188,13 +199,15 @@ watch(() => stateVideo.value, setVideoAsDocumentTitle, { immediate: true });
:row="VideoCard"
:clickAction="playlistFind"
:otherAction="handleVideoAction"
- :loading="loading"
+ :loading="isLoading"
:useToolbar="true"
:sortAction="handleSort"
:sortingOptions="sortingOptions"
:selectedID="stateVideo?.id"
:startAscending="true"
+ :search-query="searchQuery"
@search="handleSearch"
+ v-model="searchQuery"
/>
<ModalBase :modalData="editVideoModal" :useControls="false">