Files
bookish-fork-dokerized/config.py
T
truetype 0f15b7958f feat: self-hosted frontend JS (offline) + docker hardening
- Vendored epub.js/pdf.js+worker/JSZip/DOMPurify in static/vendor/
- reader.html/reader.js servono i JS da /static (niente CDN, offline-ready)
- CSP: rimosse allowlist CDN, aggiunto worker-src 'self' blob:
- Test CSP aggiornati; tutti 16 verdi; verificato smoke test offline in container
2026-08-29 22:32:10 +02:00

56 lines
2.5 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"))
# 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"],
}