Update manual add
This commit is contained in:
parent
5593d802b3
commit
426aa670fa
1 changed files with 21 additions and 2 deletions
23
handlers.py
23
handlers.py
|
|
@ -411,25 +411,44 @@ def handle_add_manual_submit(body):
|
||||||
tags = body.get("tags", [""])[0].strip()
|
tags = body.get("tags", [""])[0].strip()
|
||||||
manual_title = body.get("manual_title", [""])[0].strip()
|
manual_title = body.get("manual_title", [""])[0].strip()
|
||||||
manual_desc = body.get("manual_description", [""])[0].strip()
|
manual_desc = body.get("manual_description", [""])[0].strip()
|
||||||
|
|
||||||
if not url:
|
if not url:
|
||||||
return handle_add_form("URL is required.")
|
return handle_add_form("URL is required.")
|
||||||
if not manual_title or not manual_desc:
|
if not manual_title or not manual_desc:
|
||||||
return handle_add_form("Title and description are required for manual entry.")
|
return handle_add_form("Title and description are required for manual entry.")
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
try:
|
try:
|
||||||
now = __import__("datetime").datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
now = __import__("datetime").datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
||||||
|
|
||||||
|
# Insert the page
|
||||||
db.execute(
|
db.execute(
|
||||||
"INSERT INTO pages (url, title, body, note, last_modified, summary) VALUES (?, ?, ?, ?, ?, ?) "
|
"INSERT INTO pages (url, title, body, note, last_modified, summary) VALUES (?, ?, ?, ?, ?, ?) "
|
||||||
"ON CONFLICT(url) DO UPDATE SET title=excluded.title, body=excluded.body, "
|
"ON CONFLICT(url) DO UPDATE SET title=excluded.title, body=excluded.body, "
|
||||||
"note=excluded.note, last_modified=excluded.last_modified, summary=excluded.summary",
|
"note=excluded.note, last_modified=excluded.last_modified, summary=excluded.summary",
|
||||||
(url, manual_title, manual_desc, note, now, manual_desc[:200]),
|
(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]
|
page_id = db.execute("SELECT id FROM pages WHERE url = ?", (url,)).fetchone()[0]
|
||||||
|
|
||||||
|
# Add tags if provided
|
||||||
if tags:
|
if tags:
|
||||||
_set_page_tags(page_id, tags, db)
|
_set_page_tags(page_id, tags, db)
|
||||||
|
|
||||||
db.commit()
|
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: <a href="{esc(url)}">{esc(manual_title)}</a>')
|
return handle_add_form(f'Added manually: <a href="{esc(url)}">{esc(manual_title)}</a>')
|
||||||
finally:
|
finally:
|
||||||
return_db(db)
|
return_db(db)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue