Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request, Query, Path
|
2 |
+
from fastapi.responses import StreamingResponse, HTMLResponse
|
3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
4 |
+
import httpx
|
5 |
+
import base64
|
6 |
+
import io
|
7 |
+
|
8 |
+
app = FastAPI(docs_url=None, redoc_url=None)
|
9 |
+
# app = FastAPI(title='Jable&Javdb的API',description='Jable&Javdb最近更新的API', redoc_url=None)
|
10 |
+
|
11 |
+
app.add_middleware(
|
12 |
+
CORSMiddleware,
|
13 |
+
allow_origins=["*"],
|
14 |
+
allow_credentials=True,
|
15 |
+
allow_methods=["*"],
|
16 |
+
allow_headers=["*"],
|
17 |
+
)
|
18 |
+
|
19 |
+
# 图片API开始
|
20 |
+
@app.get("/img/{img_base64}", summary="图片显示", tags=["image"])
|
21 |
+
async def img(img_base64: str = Path(..., description="图片远程UR的base64加密代码")):
|
22 |
+
"""
|
23 |
+
显示远程地址的图片:
|
24 |
+
|
25 |
+
- **img_base64**: 图片远程UR的base64加密代码
|
26 |
+
"""
|
27 |
+
img_url = base64.b64decode(img_base64).decode()
|
28 |
+
r = httpx.get(img_url)
|
29 |
+
return StreamingResponse(io.BytesIO(r.content), media_type="image/png")
|