Merge pull request #47 from gamosoft/bugfix/create-from-template-overwrite

Bugfix/create from template overwrite
This commit is contained in:
Gamosoft 2025-11-27 09:18:07 +01:00 committed by GitHub
commit e315696a6d
2 changed files with 21 additions and 5 deletions

View File

@ -854,15 +854,24 @@ async def create_note_from_template(request: Request, data: dict):
# Apply placeholder replacements # Apply placeholder replacements
final_content = apply_template_placeholders(template_content, note_path) final_content = apply_template_placeholders(template_content, note_path)
# Save the note # Run on_note_create hook BEFORE saving (allows plugins to modify initial content)
success = save_note(config['storage']['notes_dir'], note_path, final_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: if not success:
raise HTTPException(status_code=500, detail="Failed to create note from template") 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 { return {
"success": True, "success": True,
"path": note_path, "path": note_path,

View File

@ -634,6 +634,13 @@ function noteApp() {
notePath = `${targetFolder}/${notePath}`; 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 // Create note from template
const response = await fetch('/api/templates/create-note', { const response = await fetch('/api/templates/create-note', {
method: 'POST', method: 'POST',