mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-14 02:20:53 +08:00
@@ -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 && \
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user