diff --git a/backend/main.py b/backend/main.py index ad60af4..eb63054 100644 --- a/backend/main.py +++ b/backend/main.py @@ -854,15 +854,24 @@ async def create_note_from_template(request: Request, data: dict): # Apply placeholder replacements final_content = apply_template_placeholders(template_content, note_path) - # Save the note - success = save_note(config['storage']['notes_dir'], note_path, final_content) + # Run on_note_create hook BEFORE saving (allows plugins to modify initial content) + final_content = plugin_manager.run_hook_with_return( + 'on_note_create', + note_path=note_path, + initial_content=final_content + ) + + # Run on_note_save hook (can transform content, e.g., encrypt) + transformed_content = plugin_manager.run_hook('on_note_save', note_path=note_path, content=final_content) + if transformed_content is None: + transformed_content = final_content + + # Save the note with the (potentially modified/transformed) content + success = save_note(config['storage']['notes_dir'], note_path, transformed_content) if not success: raise HTTPException(status_code=500, detail="Failed to create note from template") - # Run plugin hooks - plugin_manager.run_hook('on_note_create', note_path=note_path, initial_content=final_content) - return { "success": True, "path": note_path, diff --git a/frontend/app.js b/frontend/app.js index 811f718..9ed5e39 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -634,6 +634,13 @@ function noteApp() { notePath = `${targetFolder}/${notePath}`; } + // CRITICAL: Check if note already exists + const existingNote = this.notes.find(note => note.path === notePath); + if (existingNote) { + alert(`A note named "${this.newTemplateNoteName.trim()}" already exists in this location.\nPlease choose a different name.`); + return; + } + // Create note from template const response = await fetch('/api/templates/create-note', { method: 'POST',