From 74d18e9dd5167ccd59afa4ee821cae82fd4494cc Mon Sep 17 00:00:00 2001 From: fcarraUniSa Date: Thu, 11 Dec 2025 14:10:02 +0100 Subject: [PATCH] Update storage.ts --- services/storage.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/services/storage.ts b/services/storage.ts index 96d620b..f6b200f 100644 --- a/services/storage.ts +++ b/services/storage.ts @@ -34,25 +34,25 @@ export const generateN8nCode = (template: EmailTemplate): string => { const varsMap = template.variables.map(v => ` "${v}": "REPLACE_WITH_VALUE"`).join(',\n'); const hasVars = template.variables.length > 0; - return `// n8n Code Node - Template Populator -// 1. Ensure the previous node (SQL) returns 'full_html' and 'subject'. -// 2. Adjust path (item.json.full_html) if your SQL node output is different. + return `// Nodo Code n8n - Popolatore Template +// 1. Assicurati che il nodo precedente (SQL) restituisca 'full_html' e 'subject'. +// 2. Aggiusta il percorso (item.json.full_html) se l'output del tuo nodo SQL รจ diverso. for (const item of items) { const templateHtml = item.json.full_html; const templateSubject = item.json.subject; - // Define your dynamic data here + // Definisci qui i tuoi dati dinamici const replacements = { -${hasVars ? varsMap : ' // No variables detected in this template'} +${hasVars ? varsMap : ' // Nessuna variabile rilevata in questo template'} }; let finalHtml = templateHtml; let finalSubject = templateSubject; - // Perform replacement + // Esegui sostituzione for (const [key, value] of Object.entries(replacements)) { - // Replaces {{key}} globally in HTML and Subject + // Sostituisce {{key}} globalmente nell'HTML e nell'Oggetto const regex = new RegExp('{{' + key + '}}', 'g'); finalHtml = finalHtml.replace(regex, value); if (finalSubject) { @@ -60,7 +60,7 @@ ${hasVars ? varsMap : ' // No variables detected in this template'} } } - // Output the processed content + // Output del contenuto processato item.json.processed_html = finalHtml; item.json.processed_subject = finalSubject; } @@ -72,10 +72,10 @@ return items;`; export const getTemplates = async (): Promise => { try { const response = await fetch('/api/templates'); - if (!response.ok) throw new Error('Failed to fetch'); + if (!response.ok) throw new Error('Fallito il recupero'); return await response.json(); } catch (e) { - console.error("Failed to load templates", e); + console.error("Fallito il caricamento dei template", e); return []; } }; @@ -92,10 +92,10 @@ export const saveTemplate = async (template: EmailTemplate): Promise => { if (!response.ok) { const error = await response.json(); - throw new Error(error.message || 'Failed to save'); + throw new Error(error.message || 'Salvataggio fallito'); } } catch (e) { - console.error("Failed to save template", e); + console.error("Fallito il salvataggio del template", e); throw e; } }; @@ -105,9 +105,9 @@ export const deleteTemplate = async (id: string): Promise => { const response = await fetch(`/api/templates/${id}`, { method: 'DELETE', }); - if (!response.ok) throw new Error('Failed to delete'); + if (!response.ok) throw new Error('Eliminazione fallita'); } catch (e) { - console.error("Failed to delete template", e); + console.error("Fallita l'eliminazione del template", e); throw e; } };