Files
truetype 3681fd95eb
deps-checksum / checksum lockfile (push) Canceled after 0s
CI / pytest (3.12) (push) Canceled after 0s
CI / Docker smoke test (push) Canceled after 0s
feat(R7): metrics + JSON logs + security headers
2026-08-31 16:24:51 +02:00

62 lines
2.8 KiB
Python

import os
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
DATA_DIR = os.path.abspath(os.environ.get("BOOKISH_DATA_DIR", BASE_DIR))
DEBUG = os.environ.get("BOOKISH_DEBUG", "false").lower() in {"1", "true", "yes"}
_DEFAULT_SECRET = "cambiami-in-produzione"
SECRET_KEY = os.environ.get("BOOKISH_SECRET", _DEFAULT_SECRET)
if not DEBUG and (not SECRET_KEY or SECRET_KEY == _DEFAULT_SECRET):
raise RuntimeError(
"BOOKISH_SECRET deve essere impostato quando BOOKISH_DEBUG=false"
)
UPLOAD_FOLDER = os.path.join(DATA_DIR, "uploads")
CONVERTED_FOLDER = os.path.join(DATA_DIR, "converted")
DB_PATH = os.path.join(DATA_DIR, "bookish.db")
MAX_FILE_SIZE = 50 * 1024 * 1024 # 50 MB
CLEANUP_HOURS = int(os.environ.get("BOOKISH_CLEANUP_HOURS", "1"))
# Autenticazione opzionale (Basic). Se entrambe le variabili sono valorizzate,
# tutte le route tranne healthz/static richiedono preventivamente il login.
AUTH_USERNAME = os.environ.get("BOOKISH_AUTH_USERNAME") or None
AUTH_PASSWORD = os.environ.get("BOOKISH_AUTH_PASSWORD") or None
# Rate limit: numero massimo di upload per IP nell'arco di un'ora.
# 0 disabilita il limite.
RATE_LIMIT_UPLOAD = int(os.environ.get("BOOKISH_RATE_LIMIT_UPLOAD", "20"))
# Logging: "json" abilita il formato strutturato (una riga JSON per log)
LOG_FORMAT = os.environ.get("LOG_FORMAT", "").lower()
# Timeout conversioni (secondi): per documentazione/guardia via gunicorn
CONVERSION_TIMEOUT_SECONDS = int(os.environ.get("BOOKISH_CONVERSION_TIMEOUT", "300"))
# Formati supportati
SUPPORTED_FORMATS = {
"epub": {"label": "EPUB", "mime": "application/epub+zip"},
"md": {"label": "Markdown", "mime": "text/markdown"},
"docx": {"label": "DOCX", "mime": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
"pdf": {"label": "PDF", "mime": "application/pdf"},
"txt": {"label": "Testo", "mime": "text/plain"},
"html": {"label": "HTML", "mime": "text/html"},
"fb2": {"label": "FB2", "mime": "application/x-fictionbook+xml"},
"latex": {"label": "LaTeX", "mime": "text/x-tex"},
"mobi": {"label": "MOBI", "mime": "application/x-mobipocket-ebook"},
}
# Conversion matrix: quali formati possono convertire in cosa
# Pandoc gestisce tutto; qui segnaliamo limitazioni note
OUTPUT_FORMATS_BY_INPUT = {
"epub": ["epub", "md", "docx", "pdf", "txt", "html", "fb2", "latex"],
"pdf": ["epub", "md", "docx", "txt", "html", "latex"],
"docx": ["epub", "md", "pdf", "txt", "html", "latex"],
"md": ["epub", "docx", "pdf", "txt", "html", "latex"],
"txt": ["epub", "md", "docx", "pdf", "html", "latex"],
"html": ["epub", "md", "docx", "pdf", "txt", "latex"],
"fb2": ["epub", "md", "docx", "pdf", "txt", "html", "latex"],
"mobi": ["epub", "md", "docx", "pdf", "txt", "html"],
"latex": ["epub", "md", "docx", "pdf", "txt", "html"],
}