Update storage.ts

This commit is contained in:
fcarraUniSa
2025-12-11 14:10:02 +01:00
committed by GitHub
parent 646276698e
commit 74d18e9dd5

View File

@@ -34,25 +34,25 @@ export const generateN8nCode = (template: EmailTemplate): string => {
const varsMap = template.variables.map(v => ` "${v}": "REPLACE_WITH_VALUE"`).join(',\n'); const varsMap = template.variables.map(v => ` "${v}": "REPLACE_WITH_VALUE"`).join(',\n');
const hasVars = template.variables.length > 0; const hasVars = template.variables.length > 0;
return `// n8n Code Node - Template Populator return `// Nodo Code n8n - Popolatore Template
// 1. Ensure the previous node (SQL) returns 'full_html' and 'subject'. // 1. Assicurati che il nodo precedente (SQL) restituisca 'full_html' e 'subject'.
// 2. Adjust path (item.json.full_html) if your SQL node output is different. // 2. Aggiusta il percorso (item.json.full_html) se l'output del tuo nodo SQL è diverso.
for (const item of items) { for (const item of items) {
const templateHtml = item.json.full_html; const templateHtml = item.json.full_html;
const templateSubject = item.json.subject; const templateSubject = item.json.subject;
// Define your dynamic data here // Definisci qui i tuoi dati dinamici
const replacements = { const replacements = {
${hasVars ? varsMap : ' // No variables detected in this template'} ${hasVars ? varsMap : ' // Nessuna variabile rilevata in questo template'}
}; };
let finalHtml = templateHtml; let finalHtml = templateHtml;
let finalSubject = templateSubject; let finalSubject = templateSubject;
// Perform replacement // Esegui sostituzione
for (const [key, value] of Object.entries(replacements)) { 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'); const regex = new RegExp('{{' + key + '}}', 'g');
finalHtml = finalHtml.replace(regex, value); finalHtml = finalHtml.replace(regex, value);
if (finalSubject) { 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_html = finalHtml;
item.json.processed_subject = finalSubject; item.json.processed_subject = finalSubject;
} }
@@ -72,10 +72,10 @@ return items;`;
export const getTemplates = async (): Promise<EmailTemplate[]> => { export const getTemplates = async (): Promise<EmailTemplate[]> => {
try { try {
const response = await fetch('/api/templates'); 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(); return await response.json();
} catch (e) { } catch (e) {
console.error("Failed to load templates", e); console.error("Fallito il caricamento dei template", e);
return []; return [];
} }
}; };
@@ -92,10 +92,10 @@ export const saveTemplate = async (template: EmailTemplate): Promise<void> => {
if (!response.ok) { if (!response.ok) {
const error = await response.json(); const error = await response.json();
throw new Error(error.message || 'Failed to save'); throw new Error(error.message || 'Salvataggio fallito');
} }
} catch (e) { } catch (e) {
console.error("Failed to save template", e); console.error("Fallito il salvataggio del template", e);
throw e; throw e;
} }
}; };
@@ -105,9 +105,9 @@ export const deleteTemplate = async (id: string): Promise<void> => {
const response = await fetch(`/api/templates/${id}`, { const response = await fetch(`/api/templates/${id}`, {
method: 'DELETE', method: 'DELETE',
}); });
if (!response.ok) throw new Error('Failed to delete'); if (!response.ok) throw new Error('Eliminazione fallita');
} catch (e) { } catch (e) {
console.error("Failed to delete template", e); console.error("Fallita l'eliminazione del template", e);
throw e; throw e;
} }
}; };