CI / check (push) Successful in 30s
CI / tests-imaging-browsers (push) Successful in 1m31s
CI / tests-unit (push) Successful in 1m45s
CI / tests-integration (push) Successful in 1m49s
CI / tests-quality (push) Successful in 47s
CI / tests-ui (push) Successful in 4m24s
CI / preflight (push) Skipped
CI / deploy (push) Successful in 3m39s
The project lints with Biome only, so none of these 78 directives across 57 files ever suppressed anything. Directives that carried the rationale for a flagged dynamic index access keep that rationale as a plain comment.
51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
"use server";
|
|
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { revalidatePath } from "next/cache";
|
|
import { requirePermission } from "@/lib/admin/guard";
|
|
import { db, WebsiteSetting } from "@/lib/db";
|
|
import { validateSiteImageUpload } from "@/lib/images/site-image-upload";
|
|
import { logger } from "@/lib/logger";
|
|
import { resolveMediaPath } from "@/lib/media-storage";
|
|
import { PERMS } from "@/lib/permissions";
|
|
import { siteSettings } from "@/lib/services/site-settings";
|
|
|
|
export async function saveLogo(
|
|
formData: FormData,
|
|
): Promise<{ success: boolean; url?: string; error?: string }> {
|
|
await requirePermission(PERMS.SETTINGS_EDIT);
|
|
try {
|
|
const upload = await validateSiteImageUpload(
|
|
formData instanceof FormData ? formData.get("file") : null,
|
|
);
|
|
if (!upload.success) return upload;
|
|
const ext = upload.extension;
|
|
const filename = `logo-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.${ext}`;
|
|
const baseDir = resolveMediaPath("logo");
|
|
const filePath = path.resolve(baseDir, filename);
|
|
if (!filePath.startsWith(baseDir + path.sep)) {
|
|
return { success: false, error: "Invalid path" };
|
|
}
|
|
|
|
const buffer = upload.bytes;
|
|
await mkdir(baseDir, { recursive: true });
|
|
await writeFile(filePath, buffer);
|
|
|
|
const url = `/api/media/logo/${filename}`;
|
|
|
|
await db
|
|
.insert(WebsiteSetting)
|
|
.values({ key: "cms_logo", value: url, comment: "Logo (generator)" })
|
|
.onDuplicateKeyUpdate({ set: { value: url } });
|
|
|
|
siteSettings.reload();
|
|
revalidatePath("/", "layout");
|
|
|
|
return { success: true, url };
|
|
} catch {
|
|
logger.error("Site logo update failed", { module: "site-images" });
|
|
return { success: false, error: "Could not update site logo" };
|
|
}
|
|
}
|