refactor: split 8081 app sources from served assets
This commit is contained in:
@@ -45,8 +45,8 @@ INCOMING_FILES_DIR = BASE_DIR / "incoming-files"
|
||||
INCOMING_SERVED_DIR = INCOMING_FILES_DIR / "served"
|
||||
INCOMING_REFERENCE_DIR = INCOMING_FILES_DIR / "reference"
|
||||
BUSINESS_DASHBOARD_DIR = INCOMING_FILES_DIR / "사업관리대장"
|
||||
BUSINESS_DASHBOARD_WRAPPER_PATH = BUSINESS_DASHBOARD_DIR / "MH 통합 대시보드_260320.html"
|
||||
BUSINESS_DASHBOARD_THEME_CSS = BUSINESS_DASHBOARD_DIR / "MH 통합 대시보드_260320.css"
|
||||
BUSINESS_LEDGER_SERVED_DIR = INCOMING_SERVED_DIR / "ledger"
|
||||
BUSINESS_LEDGER_INDEX_PATH = BUSINESS_LEDGER_SERVED_DIR / "index.html"
|
||||
FIXED_OFFICE_SOURCE_KEY = "technical-development-center"
|
||||
FIXED_OFFICE_CONFIGS = {
|
||||
"technical-development-center": {
|
||||
@@ -66,7 +66,6 @@ FIXED_OFFICE_CONFIGS = {
|
||||
},
|
||||
}
|
||||
_fixed_office_cache: dict[str, dict[str, object]] = {}
|
||||
_business_ledger_html_cache: str | None = None
|
||||
BUSINESS_LEDGER_DEFAULT_SOURCE_KEY = "business_ledger_default"
|
||||
AUTH_DEFAULT_PASSWORD = "1111"
|
||||
AUTH_PASSWORD_ITERATIONS = 390000
|
||||
@@ -89,34 +88,9 @@ MH_HEADER_ORDER = [
|
||||
"사업 종류", "연장근무 프로젝트 코드", "연장근무 프로젝트명", "연장근무 서브코드", "연장근무 시간(실제)", "연장근무 시간(가공)"
|
||||
]
|
||||
|
||||
|
||||
def build_business_ledger_html() -> str:
|
||||
global _business_ledger_html_cache
|
||||
if _business_ledger_html_cache is not None:
|
||||
return _business_ledger_html_cache
|
||||
if not BUSINESS_DASHBOARD_WRAPPER_PATH.exists():
|
||||
raise FileNotFoundError("Business dashboard wrapper file not found.")
|
||||
source = BUSINESS_DASHBOARD_WRAPPER_PATH.read_text(encoding="utf-8-sig")
|
||||
match = re.search(r"const BUSINESS_HTML_B64='([^']+)';", source)
|
||||
if not match:
|
||||
raise ValueError("Embedded business ledger source was not found.")
|
||||
decoded = base64.b64decode(match.group(1)).decode("utf-8")
|
||||
head_injection = (
|
||||
'<base href="/integrations/ledger-assets/">'
|
||||
'<link rel="stylesheet" href="/integrations/ledger-assets/MH%20통합%20대시보드_260320.css">'
|
||||
'<link rel="stylesheet" href="/integrations/ledger-assets/ledger-override.css?v=20260401-03">'
|
||||
)
|
||||
html = decoded.replace("</head>", f"{head_injection}</head>", 1)
|
||||
html = html.replace("<body>", '<body class="mh-business-theme">', 1)
|
||||
html = html.replace("</body>", '<script src="/integrations/ledger-assets/ledger-override.js?v=20260401-03"></script></body>', 1)
|
||||
_business_ledger_html_cache = html
|
||||
return html
|
||||
|
||||
|
||||
def sync_default_business_ledger_source(cur) -> None:
|
||||
if not BUSINESS_DASHBOARD_DIR.exists():
|
||||
return
|
||||
candidates = [
|
||||
BUSINESS_LEDGER_SERVED_DIR / "사업관리대장-1.xlsx",
|
||||
BUSINESS_DASHBOARD_DIR / "사업관리대장-1.xlsx",
|
||||
BUSINESS_DASHBOARD_DIR / "사업관리 대장-1.xlsx",
|
||||
BUSINESS_DASHBOARD_DIR / "사업관리대장.xlsx",
|
||||
@@ -165,7 +139,7 @@ def sync_default_business_ledger_source(cur) -> None:
|
||||
|
||||
app.mount(
|
||||
"/integrations/ledger-assets",
|
||||
StaticFiles(directory=str(BUSINESS_DASHBOARD_DIR), check_dir=False),
|
||||
StaticFiles(directory=str(BUSINESS_LEDGER_SERVED_DIR), check_dir=False),
|
||||
name="integration-ledger-assets",
|
||||
)
|
||||
|
||||
@@ -4627,20 +4601,16 @@ def integration_payment() -> FileResponse:
|
||||
|
||||
|
||||
@app.get("/integrations/ledger")
|
||||
def integration_ledger() -> HTMLResponse:
|
||||
try:
|
||||
html = build_business_ledger_html()
|
||||
except FileNotFoundError:
|
||||
def integration_ledger() -> FileResponse:
|
||||
# #21 phase-1: runtime no longer decodes reference wrapper HTML. Serve the promoted
|
||||
# ledger entry file from incoming-files/served/ledger only.
|
||||
target = BUSINESS_LEDGER_INDEX_PATH
|
||||
if not target.exists():
|
||||
raise HTTPException(status_code=404, detail="Business ledger integration file not found.")
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=500, detail="Business ledger integration source is invalid.")
|
||||
return HTMLResponse(
|
||||
html,
|
||||
headers={
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
|
||||
"Pragma": "no-cache",
|
||||
},
|
||||
)
|
||||
response = FileResponse(target)
|
||||
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
|
||||
response.headers["Pragma"] = "no-cache"
|
||||
return response
|
||||
|
||||
|
||||
@app.get("/integrations/mh")
|
||||
|
||||
Reference in New Issue
Block a user