feat(admin): add feed/source management, rewrite editor, reopen flow, and WP block output
This commit is contained in:
parent
50f737f434
commit
88b2ee1d01
9 changed files with 555 additions and 70 deletions
|
|
@ -28,6 +28,26 @@ class FeedCreate:
|
|||
is_enabled: bool
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SourceUpdate:
|
||||
name: str
|
||||
base_url: str | None
|
||||
terms_url: str | None
|
||||
license_name: str | None
|
||||
risk_level: str
|
||||
is_enabled: bool
|
||||
notes: str | None
|
||||
last_reviewed_at: str | None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FeedUpdate:
|
||||
name: str
|
||||
url: str
|
||||
source_id: int | None
|
||||
is_enabled: bool
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class RunCreate:
|
||||
run_type: str
|
||||
|
|
@ -118,6 +138,35 @@ def get_source_by_id(source_id: int) -> dict[str, Any] | None:
|
|||
return dict(row) if row else None
|
||||
|
||||
|
||||
def update_source(source_id: int, payload: SourceUpdate) -> bool:
|
||||
with get_conn() as conn:
|
||||
cur = conn.execute(
|
||||
"""
|
||||
UPDATE sources
|
||||
SET name = ?, base_url = ?, terms_url = ?, license_name = ?, risk_level = ?, is_enabled = ?, notes = ?, last_reviewed_at = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(
|
||||
payload.name.strip(),
|
||||
payload.base_url,
|
||||
payload.terms_url,
|
||||
payload.license_name,
|
||||
payload.risk_level,
|
||||
1 if payload.is_enabled else 0,
|
||||
payload.notes,
|
||||
payload.last_reviewed_at,
|
||||
source_id,
|
||||
),
|
||||
)
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
def delete_source(source_id: int) -> bool:
|
||||
with get_conn() as conn:
|
||||
cur = conn.execute("DELETE FROM sources WHERE id = ?", (source_id,))
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
def create_feed(payload: FeedCreate) -> int:
|
||||
with get_conn() as conn:
|
||||
cur = conn.execute(
|
||||
|
|
@ -177,6 +226,31 @@ def get_feed_by_id(feed_id: int) -> dict[str, Any] | None:
|
|||
return dict(row) if row else None
|
||||
|
||||
|
||||
def update_feed(feed_id: int, payload: FeedUpdate) -> bool:
|
||||
with get_conn() as conn:
|
||||
cur = conn.execute(
|
||||
"""
|
||||
UPDATE feeds
|
||||
SET name = ?, url = ?, source_id = ?, is_enabled = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(
|
||||
payload.name.strip(),
|
||||
payload.url.strip(),
|
||||
payload.source_id,
|
||||
1 if payload.is_enabled else 0,
|
||||
feed_id,
|
||||
),
|
||||
)
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
def delete_feed(feed_id: int) -> bool:
|
||||
with get_conn() as conn:
|
||||
cur = conn.execute("DELETE FROM feeds WHERE id = ?", (feed_id,))
|
||||
return cur.rowcount > 0
|
||||
|
||||
|
||||
def update_feed_fetch_state(feed_id: int, etag: str | None, last_modified: str | None) -> None:
|
||||
with get_conn() as conn:
|
||||
conn.execute(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue