minor dashboard changes
This commit is contained in:
@@ -9,10 +9,16 @@ import { DEFAULT_IMAGES } from '$lib/content/defaults';
|
||||
const UPLOAD_DIR = join(process.cwd(), 'static', 'img', 'uploads');
|
||||
const MAX_BYTES = 8 * 1024 * 1024; // 8 MB
|
||||
const ALLOWED = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif', 'image/svg+xml']);
|
||||
const LOCKED_SLOTS = new Set(['cima_logo']);
|
||||
|
||||
export const load: PageServerLoad = () => {
|
||||
const content = getContent();
|
||||
return { images: content.images };
|
||||
const images: typeof content.images = {};
|
||||
for (const [id, img] of Object.entries(content.images)) {
|
||||
if (LOCKED_SLOTS.has(id)) continue;
|
||||
images[id] = img;
|
||||
}
|
||||
return { images };
|
||||
};
|
||||
|
||||
function extFromType(type: string, fallbackName: string): string {
|
||||
@@ -33,7 +39,7 @@ export const actions: Actions = {
|
||||
const alt = String(form.get('alt') ?? '').trim();
|
||||
const file = form.get('file');
|
||||
|
||||
if (!slot || !(slot in DEFAULT_IMAGES)) return fail(400, { error: 'Slot immagine non valido.' });
|
||||
if (!slot || !(slot in DEFAULT_IMAGES) || LOCKED_SLOTS.has(slot)) return fail(400, { error: 'Slot immagine non valido.' });
|
||||
if (!(file instanceof File) || !file.size) {
|
||||
// alt-only update
|
||||
if (alt) {
|
||||
@@ -59,7 +65,7 @@ export const actions: Actions = {
|
||||
reset: async ({ request }) => {
|
||||
const form = await request.formData();
|
||||
const slot = String(form.get('slot') ?? '');
|
||||
if (!slot || !(slot in DEFAULT_IMAGES)) return fail(400, { error: 'Slot non valido.' });
|
||||
if (!slot || !(slot in DEFAULT_IMAGES) || LOCKED_SLOTS.has(slot)) return fail(400, { error: 'Slot non valido.' });
|
||||
|
||||
const current = getContent().images[slot];
|
||||
if (current?.src?.startsWith('/img/uploads/')) {
|
||||
|
||||
Reference in New Issue
Block a user