From 608b1b68d2e8b5883e5fe9bfc2d0cce27c5967e3 Mon Sep 17 00:00:00 2001 From: AdrianoDev Date: Sun, 5 Jul 2026 17:35:41 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20pannello=20contenuti=20=E2=80=94=20PUT?= =?UTF-8?q?=20ritorna=20value=20salvato,=20data-q=20aggiornato,=20guard=20?= =?UTF-8?q?hash,=20aria-label?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/admin/content.astro | 19 ++++++++++++------- src/pages/api/admin/content/[tag].ts | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/pages/admin/content.astro b/src/pages/admin/content.astro index 2779967..bafa84e 100644 --- a/src/pages/admin/content.astro +++ b/src/pages/admin/content.astro @@ -43,7 +43,7 @@ const allStyles = STYLE_GROUPS as Record;

Contenuti

Vedi sito con tag ↗ - +
{GROUP_ORDER.map((g) => { @@ -66,7 +66,7 @@ const allStyles = STYLE_GROUPS as Record; : Nessun override: il sito usa l'immagine originale.}

- +

@@ -74,8 +74,8 @@ const allStyles = STYLE_GROUPS as Record; ) : ( <> {isLong(it.value) - ? - : } + ? + : } {it.styleOptions.length > 0 && (

{it.styleOptions.map((sg) => ( @@ -185,9 +185,13 @@ const allStyles = STYLE_GROUPS as Record; headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ value, styles }), }), - () => { + (data) => { + const saved = typeof data.value === 'string' ? data.value : value; + const field = row.querySelector('[data-value]')!; + field.value = saved; + row.dataset.q = `${row.dataset.tag} ${saved}`.toLowerCase(); row.querySelector('.crow-snippet')!.textContent = - value.length > 60 ? `${value.slice(0, 60)}…` : value; + saved.length > 60 ? `${saved.slice(0, 60)}…` : saved; }, 'Salvato.', 'Salvataggio non riuscito.'); } else if (btn.hasAttribute('data-upload')) { @@ -226,7 +230,8 @@ const allStyles = STYLE_GROUPS as Record; // Ancore: # apre gruppo + riga, scrolla ed evidenzia. function openHash(): void { - const tag = decodeURIComponent(location.hash.slice(1)); + let tag: string; + try { tag = decodeURIComponent(location.hash.slice(1)); } catch { return; } if (!tag) return; const row = document.getElementById(tag); if (!row || !row.classList.contains('crow')) return; diff --git a/src/pages/api/admin/content/[tag].ts b/src/pages/api/admin/content/[tag].ts index 753b7c7..1fd7c0b 100644 --- a/src/pages/api/admin/content/[tag].ts +++ b/src/pages/api/admin/content/[tag].ts @@ -14,5 +14,8 @@ export const PUT: APIRoute = async ({ params, request, locals }) => { const r = applyContentUpdate(getDb(), params.tag ?? '', data, locals.user!.username); if (!r.ok) return json(r.status, { error: r.error }); invalidateContentCache(); - return json(200, { ok: true }); + // Il value salvato può differire da quello inviato (sanitizeInline sui tag html): + // lo restituiamo così il pannello mostra il dato reale. + const row = getDb().prepare('SELECT value FROM content_blocks WHERE tag = ?').get(params.tag) as { value: string }; + return json(200, { ok: true, value: row.value }); };