Skip to content

A self-hosted media server and file management system

fix: simplify metadata resource shape to reduce request sizes

aminnausin928d6c7e395c
diff --git a/app/Http/Resources/MetadataResource.php b/app/Http/Resources/MetadataResource.php
index 62f72c0b..4fe6c8cf 100644
--- a/app/Http/Resources/MetadataResource.php
+++ b/app/Http/Resources/MetadataResource.php
@@ -14,26 +14,37 @@ class MetadataResource extends JsonResource {
public function toArray(Request $request): array {
return [
'id' => $this->id,
- 'attributes' => [
- 'title' => $this->title ?? $this->video->name,
- 'description' => $this->description,
- 'season' => $this->season,
- 'episode' => $this->episode,
- 'duration' => $this->duration,
- 'view_count' => $this->view_count,
- 'file_size' => $this->file_size,
- 'intro_start' => $this->intro_start,
- 'intro_duration' => $this->intro_duration,
- 'released_at' => $this->released_at, // user provided metadata
- 'edited_at' => $this->edited_at, // last user edit time
- 'file_modified_at' => $this->first_file_modified_at ?: $this->file_modified_at, // file_mtime from disk (required)
- 'updated_at' => $this->updated_at, // db update time
- ],
- 'relationships' => [
- 'video_id' => $this->video_id,
- 'editor_id' => $this->editor_id,
- 'video_tags' => VideoTagResource::collection($this->videoTags),
- ],
+ 'uuid' => $this->uuid,
+
+ 'video_id' => $this->video_id,
+ 'editor_id' => $this->editor_id,
+
+ 'title' => $this->title,
+ 'lyrics' => $this->lyrics,
+
+ 'poster_url' => $this->poster_url,
+
+ 'duration' => $this->duration,
+ 'mime_type' => $this->mime_type,
+ 'codec' => $this->codec,
+ 'bitrate' => $this->bitrate,
+ 'resolution_width' => $this->resolution_width,
+ 'resolution_height' => $this->resolution_height,
+ 'frame_rate' => $this->frame_rate,
+ 'media_type' => $this->media_type,
+
+ 'created_at' => $this->created_at,
+ 'updated_at' => $this->updated_at, // db update time
+ 'edited_at' => $this->edited_at, // last user edit time
+
+ 'file_scanned_at' => $this->file_scanned_at,
+ // file_modified_at is file_mtime from disk (defaults to first seen date rather than the date of any updated files)
+ 'file_modified_at' => $this->first_file_modified_at ?: $this->file_modified_at,
+ 'first_file_modified_at' => $this->first_file_modified_at,
+ 'subtitles_scanned_at' => $this->subtitles_scanned_at,
+
+ 'progress_offset' => $this->playbackProgress?->progress_offset ?? 0,
+ 'progress_percentage' => $this->playbackProgress?->progress_percentage ?? 0,
];
}
}
diff --git a/app/Http/Resources/VideoResource.php b/app/Http/Resources/VideoResource.php
index f16dd72c..ce8b194b 100755
--- a/app/Http/Resources/VideoResource.php
+++ b/app/Http/Resources/VideoResource.php
@@ -26,6 +26,7 @@ class VideoResource extends JsonResource {
'id' => $this->id,
'name' => $this->name,
'path' => $this->path,
+
'title' => $metadata?->title ?: $this->name,
'description' => $metadata?->description, // ?: $this->folder->series->description
'duration' => $metadata?->duration,
@@ -33,18 +34,23 @@ class VideoResource extends JsonResource {
'season' => $metadata?->season,
'artist' => $metadata?->artist,
'album' => $metadata?->album,
- 'view_count' => $metadata?->view_count ?? 0,
- 'file_size' => $metadata?->file_size ?: null,
- 'video_tags' => VideoTagResource::collection($metadata->videoTags ?? []),
'intro_start' => $metadata->intro_start,
'intro_duration' => $metadata->intro_duration,
+
+ 'video_tags' => VideoTagResource::collection($this->relationLoaded('metadata.videoTags') ? $metadata->videoTags : []),
+ 'subtitles' => SubtitleResource::collection($metadata->subtitles ?? []),
+
+ 'view_count' => $metadata?->view_count ?? 0,
+
+ 'file_size' => $metadata?->file_size ?: null,
+
'created_at' => $this->created_at, // Date Added to Server
'updated_at' => $metadata?->updated_at ?: null, // Metadata Last Updated
'released_at' => $metadata?->released_at ?: null, // User Provided Release Date in F d, Y ?
'file_modified_at' => $metadata?->first_file_modified_at ?: $metadata?->file_modified_at ?: null, // File Last Modified (Should be date_added)
'edited_at' => $metadata?->edited_at,
- 'metadata' => $metadata,
- 'subtitles' => SubtitleResource::collection($metadata->subtitles ?? []),
+
+ 'metadata' => new MetadataResource($metadata),
];
}
}
diff --git a/resources/js/contracts/media.ts b/resources/js/contracts/media.ts
index af21ece6..9ee40560 100644
--- a/resources/js/contracts/media.ts
+++ b/resources/js/contracts/media.ts
@@ -1,5 +1,5 @@
import type { FolderTagResource, VideoTagResource } from '@/contracts/tags';
-import type { Metadata } from '@/types/model';
+import type { MediaTypeValue } from '@/types/types';
export interface CategoryResource {
id: number;
@@ -60,30 +60,56 @@ export interface SeriesResource {
//#region Media
export interface MetadataResource {
+ // Commented out attributes are duplicated in VideoResource?
+
+ // Id
id: number;
- attributes: {
- title?: string;
- description?: string;
- poster_url?: string;
- season?: number;
- episode?: number;
- duration?: number;
- artist?: string;
- album?: string;
- view_count?: number;
- file_size?: number;
- intro_start?: number;
- intro_duration?: number;
- released_at?: string;
- file_modified_at?: string;
- edited_at?: string;
- updated_at?: string;
- };
- relationships: {
- video_id?: number;
- editor_id?: number;
- video_tags?: VideoTagResource[];
- };
+ uuid?: string;
+
+ // Fk
+ video_id?: number;
+ editor_id?: number;
+
+ // User Editable
+ title?: string;
+ // description?: string;
+ lyrics?: string;
+ // episode?: number;
+ // season?: number;
+ poster_url?: string;
+ artist?: string;
+ album?: string;
+ // released_at?: string;
+ // intro_start?: number;
+ // intro_duration?: number;
+ // video_tags?: VideoTagResource[];
+
+ // API Editable
+ // view_count?: number;
+
+ // FFmpeg Generated
+ duration?: number;
+ // file_size?: number;
+ mime_type?: string;
+ codec?: string;
+ bitrate?: number;
+ resolution_width?: number;
+ resolution_height?: number;
+ frame_rate?: number;
+ media_type: MediaTypeValue;
+
+ // Date info
+ created_at?: string;
+ // updated_at?: string;
+ edited_at?: string;
+
+ file_scanned_at?: string;
+ file_modified_at?: string;
+ first_file_modified_at?: string;
+ subtitles_scanned_at?: string;
+
+ progress_offset?: number;
+ progress_percentage: number;
}
export interface VideoResource {
@@ -107,7 +133,7 @@ export interface VideoResource {
updated_at?: string;
file_modified_at?: string;
edited_at?: string;
- metadata?: Metadata;
+ metadata?: MetadataResource;
subtitles: SubtitleResource[];
}
diff --git a/resources/js/service/lyricsService.ts b/resources/js/service/lyricsService.ts
index b8ca4e40..2fd04428 100644
--- a/resources/js/service/lyricsService.ts
+++ b/resources/js/service/lyricsService.ts
@@ -1,6 +1,6 @@
import type { LyricsUpdateRequest } from '@/types/requests';
+import type { MetadataResource } from '@/contracts/media';
import type { LrcLibResult } from '@/types/types';
-import type { Metadata } from '@/types/model';
import { API } from '@/service/api';
@@ -40,7 +40,7 @@ export function updateLyrics(id: number, data: LyricsUpdateRequest) {
return API.patch(`/metadata/${id}/lyrics`, data);
}
-export const generateLyricsSearchQuery = (metadata?: Metadata, track?: string, album?: string, artist?: string): string | undefined => {
+export const generateLyricsSearchQuery = (metadata?: MetadataResource, track?: string, album?: string, artist?: string): string | undefined => {
if (!metadata) return undefined;
const params = new URLSearchParams();
diff --git a/resources/js/stores/LyricStore.ts b/resources/js/stores/LyricStore.ts
index e7c5bad2..4baaf24e 100644
--- a/resources/js/stores/LyricStore.ts
+++ b/resources/js/stores/LyricStore.ts
@@ -1,5 +1,5 @@
+import type { MetadataResource } from '@/contracts/media';
import type { LrcLibResult } from '@/types/types';
-import type { Metadata } from '@/types/model';
import { fetchSyncedLyrics, searchSyncedLyrics } from '@/service/lyricsService';
import { defineStore, storeToRefs } from 'pinia';
@@ -97,7 +97,7 @@ export const useLyricStore = defineStore('Lyric', () => {
}
};
- const validateData = (metadata: typeof stateVideo.value.metadata): Metadata => {
+ const validateData = (metadata: typeof stateVideo.value.metadata): MetadataResource => {
if (!metadata) {
toast.error('Data is malformed.');
throw new Error('Metadata is missing');