Refactor root admin dashboards and settings

This commit is contained in:
MOH
2026-03-10 16:43:43 +01:00
parent db6c5392bb
commit 5b51a2a063
26 changed files with 1121 additions and 781 deletions
+3 -21
View File
@@ -123,16 +123,11 @@ export async function createStandaloneMediaAsset(input: {
kind: MediaKind;
label: string;
uploadFile: FormDataEntryValue | null;
externalUrl: string;
}) {
const trimmedLabel = input.label.trim();
if (!trimmedLabel) {
throw new Error("Media label is required.");
}
if (input.uploadFile instanceof File && input.uploadFile.size > 0) {
const savedFile = await saveMediaUpload(input.uploadFile, input.kind.toLowerCase());
const derivedLabel = input.uploadFile.name.replace(/\.[^.]+$/, "").trim();
const trimmedLabel = input.label.trim() || derivedLabel || "Media asset";
if (!savedFile) {
throw new Error("Unable to save upload.");
@@ -150,20 +145,7 @@ export async function createStandaloneMediaAsset(input: {
});
}
const url = input.externalUrl.trim();
if (!url) {
throw new Error("Either an upload file or an external URL is required.");
}
return createMediaAsset({
source: MediaSource.EXTERNAL,
kind: input.kind,
url,
fileName: getFileNameFromUrl(url),
label: trimmedLabel,
altText: trimmedLabel,
});
throw new Error("Upload file is required.");
}
export async function deleteMediaAssetAndFile(input: {
+1 -1
View File
@@ -76,7 +76,7 @@ export async function saveMediaUpload(file: File, folder: string) {
}
const safeBaseName = sanitizeBaseName(file.name.replace(/\.[^.]+$/, "")) || "asset";
const finalName = `${Date.now()}-${safeBaseName}-${randomUUID().slice(0, 8)}${extension}`;
const finalName = `${safeBaseName}-${randomUUID().slice(0, 8)}${extension}`;
const targetDir = path.join(MEDIA_UPLOAD_ROOT, folder);
const targetPath = path.join(targetDir, finalName);