Merge pull request #47 from gamosoft/bugfix/create-from-template-overwrite
Bugfix/create from template overwrite
This commit is contained in:
commit
e315696a6d
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue