Links and Other Enhancements

This commit is contained in:
2026-03-02 19:55:04 +00:00
parent cf84d6d2dd
commit 0ed86ee2dc
24 changed files with 475 additions and 153 deletions

View File

@@ -13,6 +13,7 @@ from sqlalchemy import text
from core.database import get_db
from core.base_repository import BaseRepository
from core.sidebar import get_sidebar_data
from routers.weblinks import get_default_folder_id
router = APIRouter(prefix="/capture", tags=["capture"])
templates = Jinja2Templates(directory="templates")
@@ -24,7 +25,7 @@ CONVERT_TYPES = {
"list_item": "List Item",
"contact": "Contact",
"decision": "Decision",
"weblink": "Weblink",
"link": "Link",
}
@@ -309,8 +310,8 @@ async def convert_to_decision(
return RedirectResponse(url=f"/decisions/{decision['id']}", status_code=303)
@router.post("/{capture_id}/to-weblink")
async def convert_to_weblink(
@router.post("/{capture_id}/to-link")
async def convert_to_link(
capture_id: str, request: Request,
label: Optional[str] = Form(None),
url: Optional[str] = Form(None),
@@ -321,7 +322,7 @@ async def convert_to_weblink(
if not item:
return RedirectResponse(url="/capture", status_code=303)
weblink_repo = BaseRepository("weblinks", db)
link_repo = BaseRepository("links", db)
raw = item["raw_text"]
url_match = re.search(r'https?://\S+', raw)
link_url = (url.strip() if url and url.strip() else None) or (url_match.group(0) if url_match else raw)
@@ -330,13 +331,20 @@ async def convert_to_weblink(
link_label = link_url
data = {"label": link_label, "url": link_url}
weblink = await weblink_repo.create(data)
link = await link_repo.create(data)
# Assign to Default folder
default_fid = await get_default_folder_id(db)
await db.execute(text("""
INSERT INTO folder_links (folder_id, link_id)
VALUES (:fid, :lid) ON CONFLICT DO NOTHING
"""), {"fid": default_fid, "lid": link["id"]})
await capture_repo.update(capture_id, {
"processed": True, "converted_to_type": "weblink",
"converted_to_id": str(weblink["id"]),
"processed": True, "converted_to_type": "link",
"converted_to_id": str(link["id"]),
})
return RedirectResponse(url="/weblinks", status_code=303)
return RedirectResponse(url="/links", status_code=303)
@router.post("/{capture_id}/dismiss")