"""运行时只读配置接口。 向前端暴露由后端 ``.env`` / 启动器决定的非敏感配置项, 让前端可以根据后端策略切换实现(如 PDF 预览引擎), 而不必把每个环境变量都硬编码进打包产物。 """ from __future__ import annotations from flask import current_app from dms.api.v1.blueprint import api_v1 from dms.common.response import success_response @api_v1.get("/config/runtime") def get_runtime_config(): pdf_viewer_engine = current_app.config.get( "DMS_PDF_VIEWER_ENGINE", "iframe" ) if pdf_viewer_engine not in {"iframe", "pdfjs"}: pdf_viewer_engine = "iframe" response, status = success_response( {"pdfViewerEngine": pdf_viewer_engine} ) # 该接口仅暴露非敏感开关,允许浏览器缓存以减少首屏请求。 response.headers["Cache-Control"] = "public, max-age=60" return response, status