[skip ci] Update version to v1.5.67
This commit is contained in:
303
config.py
303
config.py
@@ -1,169 +1,136 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
项目配置文件
|
||||
统一管理所有配置参数,避免硬编码
|
||||
"""
|
||||
# 用户访问令牌(默认空字符串)
|
||||
import os # 用于路径与目录操作(写入用户配置目录)
|
||||
import json # 用于将令牌保存为 JSON 格式
|
||||
|
||||
# 后端服务器配置
|
||||
# BACKEND_HOST = "192.168.5.233"
|
||||
# BACKEND_HOST = "192.168.5.106"
|
||||
BACKEND_HOST = "192.168.5.12"
|
||||
# BACKEND_HOST = "shuidrop.com"
|
||||
# BACKEND_HOST = "test.shuidrop.com"
|
||||
BACKEND_PORT = "8000"
|
||||
# BACKEND_PORT = ""
|
||||
BACKEND_WS_URL = f"ws://{BACKEND_HOST}:{BACKEND_PORT}"
|
||||
# BACKEND_WS_URL = f"wss://{BACKEND_HOST}"
|
||||
|
||||
# WebSocket配置
|
||||
WS_CONNECT_TIMEOUT = 16.0
|
||||
WS_MESSAGE_TIMEOUT = 30.0
|
||||
WS_PING_INTERVAL = 15 # 10秒ping间隔(提高检测频率)
|
||||
WS_PING_TIMEOUT = 10 # 5秒ping超时(更快检测断线)
|
||||
WS_ENABLE_PING = True # 是否启用WebSocket原生ping心跳
|
||||
WS_ENABLE_APP_PING = False # 禁用应用层ping心跳(避免重复)
|
||||
|
||||
# AI处理超时配置
|
||||
AI_PROCESS_TIMEOUT = 30 # AI处理超时时间(秒)
|
||||
AI_LONG_PROCESS_THRESHOLD = 10 # AI长时间处理阈值(秒)
|
||||
|
||||
# 内存管理配置
|
||||
MAX_PENDING_REPLIES = 100
|
||||
CLEANUP_INTERVAL = 300 # 5分钟
|
||||
FUTURE_TIMEOUT = 300 # 5分钟
|
||||
|
||||
# 终端日志配置(简化)
|
||||
LOG_LEVEL = "INFO"
|
||||
VERSION = "1.0"
|
||||
|
||||
# GUI配置
|
||||
WINDOW_TITLE = "AI回复连接入口-V1.0"
|
||||
|
||||
# 应用版本号(用于版本检查)
|
||||
APP_VERSION = "1.5.66"
|
||||
|
||||
# 🔥 多实例运行模式开关
|
||||
# - True: 测试模式(多实例,不保存token,避免冲突)
|
||||
# - False: 生产模式(单实例,保存token,自动加载)
|
||||
#
|
||||
# 使用方法:
|
||||
# 1. 修改此值:MULTI_INSTANCE_MODE = False # 改为生产模式
|
||||
# 2. 或设置环境变量:SHUIDROP_MULTI_INSTANCE=0 # 临时切换到生产模式
|
||||
MULTI_INSTANCE_MODE = True # 默认:测试模式
|
||||
|
||||
def is_multi_instance_mode() -> bool:
|
||||
"""
|
||||
检查是否为多实例模式(支持环境变量覆盖)
|
||||
|
||||
优先级:
|
||||
1. 环境变量 SHUIDROP_MULTI_INSTANCE(0=生产,1=测试)
|
||||
2. 配置文件 MULTI_INSTANCE_MODE
|
||||
|
||||
Returns:
|
||||
bool: True=多实例模式,False=单实例模式
|
||||
"""
|
||||
# 检查环境变量
|
||||
env_value = os.getenv('SHUIDROP_MULTI_INSTANCE')
|
||||
if env_value is not None:
|
||||
# 0, false, False, no, No → 生产模式
|
||||
if env_value.lower() in ('0', 'false', 'no'):
|
||||
return False
|
||||
# 1, true, True, yes, Yes → 测试模式
|
||||
if env_value.lower() in ('1', 'true', 'yes'):
|
||||
return True
|
||||
|
||||
# 使用配置文件值 (如果不做设置我们可以直接用编码变量进行控制是否可以允许多实例的方式运行)
|
||||
return MULTI_INSTANCE_MODE
|
||||
|
||||
# 平台特定配置
|
||||
PLATFORMS = {
|
||||
"JD": {
|
||||
"name": "京东",
|
||||
"ws_url": "wss://dongdong.jd.com/workbench/websocket"
|
||||
},
|
||||
"DOUYIN": {
|
||||
"name": "抖音",
|
||||
"ws_url": None # 动态获取
|
||||
},
|
||||
"QIANNIU": {
|
||||
"name": "千牛(淘宝)",
|
||||
"ws_url": "ws://127.0.0.1:3030"
|
||||
},
|
||||
"PDD": {
|
||||
"name": "拼多多",
|
||||
"ws_url": None # 动态获取
|
||||
}
|
||||
}
|
||||
|
||||
def get_backend_ws_url(platform: str, store_id: str) -> str:
|
||||
"""获取旧版后端WebSocket URL(按店铺建连接,保留兼容)"""
|
||||
return f"{BACKEND_WS_URL}/ws/platform/{platform.lower()}/{store_id}/"
|
||||
|
||||
def get_gui_ws_url(exe_token: str) -> str:
|
||||
"""获取新版单连接GUI专用WebSocket URL(按用户token建一条连接)"""
|
||||
return f"{BACKEND_WS_URL}/ws/gui/{exe_token}/"
|
||||
|
||||
def get_config():
|
||||
"""获取所有配置"""
|
||||
return {
|
||||
'backend_host': BACKEND_HOST,
|
||||
'backend_port': BACKEND_PORT,
|
||||
'backend_ws_url': BACKEND_WS_URL,
|
||||
'ws_connect_timeout': WS_CONNECT_TIMEOUT,
|
||||
'ws_message_timeout': WS_MESSAGE_TIMEOUT,
|
||||
'max_pending_replies': MAX_PENDING_REPLIES,
|
||||
'cleanup_interval': CLEANUP_INTERVAL,
|
||||
'platforms': PLATFORMS
|
||||
}
|
||||
|
||||
|
||||
|
||||
APP_NAME = "ShuidropGUI" # 应用名称(作为配置目录名)
|
||||
|
||||
API_TOKEN = 'sd_acF0TisgfFOtsBm4ytqb17MQbcxuX9Vp' # 默认回退令牌(仅当未找到外部配置时使用)
|
||||
|
||||
def _get_config_paths():
|
||||
"""返回(配置目录, 配置文件路径),位于 %APPDATA%/ShuidropGUI/config.json"""
|
||||
base_dir = os.getenv('APPDATA') or os.path.expanduser('~') # 优先使用 APPDATA,其次使用用户主目录
|
||||
cfg_dir = os.path.join(base_dir, APP_NAME) # 组合配置目录路径
|
||||
cfg_file = os.path.join(cfg_dir, 'config.json') # 组合配置文件路径
|
||||
return cfg_dir, cfg_file
|
||||
|
||||
|
||||
def get_saved_token() -> str:
|
||||
"""优先从外部 JSON 配置读取令牌,不存在时回退到内置 API_TOKEN"""
|
||||
try:
|
||||
cfg_dir, cfg_file = _get_config_paths() # 获取目录与文件路径
|
||||
if os.path.exists(cfg_file): # 如果配置文件存在
|
||||
with open(cfg_file, 'r', encoding='utf-8') as f: # 以 UTF-8 读取
|
||||
data = json.load(f) # 解析 JSON 内容
|
||||
token = data.get('token', '') # 读取 token 字段
|
||||
if token: # 如果有效
|
||||
return token # 返回读取到的令牌
|
||||
except Exception:
|
||||
pass # 读取失败时静默回退
|
||||
return API_TOKEN # 回退为内置的默认值
|
||||
|
||||
|
||||
def set_saved_token(new_token: str) -> bool:
|
||||
"""将访问令牌写入外部 JSON 配置,并更新内存中的值
|
||||
- new_token: 新的访问令牌字符串
|
||||
返回: True 表示写入成功,False 表示失败
|
||||
"""
|
||||
try:
|
||||
cfg_dir, cfg_file = _get_config_paths()
|
||||
os.makedirs(cfg_dir, exist_ok=True)
|
||||
data = {'token': new_token}
|
||||
with open(cfg_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
# 同步更新内存变量,保证运行期可立即生效
|
||||
global API_TOKEN
|
||||
API_TOKEN = new_token
|
||||
return True
|
||||
except Exception as e:
|
||||
# 发生异常时打印提示并返回失败
|
||||
print(f"写入令牌失败: {e}")
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
项目配置文件
|
||||
统一管理所有配置参数,避免硬编码
|
||||
"""
|
||||
# 用户访问令牌(默认空字符串)
|
||||
import os # 用于路径与目录操作(写入用户配置目录)
|
||||
import json # 用于将令牌保存为 JSON 格式
|
||||
|
||||
# 后端服务器配置
|
||||
# BACKEND_HOST = "192.168.5.233"
|
||||
# BACKEND_HOST = "192.168.5.106"
|
||||
BACKEND_HOST = "192.168.5.12"
|
||||
# BACKEND_HOST = "shuidrop.com"
|
||||
# BACKEND_HOST = "test.shuidrop.com"
|
||||
BACKEND_PORT = "8000"
|
||||
# BACKEND_PORT = ""
|
||||
BACKEND_WS_URL = f"ws://{BACKEND_HOST}:{BACKEND_PORT}"
|
||||
# BACKEND_WS_URL = f"wss://{BACKEND_HOST}"
|
||||
|
||||
# WebSocket配置
|
||||
WS_CONNECT_TIMEOUT = 16.0
|
||||
WS_MESSAGE_TIMEOUT = 30.0
|
||||
WS_PING_INTERVAL = 15 # 10秒ping间隔(提高检测频率)
|
||||
WS_PING_TIMEOUT = 10 # 5秒ping超时(更快检测断线)
|
||||
WS_ENABLE_PING = True # 是否启用WebSocket原生ping心跳
|
||||
WS_ENABLE_APP_PING = False # 禁用应用层ping心跳(避免重复)
|
||||
|
||||
# AI处理超时配置
|
||||
AI_PROCESS_TIMEOUT = 30 # AI处理超时时间(秒)
|
||||
AI_LONG_PROCESS_THRESHOLD = 10 # AI长时间处理阈值(秒)
|
||||
|
||||
# 内存管理配置
|
||||
MAX_PENDING_REPLIES = 100
|
||||
CLEANUP_INTERVAL = 300 # 5分钟
|
||||
FUTURE_TIMEOUT = 300 # 5分钟
|
||||
|
||||
# 终端日志配置(简化)
|
||||
LOG_LEVEL = "INFO"
|
||||
VERSION = "1.0"
|
||||
|
||||
# GUI配置
|
||||
WINDOW_TITLE = "AI回复连接入口-V1.0"
|
||||
|
||||
# 应用版本号(用于版本检查)
|
||||
APP_VERSION = "1.5.67"
|
||||
|
||||
# 平台特定配置
|
||||
PLATFORMS = {
|
||||
"JD": {
|
||||
"name": "京东",
|
||||
"ws_url": "wss://dongdong.jd.com/workbench/websocket"
|
||||
},
|
||||
"DOUYIN": {
|
||||
"name": "抖音",
|
||||
"ws_url": None # 动态获取
|
||||
},
|
||||
"QIANNIU": {
|
||||
"name": "千牛(淘宝)",
|
||||
"ws_url": "ws://127.0.0.1:3030"
|
||||
},
|
||||
"PDD": {
|
||||
"name": "拼多多",
|
||||
"ws_url": None # 动态获取
|
||||
}
|
||||
}
|
||||
|
||||
def get_backend_ws_url(platform: str, store_id: str) -> str:
|
||||
"""获取旧版后端WebSocket URL(按店铺建连接,保留兼容)"""
|
||||
return f"{BACKEND_WS_URL}/ws/platform/{platform.lower()}/{store_id}/"
|
||||
|
||||
def get_gui_ws_url(exe_token: str) -> str:
|
||||
"""获取新版单连接GUI专用WebSocket URL(按用户token建一条连接)"""
|
||||
return f"{BACKEND_WS_URL}/ws/gui/{exe_token}/"
|
||||
|
||||
def get_config():
|
||||
"""获取所有配置"""
|
||||
return {
|
||||
'backend_host': BACKEND_HOST,
|
||||
'backend_port': BACKEND_PORT,
|
||||
'backend_ws_url': BACKEND_WS_URL,
|
||||
'ws_connect_timeout': WS_CONNECT_TIMEOUT,
|
||||
'ws_message_timeout': WS_MESSAGE_TIMEOUT,
|
||||
'max_pending_replies': MAX_PENDING_REPLIES,
|
||||
'cleanup_interval': CLEANUP_INTERVAL,
|
||||
'platforms': PLATFORMS
|
||||
}
|
||||
|
||||
|
||||
|
||||
APP_NAME = "ShuidropGUI" # 应用名称(作为配置目录名)
|
||||
|
||||
API_TOKEN = 'sd_acF0TisgfFOtsBm4ytqb17MQbcxuX9Vp' # 默认回退令牌(仅当未找到外部配置时使用)
|
||||
|
||||
def _get_config_paths():
|
||||
"""返回(配置目录, 配置文件路径),位于 %APPDATA%/ShuidropGUI/config.json"""
|
||||
base_dir = os.getenv('APPDATA') or os.path.expanduser('~') # 优先使用 APPDATA,其次使用用户主目录
|
||||
cfg_dir = os.path.join(base_dir, APP_NAME) # 组合配置目录路径
|
||||
cfg_file = os.path.join(cfg_dir, 'config.json') # 组合配置文件路径
|
||||
return cfg_dir, cfg_file
|
||||
|
||||
|
||||
def get_saved_token() -> str:
|
||||
"""优先从外部 JSON 配置读取令牌,不存在时回退到内置 API_TOKEN"""
|
||||
try:
|
||||
cfg_dir, cfg_file = _get_config_paths() # 获取目录与文件路径
|
||||
if os.path.exists(cfg_file): # 如果配置文件存在
|
||||
with open(cfg_file, 'r', encoding='utf-8') as f: # 以 UTF-8 读取
|
||||
data = json.load(f) # 解析 JSON 内容
|
||||
token = data.get('token', '') # 读取 token 字段
|
||||
if token: # 如果有效
|
||||
return token # 返回读取到的令牌
|
||||
except Exception:
|
||||
pass # 读取失败时静默回退
|
||||
return API_TOKEN # 回退为内置的默认值
|
||||
|
||||
|
||||
def set_saved_token(new_token: str) -> bool:
|
||||
"""将访问令牌写入外部 JSON 配置,并更新内存中的值
|
||||
- new_token: 新的访问令牌字符串
|
||||
返回: True 表示写入成功,False 表示失败
|
||||
"""
|
||||
try:
|
||||
cfg_dir, cfg_file = _get_config_paths()
|
||||
os.makedirs(cfg_dir, exist_ok=True)
|
||||
data = {'token': new_token}
|
||||
with open(cfg_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
# 同步更新内存变量,保证运行期可立即生效
|
||||
global API_TOKEN
|
||||
API_TOKEN = new_token
|
||||
return True
|
||||
except Exception as e:
|
||||
# 发生异常时打印提示并返回失败
|
||||
print(f"写入令牌失败: {e}")
|
||||
return False
|
||||
@@ -1,4 +1,20 @@
|
||||
[
|
||||
{
|
||||
"version": "1.5.67",
|
||||
"update_type": "patch",
|
||||
"content": "[skip ci] Update version to v1.5.66",
|
||||
"author": "Gitea Actions Bot",
|
||||
"commit_hash": "2083516b8c66377b5f13df0989fce0eeb82c105e",
|
||||
"commit_short_hash": "2083516b",
|
||||
"branch": "develop",
|
||||
"release_time": "2025-11-03 11:31:45",
|
||||
"download_url": "https://shuidrop-chat-server.ks3-cn-guangzhou.ksyuncs.com/installers/ShuiDi_AI_Assistant_Setup_v1.5.67.exe",
|
||||
"stats": {
|
||||
"files_changed": 2,
|
||||
"lines_added": 17,
|
||||
"lines_deleted": 17
|
||||
}
|
||||
},
|
||||
{
|
||||
"version": "1.5.66",
|
||||
"update_type": "patch",
|
||||
@@ -782,21 +798,5 @@
|
||||
"lines_added": 31,
|
||||
"lines_deleted": 47
|
||||
}
|
||||
},
|
||||
{
|
||||
"version": "1.4.23",
|
||||
"update_type": "patch",
|
||||
"content": "Merge remote-tracking branch 'origin/develop' into develop",
|
||||
"author": "haosicheng",
|
||||
"commit_hash": "0d9ab498b1bb8df1372e028978f69ad096f47869",
|
||||
"commit_short_hash": "0d9ab498",
|
||||
"branch": "develop",
|
||||
"release_time": "2025-10-10 15:35:22",
|
||||
"download_url": "https://shuidrop.com/download/gui/ShuiDi_AI_Assistant_Setup_v1.4.23.exe",
|
||||
"stats": {
|
||||
"files_changed": 5,
|
||||
"lines_added": 200,
|
||||
"lines_deleted": 11
|
||||
}
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user