initial: blog-app snapshot

This commit is contained in:
omo
2026-08-17 17:11:27 +08:00
commit 65cb9d5ead
125 changed files with 14720 additions and 0 deletions

38
routes/watchdog.py Normal file
View File

@@ -0,0 +1,38 @@
"""Watchdog blueprint: /watchdog page + /watchdog/run trigger (CSRF-guarded)."""
import logging
from flask import Blueprint, flash, redirect, render_template, request, url_for
from extensions import get_db, get_watchdog_db
from repositories import project_repo
from security import validate_csrf
from services import watchdog as watchdog_service
logger = logging.getLogger(__name__)
bp = Blueprint("watchdog", __name__)
@bp.route("/watchdog")
def page_watchdog():
days = watchdog_service.parse_days(request.args.get("days"), default=7)
reports = watchdog_service.load_watchdog_reports(get_watchdog_db(), days=days)
starred = project_repo.get_starred_names(get_db())
return render_template(
"watchdog.html", reports=reports, days=days, starred=starred
)
@bp.route("/watchdog/run", methods=["POST"])
def watchdog_run():
validate_csrf()
ok, status, message = watchdog_service.trigger_watchdog_run()
if ok:
flash(message, "success")
elif status in ("cooldown",):
flash(message, "warning")
else:
flash(message, "danger")
return redirect(url_for("watchdog.page_watchdog"))