admin import/validate

This commit is contained in:
Danilo Reyes
2026-02-28 21:17:46 -06:00
parent da87b6f9d2
commit 2ccdd713ea
2 changed files with 105 additions and 2 deletions

View File

@@ -347,6 +347,13 @@ def get_links(
return conn.execute(f"SELECT * FROM links {clause} ORDER BY user_name, id", params).fetchall()
def get_links_by_user(conn: sqlite3.Connection, user_name: str) -> list[sqlite3.Row]:
return conn.execute(
"SELECT * FROM links WHERE user_name = ? ORDER BY id",
(user_name,),
).fetchall()
def import_master_list(conn: sqlite3.Connection, user_name: str, path: Path) -> dict:
if not path.is_file():
return {"status": "missing", "path": str(path)}
@@ -356,15 +363,33 @@ def import_master_list(conn: sqlite3.Connection, user_name: str, path: Path) ->
added = 0
exists = 0
removed = 0
duplicates: list[str] = []
for line in lines:
result = add_link(conn, user_name, line, assume_yes=True, source="import")
disabled = False
raw = line
if raw.startswith("#"):
disabled = True
raw = raw.lstrip("#").strip()
if not raw:
continue
result = add_link(conn, user_name, raw, assume_yes=True, source="import")
if result["status"] == "added":
added += 1
if disabled:
set_enabled(conn, user_name, raw, enabled=False)
elif result["status"] == "exists":
exists += 1
duplicates.append(raw)
elif result["status"] == "removed":
removed += 1
return {"status": "ok", "added": added, "exists": exists, "removed": removed}
return {
"status": "ok",
"added": added,
"exists": exists,
"removed": removed,
"duplicates": duplicates,
}
def bulk_rename_handle(