Add configurable timeout calculation for transfers

Introduce timeout configuration and automatic timeout estimation for uploads/downloads. Added TimeoutConfig to OneBot config with baseTimeout, upload/downloadSpeedKBps and maxTimeout, plus calculateTimeout and capTimeout helpers. Applied estimation to FileApi.downloadFileById calls (GetFile, BaseDownloadStream) and to message sending (OneBotMsgApi) to compute timeouts from total payload size; sendMsg now accepts an optional timeout override which is capped by maxTimeout. Updated SendMsg payload schema to allow a custom timeout, and updated web UI store, types and config form to expose timeout settings and defaults.
This commit is contained in:
手瓜一十雪 committed 2026-03-12 15:01:34 +08:00
1 parent df0795f2c5
commit e9b74138d1
8 files changed
+173 -28

No files matched your search

@@ -23,6 +23,12 @@ const OneBotConfigCard = () => {
enableLocalFile2Url: false,
parseMultMsg: false,
imageDownloadProxy: '',
timeout: {
baseTimeout: 10000,
uploadSpeedKBps: 256,
downloadSpeedKBps: 256,
maxTimeout: 1800000,
},
},
});
const reset = () => {
@@ -30,6 +36,12 @@ const OneBotConfigCard = () => {
setOnebotValue('enableLocalFile2Url', config.enableLocalFile2Url);
setOnebotValue('parseMultMsg', config.parseMultMsg);
setOnebotValue('imageDownloadProxy', config.imageDownloadProxy);
setOnebotValue('timeout', config.timeout ?? {
baseTimeout: 10000,
uploadSpeedKBps: 256,
downloadSpeedKBps: 1000,
maxTimeout: 1800000,
});
};
const onSubmit = handleOnebotSubmit(async (data) => {
@@ -122,6 +134,82 @@ const OneBotConfigCard = () => {
/>
)}
/>
<Controller
control={control}
name='timeout.baseTimeout'
render={({ field }) => (
<Input
{...field}
type='number'
label='基础超时时间(毫秒)'
placeholder='10000'
value={field.value?.toString() ?? ''}
onChange={(e) => field.onChange(parseInt(e.target.value) || 0)}
classNames={{
inputWrapper:
'bg-default-100/50 dark:bg-white/5 backdrop-blur-md border border-transparent hover:bg-default-200/50 dark:hover:bg-white/10 transition-all shadow-sm data-[hover=true]:border-default-300',
input: 'bg-transparent text-default-700 placeholder:text-default-400',
}}
/>
)}
/>
<Controller
control={control}
name='timeout.uploadSpeedKBps'
render={({ field }) => (
<Input
{...field}
type='number'
label='预估上传速度(KB/s)'
placeholder='256'
value={field.value?.toString() ?? ''}
onChange={(e) => field.onChange(parseInt(e.target.value) || 0)}
classNames={{
inputWrapper:
'bg-default-100/50 dark:bg-white/5 backdrop-blur-md border border-transparent hover:bg-default-200/50 dark:hover:bg-white/10 transition-all shadow-sm data-[hover=true]:border-default-300',
input: 'bg-transparent text-default-700 placeholder:text-default-400',
}}
/>
)}
/>
<Controller
control={control}
name='timeout.downloadSpeedKBps'
render={({ field }) => (
<Input
{...field}
type='number'
label='预估下载速度(KB/s)'
placeholder='1000'
value={field.value?.toString() ?? ''}
onChange={(e) => field.onChange(parseInt(e.target.value) || 0)}
classNames={{
inputWrapper:
'bg-default-100/50 dark:bg-white/5 backdrop-blur-md border border-transparent hover:bg-default-200/50 dark:hover:bg-white/10 transition-all shadow-sm data-[hover=true]:border-default-300',
input: 'bg-transparent text-default-700 placeholder:text-default-400',
}}
/>
)}
/>
<Controller
control={control}
name='timeout.maxTimeout'
render={({ field }) => (
<Input
{...field}
type='number'
label='最大超时时间(毫秒)'
placeholder='1800000'
value={field.value?.toString() ?? ''}
onChange={(e) => field.onChange(parseInt(e.target.value) || 0)}
classNames={{
inputWrapper:
'bg-default-100/50 dark:bg-white/5 backdrop-blur-md border border-transparent hover:bg-default-200/50 dark:hover:bg-white/10 transition-all shadow-sm data-[hover=true]:border-default-300',
input: 'bg-transparent text-default-700 placeholder:text-default-400',
}}
/>
)}
/>
<SaveButtons
onSubmit={onSubmit}
reset={reset}
@@ -19,6 +19,12 @@ const initialState: ConfigState = {
enableLocalFile2Url: false,
parseMultMsg: true,
imageDownloadProxy: '',
timeout: {
baseTimeout: 10000,
uploadSpeedKBps: 256,
downloadSpeedKBps: 256,
maxTimeout: 1800000,
},
},
};
@@ -56,10 +56,18 @@ interface NetworkConfig {
websocketClients: Array<WebsocketClientConfig>;
}
interface TimeoutConfig {
baseTimeout: number;
uploadSpeedKBps: number;
downloadSpeedKBps: number;
maxTimeout: number;
}
interface OneBotConfig {
network: NetworkConfig; // 网络配置
musicSignUrl: string; // 音乐签名地址
enableLocalFile2Url: boolean;
parseMultMsg: boolean;
imageDownloadProxy: string; // 图片下载代理地址
timeout: TimeoutConfig; // 超时预测配置
}