Compare commits
2 Commits
a092cdfb4c
...
1b7fcd603c
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b7fcd603c | |||
| 1ab7d94660 |
@ -66,3 +66,7 @@ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlDx4KdOtOQE+tBq6jHKKFenRaRe2gbBnleBk
|
|||||||
# 开发模式配置
|
# 开发模式配置
|
||||||
DEV_MODE = False # True=开发模式(固定验证码),False=生产模式(真实短信)
|
DEV_MODE = False # True=开发模式(固定验证码),False=生产模式(真实短信)
|
||||||
DEV_SMS_CODE = "888888" # 开发模式下的固定验证码
|
DEV_SMS_CODE = "888888" # 开发模式下的固定验证码
|
||||||
|
|
||||||
|
# Proxy Config
|
||||||
|
USE_PROXY = True # 是否开启代理
|
||||||
|
PROXY_URL = "https://nas.4x4g.com:10011/api/tool/proxy/?url="
|
||||||
|
|||||||
@ -6,6 +6,7 @@ from urllib.parse import quote
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
from config import Config
|
from config import Config
|
||||||
from extensions import s3_client
|
from extensions import s3_client
|
||||||
|
from utils import get_proxied_url
|
||||||
|
|
||||||
def handle_file_uploads(files):
|
def handle_file_uploads(files):
|
||||||
"""处理文件上传到 MinIO"""
|
"""处理文件上传到 MinIO"""
|
||||||
@ -22,7 +23,7 @@ def handle_file_uploads(files):
|
|||||||
|
|
||||||
def get_remote_file_stream(url):
|
def get_remote_file_stream(url):
|
||||||
"""获取远程文件的流"""
|
"""获取远程文件的流"""
|
||||||
req = requests.get(url, stream=True, timeout=60)
|
req = requests.get(get_proxied_url(url), stream=True, timeout=60)
|
||||||
req.raise_for_status()
|
req.raise_for_status()
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
import threading
|
import threading
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
from utils import get_proxied_url
|
||||||
|
|
||||||
def get_model_cost(model_value, is_video=False):
|
def get_model_cost(model_value, is_video=False):
|
||||||
"""获取模型消耗积分"""
|
"""获取模型消耗积分"""
|
||||||
@ -88,7 +89,7 @@ def handle_chat_generation_sync(user_id, api_key, model_value, prompt, use_trial
|
|||||||
"messages": [{"role": "user", "content": prompt}]
|
"messages": [{"role": "user", "content": prompt}]
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
resp = requests.post(Config.CHAT_API, json=chat_payload, headers=headers, timeout=120)
|
resp = requests.post(get_proxied_url(Config.CHAT_API), json=chat_payload, headers=headers, timeout=120)
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
if use_trial:
|
if use_trial:
|
||||||
refund_points(user_id, cost)
|
refund_points(user_id, cost)
|
||||||
|
|||||||
@ -13,6 +13,7 @@ from extensions import s3_client, redis_client, db
|
|||||||
from models import GenerationRecord, User
|
from models import GenerationRecord, User
|
||||||
from config import Config
|
from config import Config
|
||||||
from services.logger import system_logger
|
from services.logger import system_logger
|
||||||
|
from utils import get_proxied_url
|
||||||
|
|
||||||
def sync_images_background(app, record_id, raw_urls):
|
def sync_images_background(app, record_id, raw_urls):
|
||||||
"""后台同步图片至 MinIO,并生成缩略图,带重试机制"""
|
"""后台同步图片至 MinIO,并生成缩略图,带重试机制"""
|
||||||
@ -22,7 +23,7 @@ def sync_images_background(app, record_id, raw_urls):
|
|||||||
success = False
|
success = False
|
||||||
for attempt in range(3): # 3 次重试机制
|
for attempt in range(3): # 3 次重试机制
|
||||||
try:
|
try:
|
||||||
img_resp = requests.get(raw_url, timeout=30)
|
img_resp = requests.get(get_proxied_url(raw_url), timeout=30)
|
||||||
if img_resp.status_code == 200:
|
if img_resp.status_code == 200:
|
||||||
content = img_resp.content
|
content = img_resp.content
|
||||||
ext = ".png"
|
ext = ".png"
|
||||||
@ -98,7 +99,7 @@ def process_image_generation(app, user_id, task_id, payload, api_key, target_api
|
|||||||
try:
|
try:
|
||||||
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
||||||
# 使用较长的超时时间 (10分钟),确保长耗时任务不被中断
|
# 使用较长的超时时间 (10分钟),确保长耗时任务不被中断
|
||||||
resp = requests.post(target_api, json=payload, headers=headers, timeout=1000)
|
resp = requests.post(get_proxied_url(target_api), json=payload, headers=headers, timeout=1000)
|
||||||
|
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
if use_trial:
|
if use_trial:
|
||||||
@ -151,7 +152,7 @@ def sync_video_background(app, record_id, raw_url, internal_task_id=None):
|
|||||||
for attempt in range(3):
|
for attempt in range(3):
|
||||||
try:
|
try:
|
||||||
# 增加了流式下载,处理大视频文件
|
# 增加了流式下载,处理大视频文件
|
||||||
with requests.get(raw_url, stream=True, timeout=120) as r:
|
with requests.get(get_proxied_url(raw_url), stream=True, timeout=120) as r:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
content_type = r.headers.get('content-type', 'video/mp4')
|
content_type = r.headers.get('content-type', 'video/mp4')
|
||||||
ext = ".mp4"
|
ext = ".mp4"
|
||||||
@ -209,7 +210,7 @@ def process_video_generation(app, user_id, internal_task_id, payload, api_key, c
|
|||||||
try:
|
try:
|
||||||
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
|
||||||
# 1. 提交任务
|
# 1. 提交任务
|
||||||
submit_resp = requests.post(Config.VIDEO_GEN_API, json=payload, headers=headers, timeout=60)
|
submit_resp = requests.post(get_proxied_url(Config.VIDEO_GEN_API), json=payload, headers=headers, timeout=60)
|
||||||
if submit_resp.status_code != 200:
|
if submit_resp.status_code != 200:
|
||||||
raise Exception(f"视频任务提交失败: {submit_resp.text}")
|
raise Exception(f"视频任务提交失败: {submit_resp.text}")
|
||||||
|
|
||||||
@ -233,7 +234,7 @@ def process_video_generation(app, user_id, internal_task_id, payload, api_key, c
|
|||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
poll_url = Config.VIDEO_POLL_API.format(task_id=remote_task_id)
|
poll_url = Config.VIDEO_POLL_API.format(task_id=remote_task_id)
|
||||||
poll_resp = requests.get(poll_url, headers=headers, timeout=30)
|
poll_resp = requests.get(get_proxied_url(poll_url), headers=headers, timeout=30)
|
||||||
if poll_resp.status_code != 200:
|
if poll_resp.status_code != 200:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user