Skip to content

A self-hosted media server and file management system

chore: code smell function scope

aminnausina53886b2cf53
diff --git a/resources/js/composables/useMetaData.ts b/resources/js/composables/useMetaData.ts
index 5ee5227d..1f701ac4 100644
--- a/resources/js/composables/useMetaData.ts
+++ b/resources/js/composables/useMetaData.ts
@@ -1,7 +1,7 @@
import type { VideoResource } from '@/types/resources';
import type { Ref } from 'vue';
-import { toFormattedDuration } from '@/service/util';
+import { toFormattedDuration, toPlural } from '@/service/util';
import { MediaType } from '@/types/types';
import { computed } from 'vue';
@@ -13,49 +13,49 @@ export default function useMetaData(data: Ref<VideoResource>) {
const views = computed(() => generateViewsTag(data.value.view_count));
const description = computed(() => generateDescription(data.value.description ?? ''));
- function generateEpisodeTag(episodeData: VideoResource) {
- return episodeData.episode && episodeData.metadata?.media_type === MediaType.AUDIO ? `${episodeData.episode}. ` : '';
- }
+ return {
+ title,
+ duration,
+ views,
+ description,
+ };
+}
- function generateViewsTag(viewCount: number = 0) {
- return `${viewCount} view${viewCount !== 1 ? 's' : ''}`;
- }
+function generateEpisodeTag(episodeData: VideoResource) {
+ return episodeData.episode && episodeData.metadata?.media_type === MediaType.AUDIO ? `${episodeData.episode}. ` : '';
+}
- function generateDescription(description: string) {
- const parts: { type: 'text' | 'timestamp'; text?: string; raw?: string; seconds?: number }[] = [];
+function generateViewsTag(viewCount: number = 0) {
+ return `${viewCount} view${toPlural(viewCount)}`;
+}
- let lastIndex = 0;
- let match: RegExpExecArray | null;
+function generateDescription(description: string) {
+ const parts: { type: 'text' | 'timestamp'; text?: string; raw?: string; seconds?: number }[] = [];
- const regex = /(?:(\d{1,2}):)?(\d{1,2}):(\d{2}(?:\.\d+)?)/g;
+ let lastIndex = 0;
+ let match: RegExpExecArray | null;
- while ((match = regex.exec(description)) !== null) {
- const [full, hour, min, sec] = match;
- const start = match.index;
- const end = regex.lastIndex;
+ const regex = /(?:(\d{1,2}):)?(\d{1,2}):(\d{2}(?:\.\d+)?)/g;
- if (start > lastIndex) {
- parts.push({ type: 'text', text: description.slice(lastIndex, start) });
- }
+ while ((match = regex.exec(description)) !== null) {
+ const [full, hour, min, sec] = match;
+ const start = match.index;
+ const end = regex.lastIndex;
- const seconds = Number.parseInt(hour ?? '0') * 3600 + Number.parseInt(min) * 60 + Number.parseFloat(sec);
+ if (start > lastIndex) {
+ parts.push({ type: 'text', text: description.slice(lastIndex, start) });
+ }
- parts.push({ type: 'timestamp', raw: full, seconds });
+ const seconds = Number.parseInt(hour ?? '0') * 3600 + Number.parseInt(min) * 60 + Number.parseFloat(sec);
- lastIndex = end;
- }
+ parts.push({ type: 'timestamp', raw: full, seconds });
- if (lastIndex < description.length) {
- parts.push({ type: 'text', text: description.slice(lastIndex) });
- }
+ lastIndex = end;
+ }
- return parts;
+ if (lastIndex < description.length) {
+ parts.push({ type: 'text', text: description.slice(lastIndex) });
}
- return {
- title,
- duration,
- views,
- description,
- };
+ return parts;
}