Rescue Paperjet v1 implementation
This commit is contained in:
parent
7ff5c8130d
commit
db9e2ca51b
83 changed files with 6186 additions and 3894 deletions
|
|
@ -5,8 +5,8 @@ This is the main entry point. The lifespan handler initializes the database
|
|||
and ensures required directories exist on startup.
|
||||
"""
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from collections.abc import AsyncGenerator
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import Any
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
|
|
@ -14,7 +14,8 @@ from fastapi.responses import JSONResponse
|
|||
|
||||
from app.api.v1 import router as v1_router
|
||||
from app.config import settings
|
||||
from app.db import Base, engine
|
||||
from app.db import Base, SessionLocal, engine
|
||||
from app.services.trash_sweep import prune_auto_versions, sweep_trash
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
|
@ -29,6 +30,12 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
|||
settings.THUMBNAILS_PATH.mkdir(parents=True, exist_ok=True)
|
||||
settings.DATABASE_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Run retention cleanup on every startup. This keeps the single-container
|
||||
# deployment self-maintaining without requiring a separate scheduler.
|
||||
with SessionLocal() as db:
|
||||
sweep_trash(db)
|
||||
prune_auto_versions(db)
|
||||
|
||||
yield
|
||||
|
||||
# Shutdown: dispose of the engine
|
||||
|
|
@ -48,6 +55,7 @@ app = FastAPI(
|
|||
|
||||
# --- Error handlers ---
|
||||
|
||||
|
||||
@app.exception_handler(404)
|
||||
async def not_found_handler(request: Request, exc: Any) -> JSONResponse:
|
||||
"""Consistent 404 error envelope."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue