Skip to content

A self-hosted media server and file management system

fix: record resource overcomplex

aminnausine247fd4fe43c
diff --git a/app/Http/Controllers/Api/V1/RecordController.php b/app/Http/Controllers/Api/V1/RecordController.php
index cdb96b5d..7f7483d3 100644
--- a/app/Http/Controllers/Api/V1/RecordController.php
+++ b/app/Http/Controllers/Api/V1/RecordController.php
@@ -25,13 +25,12 @@ class RecordController extends Controller {
$records->limit($request->limit);
}
- return $this->success(
- RecordResource::collection(
- $records->get()
- )
- );
+ return RecordResource::collection($records->get());
}
+ /**
+ * Gets the number of times a user has viewed a metadata (media) resource (number of records with that metadata resource)
+ */
public function userViewCount(Metadata $metadata) {
return Record::where('user_id', Auth::id())->where('metadata_id', $metadata->id)->count();
}
@@ -55,6 +54,8 @@ class RecordController extends Controller {
'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
]);
+ $record->load('metadata.video.folder.category');
+
return $this->success(new RecordResource($record));
}
diff --git a/app/Http/Resources/RecordResource.php b/app/Http/Resources/RecordResource.php
index c6863efc..73176628 100755
--- a/app/Http/Resources/RecordResource.php
+++ b/app/Http/Resources/RecordResource.php
@@ -12,25 +12,26 @@ class RecordResource extends JsonResource {
* @return array<string, mixed>
*/
public function toArray(Request $request): array {
- $metadata = $this->metadata;
+ $metadata = $this->relationLoaded('metadata') ? $this->metadata : null;
$video = $metadata?->video;
$folder = $video?->folder;
$category = $folder?->category;
return [
- 'id' => (string) $this->id,
- 'attributes' => [
- 'created_at' => $this->created_at,
- 'updated_at' => $this->updated_at,
- ],
- 'relationships' => [
- 'folder' => $folder ?? ['name' => 'Unknown'],
- 'metadata' => $metadata,
- 'category' => $category,
- 'video_id' => $metadata->video_id ?? null,
- 'video_name' => $metadata->title ?? $video->name ?? $this->name ?? 'Deleted',
- 'file_name' => $this->name,
- ],
+ 'id' => $this->id,
+ // 'attributes' => [
+ 'created_at' => $this->created_at,
+ 'updated_at' => $this->updated_at,
+ // ],
+ // 'relationships' => [
+ // 'folder' => $folder ?? ['name' => 'Unknown'],
+ 'metadata' => $metadata,
+ 'category' => $category,
+ 'video_id' => $metadata?->video_id,
+ 'video_name' => $metadata?->title ?? $video?->name ?? 'Deleted',
+ 'folder_name' => $folder?->name ?? 'Unknown',
+ 'file_name' => $this->name ?? null,
+ // ],
];
}
}
diff --git a/resources/js/components/cards/RecordCard.vue b/resources/js/components/cards/RecordCard.vue
index 8376208a..05aafb64 100755
--- a/resources/js/components/cards/RecordCard.vue
+++ b/resources/js/components/cards/RecordCard.vue
@@ -14,16 +14,11 @@ const props = defineProps<{
index: number;
}>();
-const rawDate = new Date((props.record.attributes.created_at ?? '').replace(' ', 'T'));
+const rawDate = new Date((props.record.created_at ?? '').replace(' ', 'T'));
const timeSpan = ref(toTimeSpan(rawDate));
const videoLink = computed(() => {
- if (
- !(props.record.relationships.video_id ?? props.record.relationships.metadata?.video_id) ||
- !props.record.relationships.category?.name ||
- !props.record.relationships.folder?.name
- )
- return false;
- return `/${encodeURIComponent(props.record.relationships?.category?.name ?? '')}/${encodeURIComponent(props.record.relationships.folder?.name ?? '')}?video=${props.record.relationships.video_id ?? props.record.relationships.metadata?.video_id}`;
+ if (!(props.record.video_id ?? props.record.metadata?.video_id) || !props.record.category?.name || !props.record.folder_name) return false;
+ return `/${encodeURIComponent(props.record?.category?.name ?? '')}/${encodeURIComponent(props.record.folder_name ?? '')}?video=${props.record.video_id ?? props.record.metadata?.video_id}`;
});
watch(
@@ -37,11 +32,11 @@ watch(
<template>
<RouterLink
:to="videoLink ? videoLink : ''"
- class="text-left relative flex flex-col gap-4 lg:gap-2 sm:flex-row flex-wrap rounded-lg dark:bg-primary-dark-800/70 bg-primary-800 dark:hover:bg-primary-dark-600 hover:bg-gray-200 text-neutral-600 dark:text-neutral-400 shadow-sm p-3 w-full group cursor-pointer divide-gray-300 dark:divide-gray-400"
+ class="dark:bg-primary-dark-800/70 bg-primary-800 dark:hover:bg-primary-dark-600 group relative flex w-full cursor-pointer flex-col flex-wrap gap-4 divide-gray-300 rounded-lg p-3 text-left text-neutral-600 shadow-sm hover:bg-gray-200 sm:flex-row lg:gap-2 dark:divide-gray-400 dark:text-neutral-400"
>
- <section class="flex justify-between gap-4 w-full items-center">
- <h3 class="w-full truncate text-gray-900 dark:text-white" :title="props.record.relationships.video_name">
- {{ props.record.relationships.video_name }}
+ <section class="flex w-full items-center justify-between gap-4">
+ <h3 class="w-full truncate text-gray-900 dark:text-white" :title="props.record.video_name">
+ {{ props.record.video_name }}
</h3>
<div class="flex justify-end gap-1" v-if="videoLink">
<ButtonCorner
@@ -67,19 +62,19 @@ watch(
</template>
</ButtonCorner>
</div>
- <div class="flex justify-end gap-1 w-full truncate" v-else>
+ <div class="flex w-full justify-end gap-1 truncate" v-else>
{{ 'Deleted' }}
</div>
</section>
- <section class="flex flex-wrap sm:flex-nowrap sm:justify-between w-full gap-x-2 text-sm">
- <h4 class="hidden lg:block w-full text-wrap truncate sm:text-nowrap shrink-0 sm:shrink" :title="props.record.relationships.folder?.name">
- {{ props.record.relationships.folder?.name }}
+ <section class="flex w-full flex-wrap gap-x-2 text-sm sm:flex-nowrap sm:justify-between">
+ <h4 class="hidden w-full shrink-0 truncate text-wrap sm:shrink sm:text-nowrap lg:block" :title="props.record.folder_name">
+ {{ props.record.folder_name }}
</h4>
- <h4 class="hidden lg:block truncate text-right w-full line-clamp-2" :title="toFormattedDate(rawDate)">
+ <h4 class="line-clamp-2 hidden w-full truncate text-right lg:block" :title="toFormattedDate(rawDate)">
{{ timeSpan }}
</h4>
- <h4 class="lg:hidden text-wrap truncate sm:text-nowrap mr-auto">{{ props.record.relationships.folder?.name }} · {{ timeSpan }}</h4>
- <h4 class="lg:hidden truncate sm:text-right line-clamp-2 text-wrap sm:text-nowrap">
+ <h4 class="mr-auto truncate text-wrap sm:text-nowrap lg:hidden">{{ props.record.folder_name }} · {{ timeSpan }}</h4>
+ <h4 class="line-clamp-2 truncate text-wrap sm:text-right sm:text-nowrap lg:hidden">
{{
`${rawDate.toLocaleDateString('en-ca', {
year: 'numeric',
diff --git a/resources/js/components/cards/RecordCardDetails.vue b/resources/js/components/cards/RecordCardDetails.vue
index b895fc55..d27f2d60 100755
--- a/resources/js/components/cards/RecordCardDetails.vue
+++ b/resources/js/components/cards/RecordCardDetails.vue
@@ -10,26 +10,26 @@ const props = defineProps<{
data: RecordResource;
}>();
-const rawDate = new Date((props.data?.attributes.created_at ?? '').replace(' ', 'T'));
+const rawDate = new Date((props.data?.created_at ?? '').replace(' ', 'T'));
const timeSpan = toTimeSpan(rawDate);
const videoLink = computed(() => {
- if (!props.data.relationships.video_id || !props.data.relationships.category?.name || !props.data.relationships.folder?.name) return false;
- return `/${encodeURIComponent(props.data.relationships?.category?.name ?? '')}/${encodeURIComponent(props.data.relationships.folder?.name ?? '')}?video=${props.data.relationships.video_id}`;
+ if (!props.data.video_id || !props.data.category?.name || !props.data.folder_name) return false;
+ return `/${encodeURIComponent(props.data?.category?.name ?? '')}/${encodeURIComponent(props.data.folder_name ?? '')}?video=${props.data.video_id}`;
});
</script>
<template>
<section
- class="text-left relative flex flex-col gap-4 sm:flex-row flex-wrap rounded-xl dark:bg-primary-dark-800/70 bg-white ring-1 ring-gray-900/5 dark:hover:bg-primary-dark-600 hover:bg-primary-800 dark:text-white shadow-sm p-3 w-full group cursor-pointer divide-gray-300 dark:divide-neutral-400"
+ class="dark:bg-primary-dark-800/70 dark:hover:bg-primary-dark-600 hover:bg-primary-800 group relative flex w-full cursor-pointer flex-col flex-wrap gap-4 divide-gray-300 rounded-xl bg-white p-3 text-left shadow-sm ring-1 ring-gray-900/5 sm:flex-row dark:divide-neutral-400 dark:text-white"
>
- <RouterLink v-if="videoLink" :to="videoLink" class="absolute w-full h-full top-0 left-0 rounded-xl" title="Watch Video" />
+ <RouterLink v-if="videoLink" :to="videoLink" class="absolute top-0 left-0 h-full w-full rounded-xl" title="Watch Video" />
- <section class="flex justify-between gap-4 w-full">
- <h2 class="truncate z-10 flex items-center" :title="props.data.relationships.file_name">
- {{ props.data.relationships.video_name }}
+ <section class="flex w-full justify-between gap-4">
+ <h2 class="z-10 flex items-center truncate" :title="props.data.file_name">
+ {{ props.data.video_name }}
</h2>
- <div class="flex justify-end gap-1 cursor-auto z-10" @click.stop.prevent="">
+ <div class="z-10 flex cursor-auto justify-end gap-1" @click.stop.prevent="">
<ButtonCorner
v-if="videoLink"
:positionClasses="'w-7 h-7'"
@@ -51,9 +51,9 @@ const videoLink = computed(() => {
/>
</div>
</section>
- <section class="flex flex-col sm:flex-row sm:justify-between w-full text-neutral-600 dark:text-neutral-400 text-sm">
+ <section class="flex w-full flex-col text-sm text-neutral-600 sm:flex-row sm:justify-between dark:text-neutral-400">
<h3
- class="w-full text-wrap truncate sm:text-nowrap cursor-auto z-10"
+ class="z-10 w-full cursor-auto truncate text-wrap sm:text-nowrap"
@click.stop.prevent=""
:title="`Watched on ${rawDate.toLocaleDateString('en-ca', {
year: 'numeric',
@@ -64,9 +64,9 @@ const videoLink = computed(() => {
minute: '2-digit',
})}`"
>
- {{ props.data.relationships.folder?.name }} · {{ timeSpan }}
+ {{ props.data.folder_name }} · {{ timeSpan }}
</h3>
- <h3 class="truncate sm:text-right w-full line-clamp-2 cursor-auto z-10" @click.stop.prevent="">
+ <h3 class="z-10 line-clamp-2 w-full cursor-auto truncate sm:text-right" @click.stop.prevent="">
{{
`${rawDate.toLocaleDateString('en-ca', {
year: 'numeric',
diff --git a/resources/js/types/resources.ts b/resources/js/types/resources.ts
index 9e478adf..c2d8f69a 100644
--- a/resources/js/types/resources.ts
+++ b/resources/js/types/resources.ts
@@ -33,12 +33,13 @@ export interface CategoryResource {
export interface FolderResource {
id: number;
name: string;
+ title: string;
path: string;
file_count: number;
total_size: number;
is_majority_audio: boolean;
category_id: number;
- videos?: VideoResource[];
+ videos: VideoResource[];
series?: SeriesResource;
scanned_at?: string;
created_at?: string;
@@ -77,19 +78,20 @@ export interface PlaybackResource {
}
export interface RecordResource {
id: number;
- attributes: {
- created_at?: string;
- updated_at?: string;
- };
- relationships: {
- folder?: Folder | { name: string };
- metadata?: Metadata;
- category?: Category;
- video_id?: number; // from metadata so eventually remove
- video_name?: string;
- file_name?: string;
- };
+ // attributes: {
+ created_at?: string;
+ updated_at?: string;
+ // };
+ // relationships: {
+ // folder?: Folder | { name: string };
+ metadata?: Metadata;
+ category?: Category;
+ video_id?: number; // from metadata so eventually remove
+ video_name?: string;
+ folder_name?: string;
+ file_name?: string;
}
+// }
export interface SeriesResource {
id: number;
folder_id?: number;
@@ -125,7 +127,7 @@ export interface VideoResource {
duration?: number;
episode?: number;
season?: number;
- view_count?: number;
+ view_count: number;
file_size?: number;
video_tags: VideoTagResource[];
date_created: string;