Spaces:
Running
Running
Upload 2 files
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# ⚙️ 后端逻辑/核心服务端.py (Hugging Face Spaces app.py)
|
| 2 |
from fastapi import FastAPI, File, UploadFile, Form, Depends, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
-
from fastapi.responses import Response, JSONResponse, FileResponse
|
| 5 |
from sqlalchemy.orm import Session
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from huggingface_hub import hf_hub_download, HfApi
|
|
@@ -10,7 +10,7 @@ import urllib.parse
|
|
| 10 |
import urllib.request
|
| 11 |
import urllib.error
|
| 12 |
import os
|
| 13 |
-
import mimetypes
|
| 14 |
import 数据库连接 as db
|
| 15 |
|
| 16 |
from router_users import router as users_router
|
|
@@ -50,7 +50,7 @@ app.include_router(wallet_router)
|
|
| 50 |
app.include_router(proxy_router)
|
| 51 |
|
| 52 |
# ==========================================
|
| 53 |
-
# 🟢
|
| 54 |
# 解决 Private 仓库下,本地客户端报 401 Unauthorized 的终极方案
|
| 55 |
# ==========================================
|
| 56 |
@app.get("/api/image_proxy")
|
|
@@ -97,7 +97,7 @@ def proxy_hf_image(url: str = None, path: str = None):
|
|
| 97 |
def upload_file(file: UploadFile = File(...), file_type: str = Form(...)):
|
| 98 |
content = file.file.read()
|
| 99 |
|
| 100 |
-
# 动态文件大小风控
|
| 101 |
max_size = 10 * 1024 * 1024
|
| 102 |
if file_type == "avatar":
|
| 103 |
max_size = 2 * 1024 * 1024
|
|
|
|
| 1 |
# ⚙️ 后端逻辑/核心服务端.py (Hugging Face Spaces app.py)
|
| 2 |
from fastapi import FastAPI, File, UploadFile, Form, Depends, HTTPException
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
from fastapi.responses import Response, JSONResponse, FileResponse
|
| 5 |
from sqlalchemy.orm import Session
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from huggingface_hub import hf_hub_download, HfApi
|
|
|
|
| 10 |
import urllib.request
|
| 11 |
import urllib.error
|
| 12 |
import os
|
| 13 |
+
import mimetypes
|
| 14 |
import 数据库连接 as db
|
| 15 |
|
| 16 |
from router_users import router as users_router
|
|
|
|
| 50 |
app.include_router(proxy_router)
|
| 51 |
|
| 52 |
# ==========================================
|
| 53 |
+
# 🟢 私有图床代理中心 (Image Proxy)
|
| 54 |
# 解决 Private 仓库下,本地客户端报 401 Unauthorized 的终极方案
|
| 55 |
# ==========================================
|
| 56 |
@app.get("/api/image_proxy")
|
|
|
|
| 97 |
def upload_file(file: UploadFile = File(...), file_type: str = Form(...)):
|
| 98 |
content = file.file.read()
|
| 99 |
|
| 100 |
+
# 🟢 动态文件大小风控
|
| 101 |
max_size = 10 * 1024 * 1024
|
| 102 |
if file_type == "avatar":
|
| 103 |
max_size = 2 * 1024 * 1024
|
models.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# models.py
|
| 2 |
from pydantic import BaseModel
|
| 3 |
-
from typing import Optional
|
| 4 |
|
| 5 |
class SendCodeRequest(BaseModel):
|
| 6 |
contact: str
|
|
@@ -57,6 +57,7 @@ class ItemCreate(BaseModel):
|
|
| 57 |
fullDesc: str
|
| 58 |
link: str
|
| 59 |
coverUrl: Optional[str] = None
|
|
|
|
| 60 |
author: str
|
| 61 |
price: int = 0
|
| 62 |
github_token: Optional[str] = None
|
|
@@ -67,6 +68,7 @@ class ItemUpdate(BaseModel):
|
|
| 67 |
fullDesc: Optional[str] = None
|
| 68 |
link: Optional[str] = None
|
| 69 |
coverUrl: Optional[str] = None
|
|
|
|
| 70 |
price: Optional[int] = None
|
| 71 |
github_token: Optional[str] = None
|
| 72 |
|
|
|
|
| 1 |
# models.py
|
| 2 |
from pydantic import BaseModel
|
| 3 |
+
from typing import Optional, List
|
| 4 |
|
| 5 |
class SendCodeRequest(BaseModel):
|
| 6 |
contact: str
|
|
|
|
| 57 |
fullDesc: str
|
| 58 |
link: str
|
| 59 |
coverUrl: Optional[str] = None
|
| 60 |
+
imageUrls: Optional[List[str]] = [] # 🟢 新增:支持多图展示画廊
|
| 61 |
author: str
|
| 62 |
price: int = 0
|
| 63 |
github_token: Optional[str] = None
|
|
|
|
| 68 |
fullDesc: Optional[str] = None
|
| 69 |
link: Optional[str] = None
|
| 70 |
coverUrl: Optional[str] = None
|
| 71 |
+
imageUrls: Optional[List[str]] = [] # 🟢 新增:支持多图展示画廊
|
| 72 |
price: Optional[int] = None
|
| 73 |
github_token: Optional[str] = None
|
| 74 |
|