Enthält ~18 Commits vom Nextcloud-Mount (FUSE-Blocker verhinderte direkten Push): Excel-Export-Fix, IMAP-Verbesserungen, Scan-Fixes, UI-Updates. Aus Forgejo-Migration squashed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from backend.database import get_db
|
|
from backend.models import Setting
|
|
|
|
router = APIRouter()
|
|
|
|
ALLOWED_KEYS = {
|
|
"IMAP_HOST", "IMAP_PORT", "IMAP_USER", "IMAP_PASSWORD",
|
|
"GMAIL_IMAP_HOST", "GMAIL_IMAP_PORT", "GMAIL_IMAP_USER", "GMAIL_IMAP_PASSWORD",
|
|
"INVOICE_STORAGE_PATH",
|
|
}
|
|
|
|
MASK = "••••••••"
|
|
|
|
|
|
@router.get("/")
|
|
def get_settings(db: Session = Depends(get_db)):
|
|
rows = {r.key: r.value for r in db.query(Setting).filter(Setting.key.in_(ALLOWED_KEYS)).all()}
|
|
return {k: (MASK if "PASSWORD" in k and rows.get(k) else rows.get(k, "")) for k in ALLOWED_KEYS}
|
|
|
|
|
|
@router.post("/")
|
|
def save_settings(data: dict, db: Session = Depends(get_db)):
|
|
for key, value in data.items():
|
|
if key not in ALLOWED_KEYS:
|
|
continue
|
|
if "PASSWORD" in key and value == MASK:
|
|
continue
|
|
existing = db.get(Setting, key)
|
|
if existing:
|
|
existing.value = value
|
|
else:
|
|
db.add(Setting(key=key, value=value))
|
|
db.commit()
|
|
return {"status": "ok"}
|
|
|
|
|
|
def get_imap_config(db: Session) -> dict:
|
|
"""Liest IMAP-Konfiguration aus DB (Fallback auf Env-Vars)."""
|
|
import os
|
|
rows = {r.key: r.value for r in db.query(Setting).filter(Setting.key.in_(ALLOWED_KEYS)).all()}
|
|
def val(key, default=""):
|
|
return rows.get(key) or os.getenv(key, default)
|
|
return {
|
|
"host": val("IMAP_HOST", "imap.strato.de"),
|
|
"port": int(val("IMAP_PORT", "993")),
|
|
"user": val("IMAP_USER"),
|
|
"password": val("IMAP_PASSWORD"),
|
|
"storage_path": val("INVOICE_STORAGE_PATH", "/tmp/invoice-storage"),
|
|
}
|