diff --git a/handlers.py b/handlers.py index ef5488e..5903d0b 100644 --- a/handlers.py +++ b/handlers.py @@ -411,25 +411,44 @@ def handle_add_manual_submit(body): tags = body.get("tags", [""])[0].strip() manual_title = body.get("manual_title", [""])[0].strip() manual_desc = body.get("manual_description", [""])[0].strip() - + if not url: return handle_add_form("URL is required.") if not manual_title or not manual_desc: return handle_add_form("Title and description are required for manual entry.") - + db = get_db() try: now = __import__("datetime").datetime.now().strftime("%Y-%m-%dT%H:%M:%S") + + # Insert the page db.execute( "INSERT INTO pages (url, title, body, note, last_modified, summary) VALUES (?, ?, ?, ?, ?, ?) " "ON CONFLICT(url) DO UPDATE SET title=excluded.title, body=excluded.body, " "note=excluded.note, last_modified=excluded.last_modified, summary=excluded.summary", (url, manual_title, manual_desc, note, now, manual_desc[:200]), ) + + # Get the page ID page_id = db.execute("SELECT id FROM pages WHERE url = ?", (url,)).fetchone()[0] + + # Add tags if provided if tags: _set_page_tags(page_id, tags, db) + db.commit() + + # Generate embeddings for this page (if semantic search is enabled) + if get_setting("semantic_search", "1") == "1": + try: + from embeddings import store_embeddings + # Pass the page_id, title, description, and db connection + store_embeddings(page_id, manual_title, manual_desc, db) + db.commit() + except Exception as e: + # Log error but don't fail the whole operation + print(f"Error generating embeddings: {e}") + return handle_add_form(f'Added manually: {esc(manual_title)}') finally: return_db(db)