From ffdb72ed3d28d90c179bae6c0582af50a5afc959 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 4 Oct 2023 10:49:45 +0800 Subject: [PATCH 1/2] fix: add aio-http for alpine. --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 9d66f04d..50925212 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,11 @@ RUN set -ex && \ python3 \ py3-bcrypt \ py3-pip \ + py3-aiohttp \ su-exec \ shadow \ tini \ + openssl \ tzdata && \ python3 -m pip install --no-cache-dir --upgrade pip && \ sed -i '/bcrypt/d' requirements.txt && \ From edcbdc3dd3a216e6435a675a257a761840416117 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 4 Oct 2023 10:50:05 +0800 Subject: [PATCH 2/2] fix: remove reverse proxy option. --- backend/src/main.py | 37 --------------- backend/src/module/api/proxy.py | 84 --------------------------------- 2 files changed, 121 deletions(-) delete mode 100644 backend/src/module/api/proxy.py diff --git a/backend/src/main.py b/backend/src/main.py index d4df1c47..987b5589 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -7,7 +7,6 @@ from fastapi.responses import FileResponse, HTMLResponse, RedirectResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from module.api import v1 -from module.api.proxy import router as proxy_router from module.conf import VERSION, settings, setup_logger setup_logger(reset=True) @@ -32,7 +31,6 @@ def create_app() -> FastAPI: # mount routers app.include_router(v1, prefix="/api") - app.include_router(proxy_router) return app @@ -46,31 +44,6 @@ if VERSION != "DEV_VERSION": # app.mount("/icons", StaticFiles(directory="dist/icons"), name="icons") templates = Jinja2Templates(directory="dist") - # Resource - # @app.get("/favicon.svg", tags=["html"]) - # def favicon(): - # return FileResponse("dist/favicon.svg") - # - # @app.get("/AutoBangumi.svg", tags=["html"]) - # def logo(): - # return FileResponse("dist/AutoBangumi.svg") - # - # @app.get("/favicon-light.svg", tags=["html"]) - # def favicon_light(): - # return FileResponse("dist/favicon-light.svg") - # - # @app.get("/robots.txt", tags=["html"]) - # def robots(): - # return FileResponse("dist/robots.txt") - # - # @app.get("/manifest.webmanifest", tags=["html"]) - # def manifest(): - # return FileResponse("dist/manifest.webmanifest") - # - # @app.get("/sw.js", tags=["html"]) - # def sw(): - # return FileResponse("dist/sw.js") - @app.get("/{path:path}") def html(request: Request, path: str): files = os.listdir("dist") @@ -79,17 +52,7 @@ if VERSION != "DEV_VERSION": else: context = {"request": request} return templates.TemplateResponse("index.html", context) - - # HTML Response - # @app.get("/{path:path}", response_class=HTMLResponse, tags=["html"]) - # def index(request: Request, path: str): - # print(request) - # print(path) - # context = {"request": request} - # return templates.TemplateResponse("index.html", context) - else: - @app.get("/", status_code=302, tags=["html"]) def index(): return RedirectResponse("/docs") diff --git a/backend/src/module/api/proxy.py b/backend/src/module/api/proxy.py deleted file mode 100644 index 2b50cbdf..00000000 --- a/backend/src/module/api/proxy.py +++ /dev/null @@ -1,84 +0,0 @@ -import logging -import re - -from fastapi import APIRouter -from fastapi.exceptions import HTTPException -from fastapi.responses import Response - -from module.conf import settings -from module.network import RequestContent - -router = APIRouter() - -logger = logging.getLogger(__name__) - - -def get_rss_content(full_path): - url = f"https://mikanani.me/RSS/{full_path}" - custom_url = settings.rss_parser.custom_url - if "://" not in custom_url: - custom_url = f"https://{custom_url}" - try: - with RequestContent() as request: - content = request.get_html(url) - return re.sub(r"https://mikanani.me", custom_url, content) - except Exception as e: - logger.debug(e) - logger.warning("Failed to get RSS content") - raise HTTPException(status_code=500, detail="Failed to get RSS content") - - -def get_torrent(full_path): - url = f"https://mikanani.me/Download/{full_path}" - try: - with RequestContent() as request: - return request.get_content(url) - except Exception as e: - logger.debug(e) - logger.warning("Failed to get torrent") - raise HTTPException(status_code=500, detail="Failed to get torrent") - - -@router.get("/RSS/MyBangumi", tags=["proxy"]) -async def get_my_bangumi(token: str): - full_path = "MyBangumi?token=" + token - content = get_rss_content(full_path) - return Response(content, media_type="application/xml") - - -@router.get("/RSS/Search", tags=["proxy"]) -async def get_search_result(searchstr: str): - full_path = "Search?searchstr=" + searchstr - content = get_rss_content(full_path) - return Response(content, media_type="application/xml") - - -@router.get("/RSS/Bangumi", tags=["proxy"]) -async def get_bangumi(bangumiId: str, subgroupid: str): - full_path = "Bangumi?bangumiId=" + bangumiId + "&subgroupid=" + subgroupid - content = get_rss_content(full_path) - return Response(content, media_type="application/xml") - - -@router.get("/RSS/{full_path:path}", tags=["proxy"]) -async def get_rss(full_path: str): - content = get_rss_content(full_path) - return Response(content, media_type="application/xml") - - -@router.get("/Download/{full_path:path}", tags=["proxy"]) -async def download(full_path: str): - torrent = get_torrent(full_path) - return Response(torrent, media_type="application/x-bittorrent") - - -@router.get("/Home/Episode/{full_path:path}", tags=["proxy"]) -async def get_ep_info(full_path: str): - url = f"https://mikanani.me/Home/Episode/{full_path}" - try: - with RequestContent() as request: - return Response(request.get_html(url), media_type="text/html") - except Exception as e: - logger.debug(e) - logger.warning("Failed to get ep info") - raise HTTPException(status_code=500, detail="Failed to get ep info")