From 06550e28e3a3cf6523cf2ee914c2721b19005dd9 Mon Sep 17 00:00:00 2001 From: yuuki <> Date: Thu, 27 Jun 2024 01:41:35 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=8F=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index a578259..c35c257 100644 --- a/app.py +++ b/app.py @@ -59,9 +59,15 @@ async def cloudflare(zone_id: str, x_token: Union[str, None] = Header()): }) ) - res = JSONResponse(result.json()) - res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60" - res.headers["CDN-Cache-Control"] = f"max-age=60" + json = result.json() + res = JSONResponse(json) + if "success" in json and not json["success"]: + res.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR + res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0" + res.headers["CDN-Cache-Control"] = f"max-age=0" + else: + res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60" + res.headers["CDN-Cache-Control"] = f"max-age=60" return res @app.get("/api/cloudflare2") @@ -89,9 +95,15 @@ async def cloudflare2(zone_id: str, x_token: Union[str, None] = Header()): }) ) - res = JSONResponse(result.json()) - res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60" - res.headers["CDN-Cache-Control"] = f"max-age=60" + json = result.json() + res = JSONResponse(json) + if "success" in json and not json["success"]: + res.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR + res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0" + res.headers["CDN-Cache-Control"] = f"max-age=0" + else: + res.headers["Cache-Control"] = f"public, max-age=60, s-maxage=60" + res.headers["CDN-Cache-Control"] = f"max-age=60" return res @app.get("/")