Skip to content

A self-hosted media server and file management system

feat: supported file types config

aminnausin91b8aa57efc1
diff --git a/resources/css/theme.css b/resources/css/theme.css
index 56ae02fa..66f8baa0 100644
--- a/resources/css/theme.css
+++ b/resources/css/theme.css
@@ -23,9 +23,6 @@
.transition-input {
transition-property:
- /* color, */
- /* background-color, */
- /* border-color, */
outline-color,
text-decoration-color,
fill,
@@ -41,15 +38,35 @@
rotate,
filter,
-webkit-backdrop-filter,
- backdrop-filter,
- display,
- content-visibility,
- overlay,
- pointer-events;
+ backdrop-filter;
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function) /* cubic-bezier(0.4, 0, 0.2, 1) */);
transition-duration: var(--tw-duration, var(--duration-input) /* 150ms */);
}
+ .transition-input.transition-reveal {
+ transition-property:
+ outline-color,
+ text-decoration-color,
+ fill,
+ stroke,
+ --tw-gradient-from,
+ --tw-gradient-via,
+ --tw-gradient-to,
+ opacity,
+ box-shadow,
+ transform,
+ translate,
+ scale,
+ rotate,
+ filter,
+ -webkit-backdrop-filter,
+ backdrop-filter,
+ width,
+ max-width,
+ margin,
+ padding;
+ }
+
.duration-input {
--tw-duration: var(--duration-input) /* 200ms */;
}
diff --git a/resources/js/components/cedar-ui/form/FormError.vue b/resources/js/components/cedar-ui/form/FormError.vue
new file mode 100644
index 00000000..55ab4325
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/FormError.vue
@@ -0,0 +1,7 @@
+<script setup lang="ts"></script>
+
+<template>
+ <p class="text-danger text-sm">
+ <slot> </slot>
+ </p>
+</template>
diff --git a/resources/js/components/config/ConfigGeneral.vue b/resources/js/components/config/ConfigGeneral.vue
index 1b185056..3cee95f1 100644
--- a/resources/js/components/config/ConfigGeneral.vue
+++ b/resources/js/components/config/ConfigGeneral.vue
@@ -4,6 +4,7 @@ import type { BreadCrumbItem } from '@/types/types';
import { BreadCrumbs } from '@/components/cedar-ui/breadcrumbs';
import { computed } from 'vue';
+import ConfigServerFileTypes from '@/components/config/server/ConfigServerFileTypes.vue';
import ConfigServerIndexing from '@/components/config/server/ConfigServerIndexing.vue';
import ConfigServerStorage from '@/components/config/server/ConfigServerStorage.vue';
@@ -32,4 +33,5 @@ const breadCrumbs = computed(() => {
</section>
<ConfigServerIndexing />
<ConfigServerStorage />
+ <ConfigServerFileTypes />
</template>
diff --git a/resources/js/components/config/server/ConfigServerFileTypes.vue b/resources/js/components/config/server/ConfigServerFileTypes.vue
new file mode 100644
index 00000000..bc4a4ecf
--- /dev/null
+++ b/resources/js/components/config/server/ConfigServerFileTypes.vue
@@ -0,0 +1,193 @@
+<script setup lang="ts">
+import type { MediaConfigRequest } from '@/contracts/server';
+
+import { COMMON_AUDIO_EXTENSIONS, COMMON_EXTENSIONS, COMMON_SUBTITLE_EXTENSIONS, COMMON_VIDEO_EXTENSIONS } from '@/constants/config/mediaExtentions';
+import { ButtonBase, ButtonCorner, ButtonForm, ButtonText } from '@/components/cedar-ui/button';
+import { UseUpdateMediaConfig } from '@/service/server/mutations';
+import { useGetConfig } from '@/service/server/queries';
+import { ref, watch } from 'vue';
+import { FormInput } from '@/components/cedar-ui/form';
+import { cn, toast } from '@aminnausin/cedar-ui';
+import { FLAGS } from '@/config/featureFlags';
+
+import SettingsHeader from '@/components/settings/SettingsHeader.vue';
+import SettingsCard from '@/components/cards/layout/SettingsCard.vue';
+import FormError from '@/components/cedar-ui/form/FormError.vue';
+import useForm from '@/composables/useForm';
+
+const { data: serverConfig, isLoading } = useGetConfig();
+const saveConfig = UseUpdateMediaConfig();
+
+const SECTIONS: { name: 'video' | 'audio' | 'subtitles'; extensions: string[] }[] = [
+ { name: 'video', extensions: COMMON_VIDEO_EXTENSIONS },
+ { name: 'audio', extensions: COMMON_AUDIO_EXTENSIONS },
+ { name: 'subtitles', extensions: COMMON_SUBTITLE_EXTENSIONS },
+];
+
+const selectedExtensions = ref<Set<string>>(new Set());
+
+const customExtensions = ref<string[]>([]);
+const customExtensionError = ref<string>('');
+const customExtensionInput = ref('');
+
+const form = useForm<MediaConfigRequest>({
+ supported_extentions: [...selectedExtensions.value],
+});
+
+function toggleExtension(ext: string) {
+ if (selectedExtensions.value.has(ext)) selectedExtensions.value.delete(ext);
+ else selectedExtensions.value.add(ext);
+
+ updateForm();
+}
+
+function addCustomExtension() {
+ const raw = customExtensionInput.value.trim().toLowerCase().replace(/^\./, '');
+ if (!/^(?=.*[a-z])[a-z0-9]{2,5}$/.test(raw)) {
+ customExtensionError.value = 'Invalid extension';
+ return;
+ }
+ if (selectedExtensions.value.has(raw)) {
+ customExtensionError.value = 'This extension already exists';
+ return;
+ }
+ customExtensionError.value = '';
+ customExtensionInput.value = '';
+ selectedExtensions.value.add(raw);
+
+ if (!COMMON_EXTENSIONS.has(raw)) customExtensions.value.push(raw);
+
+ document.getElementById('custom-extension')?.focus();
+ updateForm();
+}
+
+function removeCustomExtension(ext: string) {
+ customExtensions.value = customExtensions.value.filter((e) => e !== ext);
+ selectedExtensions.value.delete(ext);
+ updateForm();
+}
+
+function updateForm() {
+ form.fields.supported_extentions = [...selectedExtensions.value];
+}
+
+const handleSaveFileTypes = () => {
+ form.submit((fields) => saveConfig.mutateAsync(fields), {
+ onSuccess: () => toast.success('File type settings saved.'),
+ onError: () => toast.error('Failed to save file type settings.'),
+ });
+};
+
+const setSavedExtensions = () => {
+ if (!serverConfig.value) return;
+
+ const currentExtensions = serverConfig.value.values.media.supported_extentions;
+
+ if (currentExtensions.length === 0) {
+ setDefaultExtentions();
+ return;
+ }
+
+ selectedExtensions.value = new Set(currentExtensions);
+ customExtensions.value = currentExtensions.filter((ext) => !COMMON_EXTENSIONS.has(ext));
+
+ form.init({ supported_extentions: currentExtensions });
+};
+
+const setDefaultExtentions = () => {
+ const values = serverConfig.value?.defaults.media.supported_extentions ?? [];
+ selectedExtensions.value = new Set(values);
+
+ if (!isLoading.value && values.length === 0) {
+ toast.warning('No default values found.');
+ }
+
+ updateForm();
+};
+
+watch(serverConfig, setSavedExtensions, { immediate: true });
+</script>
+
+<template>
+ <SettingsCard :class="['flex-col gap-6 truncate', { 'animate-pulse': isLoading }]">
+ <template #content>
+ <SettingsHeader>
+ <h3 class="text-base font-medium">Supported File Types<span v-if="form.dirty" class="text-danger"> *</span></h3>
+ <p class="text-foreground-2">Only selected file types will be scanned.</p>
+ </SettingsHeader>
+
+ <div class="flex w-full flex-col gap-4 font-medium">
+ <div
+ class="flex flex-col gap-2"
+ v-for="section in SECTIONS.filter((sec) => {
+ if (sec.name === 'subtitles' && !FLAGS.USE_SUBTITLE_EXTENTION_CONFIG) return false;
+ return true;
+ })"
+ :key="section.name"
+ >
+ <p class="text-foreground-1 text-xs tracking-widest uppercase">{{ section.name }}</p>
+ <div class="flex flex-wrap gap-2 gap-x-1">
+ <ButtonBase
+ v-for="ext in section.extensions"
+ :key="ext"
+ type="button"
+ @click="toggleExtension(ext)"
+ :class="
+ cn(
+ 'bg-overlay-t h-7 rounded-md px-2.5 shadow-sm dark:shadow-none',
+ selectedExtensions.has(ext)
+ ? 'bg-primary text-foreground-i dark:text-foreground-0 hover:bg-primary-active'
+ : 'text-foreground-2 hover:text-foreground-0 hover:bg-surface-2 ring-1 ring-transparent ring-inset hover:ring-current',
+ )
+ "
+ >
+ .{{ ext }}
+ </ButtonBase>
+ </div>
+ </div>
+
+ <div class="flex flex-col gap-2">
+ <p class="text-foreground-1 text-xs tracking-widest uppercase">Custom</p>
+ <div class="flex flex-wrap gap-2" v-if="customExtensions.length > 0">
+ <span
+ v-for="ext in customExtensions"
+ :key="ext"
+ class="bg-overlay-t text-foreground-1 hover:bg-surface-2 flex h-7 items-center gap-1 rounded-md px-2.5 shadow-sm dark:shadow-none"
+ >
+ .{{ ext }}
+ <ButtonCorner
+ :title="'remove custom extention'"
+ :position-classes="''"
+ :class="'text-danger mt-0.5 transition-colors duration-1000 *:size-2.5 hover:bg-transparent'"
+ @click="removeCustomExtension(ext)"
+ />
+ </span>
+ </div>
+ <form class="mt-2 flex flex-wrap items-center gap-1 *:h-8" @submit.prevent="addCustomExtension()">
+ <FormInput
+ v-model="customExtensionInput"
+ :field="{ name: 'custom-extension', type: 'text', placeholder: 'e.g. .mpv' }"
+ class="mt-0 w-full max-w-32 min-w-0"
+ required
+ />
+ <ButtonText type="submit" class="text-xs" :class="'px-3'"> Add </ButtonText>
+ </form>
+ <FormError v-if="customExtensionError">{{ customExtensionError }}</FormError>
+ </div>
+ </div>
+
+ <div class="xs:justify-end flex flex-wrap gap-1 *:h-8">
+ <ButtonForm variant="reset" :disabled="form.processing" @click="setDefaultExtentions"> Load defaults </ButtonForm>
+ <ButtonForm
+ variant="reset"
+ :class="cn('transition-reveal overflow-hidden', form.dirty ? 'mx-0 w-18 px-4 opacity-100' : '-mx-0.5 w-0 px-0 opacity-0')"
+ :disabled="form.processing"
+ @click="setSavedExtensions"
+ >
+ Reset
+ </ButtonForm>
+ <ButtonForm variant="submit" :disabled="form.processing" @click="handleSaveFileTypes"> Save </ButtonForm>
+ </div>
+ </template>
+ </SettingsCard>
+</template>
diff --git a/resources/js/composables/useForm.ts b/resources/js/composables/useForm.ts
index 2d2515b7..16c9b3d4 100644
--- a/resources/js/composables/useForm.ts
+++ b/resources/js/composables/useForm.ts
@@ -23,6 +23,7 @@ interface FormState<T> {
reset: (...fields: (keyof FormFields<T>)[]) => void;
clearErrors: (...fields: string[]) => void;
setErrors: (errors: { [key: string]: string }) => void;
+ init: (fields: FormFields<T>) => void;
}
export default function useForm<T extends Record<string, any>>(fields: FormFields<T>) {
@@ -107,6 +108,13 @@ export default function useForm<T extends Record<string, any>>(fields: FormField
});
}
},
+ init(fields) {
+ defaults = fields;
+ this.fields = cloneDeep(fields);
+ this.clearErrors();
+ this.wasSuccessful = false;
+ this.recentlySuccessful = false;
+ },
clearErrors(...fields: string[]) {
if (fields.length === 0) {
this.errors = {};
diff --git a/resources/js/config/featureFlags.ts b/resources/js/config/featureFlags.ts
index af08a524..9debfea1 100644
--- a/resources/js/config/featureFlags.ts
+++ b/resources/js/config/featureFlags.ts
@@ -9,4 +9,7 @@ export const FLAGS = {
USE_NAV_IN_SIDEBAR: false, // show settings or dashboard nav buttons in each sidebar
USE_APP_VERSION_CARD: true, // show app manifest/version card in sidebars (settings and dashboard)
USE_ASYMMETRICAL_PLAYER: false,
+
+ USE_MEDIA_EXTENTION_CONFIG: true, // Allow setting supported extentions
+ USE_SUBTITLE_EXTENTION_CONFIG: false, // Allow setting supported subtitle extentions
};
diff --git a/resources/js/constants/config/mediaExtentions.ts b/resources/js/constants/config/mediaExtentions.ts
new file mode 100644
index 00000000..626c6c79
--- /dev/null
+++ b/resources/js/constants/config/mediaExtentions.ts
@@ -0,0 +1,5 @@
+export const COMMON_VIDEO_EXTENSIONS = ['mp4', 'mkv', 'avi', 'mov', 'webm', 'm4v', 'ts'];
+export const COMMON_AUDIO_EXTENSIONS = ['mp3', 'flac', 'aac', 'ogg', 'wav', 'm4a', 'opus'];
+export const COMMON_SUBTITLE_EXTENSIONS = ['srt', 'ass', 'vtt', 'sub'];
+
+export const COMMON_EXTENSIONS = new Set([...COMMON_AUDIO_EXTENSIONS, ...COMMON_VIDEO_EXTENSIONS, ...COMMON_SUBTITLE_EXTENSIONS]);