From 8df84b165fce0cf9fc503c5172f171561f3ffe23 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 26 May 2023 23:47:16 +0800 Subject: [PATCH] feat: support bbs oss proxy --- .gitignore | 2 +- main.py | 31 +++++++++++++++++++++++++++++++ requirements.txt | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 68bc17f..2dc53ca 100644 --- a/.gitignore +++ b/.gitignore @@ -157,4 +157,4 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +.idea/ diff --git a/main.py b/main.py new file mode 100644 index 0000000..8a36629 --- /dev/null +++ b/main.py @@ -0,0 +1,31 @@ +from fastapi import FastAPI +from httpx import AsyncClient +from starlette.requests import Request +from starlette.responses import Response + +app = FastAPI() +client = AsyncClient( + timeout=60.0, +) + + +@app.get('/upload/{file_path:path}') +async def proxy_cve_search_api(req: Request, file_path: str) -> Response: + headers = {} + for i in req.headers.items(): + headers[i[0]] = i[1] + headers["host"] = "upload-bbs.miyoushe.com" + resp = await client.get( + f'https://upload-bbs.miyoushe.com/upload/{file_path}', + params=req.query_params, + headers=headers, + follow_redirects=True, + ) + content = resp.content + return Response(content=content, status_code=resp.status_code, headers=dict(resp.headers)) + + +if __name__ == '__main__': + import uvicorn + + uvicorn.run(app, host="0.0.0.0", port=5677) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..31beee3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +httpx==0.24.1 +fastapi~=0.95.2 +starlette~=0.27.0 +uvicorn~=0.22.0