mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-10 17:43:23 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -44,6 +44,7 @@ CREATE_IMAGE_MODEL=imagen-3.0-generate-002
|
||||
UPLOAD_PROVIDER=smms
|
||||
SMMS_SECRET_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
PICGO_API_KEY=xxxx
|
||||
PICGO_API_URL=https://www.picgo.net/api/1/upload
|
||||
CLOUDFLARE_IMGBED_URL=https://xxxxxxx.pages.dev/upload
|
||||
CLOUDFLARE_IMGBED_AUTH_CODE=xxxxxxxxx
|
||||
CLOUDFLARE_IMGBED_UPLOAD_FOLDER=
|
||||
|
||||
@@ -220,6 +220,7 @@ This endpoint is directly forwarded to official OpenAI Compatible API format end
|
||||
| `UPLOAD_PROVIDER` | Image upload provider: `smms`, `picgo`, `cloudflare_imgbed` | `smms` |
|
||||
| `SMMS_SECRET_TOKEN` | SM.MS API Token | `your-smms-token` |
|
||||
| `PICGO_API_KEY` | PicoGo API Key | `your-picogo-apikey` |
|
||||
| `PICGO_API_URL` | PicoGo API Server URL | `https://www.picgo.net/api/1/upload` |
|
||||
| `CLOUDFLARE_IMGBED_URL` | CloudFlare ImgBed upload URL | `https://xxxxxxx.pages.dev/upload` |
|
||||
| `CLOUDFLARE_IMGBED_AUTH_CODE`| CloudFlare ImgBed auth key | `your-cloudflare-imgber-auth-code` |
|
||||
| `CLOUDFLARE_IMGBED_UPLOAD_FOLDER`| CloudFlare ImgBed upload folder | `""` |
|
||||
|
||||
@@ -220,6 +220,7 @@ app/
|
||||
| `UPLOAD_PROVIDER` | 图片上传提供商: `smms`, `picgo`, `cloudflare_imgbed` | `smms` |
|
||||
| `SMMS_SECRET_TOKEN` | SM.MS图床的API Token | `your-smms-token` |
|
||||
| `PICGO_API_KEY` | [PicoGo](https://www.picgo.net/)图床的API Key | `your-picogo-apikey` |
|
||||
| `PICGO_API_URL` | [PicoGo](https://www.picgo.net/)图床的API服务器地址 | `https://www.picgo.net/api/1/upload` |
|
||||
| `CLOUDFLARE_IMGBED_URL` | [CloudFlare](https://github.com/MarSeventh/CloudFlare-ImgBed) 图床上传地址 | `https://xxxxxxx.pages.dev/upload` |
|
||||
| `CLOUDFLARE_IMGBED_AUTH_CODE`| CloudFlare图床的鉴权key | `your-cloudflare-imgber-auth-code` |
|
||||
| `CLOUDFLARE_IMGBED_UPLOAD_FOLDER`| CloudFlare图床的上传文件夹路径 | `""` |
|
||||
|
||||
@@ -94,6 +94,7 @@ class Settings(BaseSettings):
|
||||
UPLOAD_PROVIDER: str = "smms"
|
||||
SMMS_SECRET_TOKEN: str = ""
|
||||
PICGO_API_KEY: str = ""
|
||||
PICGO_API_URL: str = "https://www.picgo.net/api/1/upload"
|
||||
CLOUDFLARE_IMGBED_URL: str = ""
|
||||
CLOUDFLARE_IMGBED_AUTH_CODE: str = ""
|
||||
CLOUDFLARE_IMGBED_UPLOAD_FOLDER: str = ""
|
||||
|
||||
@@ -293,7 +293,9 @@ def _extract_image_data(part: dict) -> str:
|
||||
)
|
||||
elif settings.UPLOAD_PROVIDER == "picgo":
|
||||
image_uploader = ImageUploaderFactory.create(
|
||||
provider=settings.UPLOAD_PROVIDER, api_key=settings.PICGO_API_KEY
|
||||
provider=settings.UPLOAD_PROVIDER,
|
||||
api_key=settings.PICGO_API_KEY,
|
||||
api_url=settings.PICGO_API_URL
|
||||
)
|
||||
elif settings.UPLOAD_PROVIDER == "cloudflare_imgbed":
|
||||
image_uploader = ImageUploaderFactory.create(
|
||||
|
||||
@@ -122,6 +122,7 @@ class ImageCreateService:
|
||||
image_uploader = ImageUploaderFactory.create(
|
||||
provider=settings.UPLOAD_PROVIDER,
|
||||
api_key=settings.PICGO_API_KEY,
|
||||
api_url=settings.PICGO_API_URL,
|
||||
)
|
||||
elif settings.UPLOAD_PROVIDER == "cloudflare_imgbed":
|
||||
image_uploader = ImageUploaderFactory.create(
|
||||
|
||||
@@ -1836,6 +1836,23 @@ endblock %} {% block head_extra_styles %}
|
||||
<small class="text-gray-500 mt-1 block">SM.MS图床的密钥</small>
|
||||
</div>
|
||||
|
||||
<!-- PicGo API URL -->
|
||||
<div class="mb-6 provider-config" data-provider="picgo">
|
||||
<label
|
||||
for="PICGO_API_URL"
|
||||
class="block font-semibold mb-2 text-gray-700"
|
||||
>PicGo API地址</label
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
id="PICGO_API_URL"
|
||||
name="PICGO_API_URL"
|
||||
placeholder="https://www.picgo.net/api/1/upload"
|
||||
class="w-full px-4 py-3 rounded-lg form-input-themed"
|
||||
/>
|
||||
<small class="text-gray-500 mt-1 block">PicGo服务器的API地址,默认为 https://www.picgo.net/api/1/upload</small>
|
||||
</div>
|
||||
|
||||
<!-- PicGo API密钥 -->
|
||||
<div class="mb-6 provider-config" data-provider="picgo">
|
||||
<label
|
||||
|
||||
@@ -185,9 +185,22 @@ class PicGoUploader(ImageUploader):
|
||||
"""
|
||||
try:
|
||||
# 准备请求头
|
||||
headers = {
|
||||
"X-API-Key": self.api_key
|
||||
}
|
||||
headers = {}
|
||||
|
||||
# 构建请求URL
|
||||
request_url = self.api_url
|
||||
|
||||
# 判断是否为默认PicGo URL,如果是则使用header认证,否则使用URL参数认证
|
||||
if self.api_url == "https://www.picgo.net/api/1/upload":
|
||||
headers["X-API-Key"] = self.api_key
|
||||
else:
|
||||
# 对于自定义URL,将API key作为查询参数添加到URL中
|
||||
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode
|
||||
parsed_url = urlparse(request_url)
|
||||
query_params = parse_qs(parsed_url.query)
|
||||
query_params["key"] = self.api_key
|
||||
new_query = urlencode(query_params, doseq=True)
|
||||
request_url = urlunparse(parsed_url._replace(query=new_query))
|
||||
|
||||
# 准备文件数据
|
||||
files = {
|
||||
@@ -196,7 +209,7 @@ class PicGoUploader(ImageUploader):
|
||||
|
||||
# 发送请求
|
||||
response = requests.post(
|
||||
self.api_url,
|
||||
request_url,
|
||||
headers=headers,
|
||||
files=files
|
||||
)
|
||||
@@ -207,6 +220,34 @@ class PicGoUploader(ImageUploader):
|
||||
# 解析响应
|
||||
result = response.json()
|
||||
|
||||
# 处理自定义PicGo服务器的响应格式
|
||||
if "success" in result and "result" in result:
|
||||
# 自定义PicGo服务器格式: {"success": true, "result": ["url"]}
|
||||
if result["success"]:
|
||||
image_url = result["result"][0] if result["result"] and len(result["result"]) > 0 else ""
|
||||
image_metadata = ImageMetadata(
|
||||
width=0,
|
||||
height=0,
|
||||
filename=filename,
|
||||
size=0,
|
||||
url=image_url,
|
||||
delete_url=None
|
||||
)
|
||||
return UploadResponse(
|
||||
success=True,
|
||||
code="success",
|
||||
message="Upload success",
|
||||
data=image_metadata
|
||||
)
|
||||
else:
|
||||
raise UploadError(
|
||||
message="Upload failed",
|
||||
error_type=UploadErrorType.SERVER_ERROR,
|
||||
status_code=400,
|
||||
details=result
|
||||
)
|
||||
|
||||
# 处理官方PicGo服务器的响应格式
|
||||
# 验证上传是否成功
|
||||
if result.get("status_code") != 200:
|
||||
error_message = "Upload failed"
|
||||
@@ -580,7 +621,7 @@ class ImageUploaderFactory:
|
||||
credentials["secret_key"]
|
||||
)
|
||||
elif provider == "picgo":
|
||||
api_url = credentials.get("api_url", "https://www.picgo.net/api/1/upload")
|
||||
api_url = credentials.get("api_url") or "https://www.picgo.net/api/1/upload"
|
||||
return PicGoUploader(credentials["api_key"], api_url)
|
||||
elif provider == "cloudflare_imgbed":
|
||||
return CloudFlareImgBedUploader(
|
||||
|
||||
Reference in New Issue
Block a user