Upload app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,7 @@ from urllib.parse import unquote, quote
|
|
| 23 |
import jieba
|
| 24 |
import aiohttp
|
| 25 |
from fastapi import FastAPI, Query
|
| 26 |
-
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
|
| 27 |
from fastapi.staticfiles import StaticFiles
|
| 28 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 29 |
from pydantic import BaseModel
|
|
@@ -629,6 +629,22 @@ if not txt_dir.exists():
|
|
| 629 |
txt_dir.mkdir(parents=True, exist_ok=True)
|
| 630 |
app.mount("/txt", StaticFiles(directory="txt"), name="txt")
|
| 631 |
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
|
| 633 |
@app.get("/{rest_of_path:path}")
|
| 634 |
async def serve_spa(rest_of_path: str):
|
|
|
|
| 23 |
import jieba
|
| 24 |
import aiohttp
|
| 25 |
from fastapi import FastAPI, Query
|
| 26 |
+
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, PlainTextResponse, StreamingResponse
|
| 27 |
from fastapi.staticfiles import StaticFiles
|
| 28 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 29 |
from pydantic import BaseModel
|
|
|
|
| 629 |
txt_dir.mkdir(parents=True, exist_ok=True)
|
| 630 |
app.mount("/txt", StaticFiles(directory="txt"), name="txt")
|
| 631 |
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
|
| 632 |
+
app.mount("/icons", StaticFiles(directory="static/icons"), name="icons")
|
| 633 |
+
|
| 634 |
+
# ββ PWA files at root βββββββββββββββββββββββββββββββββ
|
| 635 |
+
@app.get("/manifest.json")
|
| 636 |
+
def serve_manifest():
|
| 637 |
+
p = Path("static/manifest.json")
|
| 638 |
+
if p.exists():
|
| 639 |
+
return JSONResponse(json.loads(p.read_text(encoding="utf-8")))
|
| 640 |
+
return JSONResponse({"error": "manifest not found"}, status_code=404)
|
| 641 |
+
|
| 642 |
+
@app.get("/sw.js")
|
| 643 |
+
def serve_sw():
|
| 644 |
+
p = Path("static/sw.js")
|
| 645 |
+
if p.exists():
|
| 646 |
+
return PlainTextResponse(p.read_text(encoding="utf-8"), media_type="application/javascript")
|
| 647 |
+
return PlainTextResponse("", status_code=404)
|
| 648 |
|
| 649 |
@app.get("/{rest_of_path:path}")
|
| 650 |
async def serve_spa(rest_of_path: str):
|