From fc01f4aa8ab2db92a247641cec4fb45bd0648656 Mon Sep 17 00:00:00 2001 From: yuuki <> Date: Fri, 31 Jan 2025 15:54:26 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AD=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5?= =?UTF-8?q?=E3=81=A8=E3=83=AC=E3=83=BC=E3=83=88=E3=83=AA=E3=83=9F=E3=83=83?= =?UTF-8?q?=E3=83=88=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 18 +++++++++--------- static/script.js | 5 ++++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 0f1018a..b2ae3b3 100644 --- a/app.py +++ b/app.py @@ -166,11 +166,11 @@ async def cors_handler(req: Request, call_next: Callable[[Request], Awaitable[Re @app.get("/api/litey/get") async def api_get(id: str = None): res = JSONResponse(get_litey_notes(id)) - res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0" - res.headers["CDN-Cache-Control"] = f"max-age=0" + res.headers["Cache-Control"] = f"public, max-age=15, s-maxage=15" + res.headers["CDN-Cache-Control"] = f"max-age=15" return res -@app.post("/api/litey/post") +@app.post("/api/litey/post", dependencies=[Depends(RateLimiter(times=4, seconds=3600))]) async def api_post(item: LiteYItem, req: Request): ctx["mongo_client"].litey.notes.insert_one({ "id": str(uuid4()), @@ -206,11 +206,11 @@ async def api_image_proxy(url: str): @app.get("/api/ng/get") async def api_ng_get(): res = PlainTextResponse("\n".join(get_ng_words())) - res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0" - res.headers["CDN-Cache-Control"] = f"max-age=0" + res.headers["Cache-Control"] = f"public, max-age=15, s-maxage=15" + res.headers["CDN-Cache-Control"] = f"max-age=15" return res -@app.post("/api/ng/post") +@app.post("/api/ng/post", dependencies=[Depends(RateLimiter(times=4, seconds=3600))]) async def api_ng_post(item: NGItem): ctx["mongo_client"].litey.ngs.insert_one({ "word": item.word @@ -218,7 +218,7 @@ async def api_ng_post(item: NGItem): return PlainTextResponse("OK") -@app.post("/api/ng/delete") +@app.post("/api/ng/delete", dependencies=[Depends(RateLimiter(times=1, seconds=86400))]) async def api_ng_delete(item: NGItem): ctx["mongo_client"].litey.ngs.delete_one({ "word": item.word @@ -232,8 +232,8 @@ async def home(req: Request): "notes": get_litey_notes(), "ng_words": get_ng_words() }) - res.headers["Cache-Control"] = f"public, max-age=0, s-maxage=0" - res.headers["CDN-Cache-Control"] = f"max-age=0" + res.headers["Cache-Control"] = f"public, max-age=15, s-maxage=15" + res.headers["CDN-Cache-Control"] = f"max-age=15" return res @app.get("/{ref:path}") diff --git a/static/script.js b/static/script.js index 61bd142..2ea0d2a 100644 --- a/static/script.js +++ b/static/script.js @@ -15,7 +15,10 @@ function notePost() { msg.value = ""; alert("投稿に成功しました!"); } else { - alert("投稿に失敗しました。"); + (async () => { + const text = await res.text(); + alert(`投稿に失敗しました。\n${text}`); + })(); } }); }