Refactor root admin dashboards and settings
This commit is contained in:
+3
-21
@@ -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: {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user