Source code for dakweb.routers.information

# SPDX-License-Identifier: GPL-2.0-or-later
# © 2026, Ansgar 🙀 <ansgar@debian.org>

import datetime
from email.utils import format_datetime
from typing import Annotated

from fastapi import APIRouter, Depends, HTTPException, Path, Response, status
from fastapi.responses import PlainTextResponse
from sqlalchemy import select
from sqlalchemy.orm import Session

from daklib.dbconn import Information
from dakweb.routers.deps import get_db

router = APIRouter()


[docs] def _get_information(response: Response, db: Session, key: str) -> str: """ return `key` from the `Information` table or raise a `HTTPException` if not found """ row = db.execute( select(Information).where(Information.key == key) ).scalar_one_or_none() if row is None or row.value is None: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Not found") response.headers["Last-Modified"] = format_datetime( row.modified.astimezone(datetime.UTC), usegmt=True ) return row.value
[docs] @router.get("/dinstall.status", response_class=PlainTextResponse) def get_dinstall_status(response: Response, db: Session = Depends(get_db)) -> str: return _get_information(response, db, Information.KEY_DINSTALL_STATUS)
[docs] @router.get( "/api/information/v1/mirrorstart/{archive}", response_class=PlainTextResponse ) def get_mirrorstart( archive: Annotated[str, Path(max_length=128, pattern=r"^[a-z0-9-]+$")], response: Response, db: Session = Depends(get_db), ) -> str: return _get_information(response, db, f"mirrorstart.{archive}")
[docs] @router.get("/api/information/v1/trace/{archive}", response_class=PlainTextResponse) def get_trace( archive: Annotated[str, Path(max_length=128, pattern=r"^[a-z0-9-]+$")], response: Response, db: Session = Depends(get_db), ) -> str: return _get_information(response, db, f"trace.{archive}")