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

+26
View File
@@ -78,12 +78,20 @@ const NetworkConfigSchema = Type.Object({
plugins: Type.Array(PluginConfigSchema, { default: [] }),
}, { default: {} });
const TimeoutConfigSchema = Type.Object({
baseTimeout: Type.Number({ default: 10000 }),
uploadSpeedKBps: Type.Number({ default: 256 }),
downloadSpeedKBps: Type.Number({ default: 256 }),
maxTimeout: Type.Number({ default: 1800000 }),
}, { default: {} });
export const OneBotConfigSchema = Type.Object({
network: NetworkConfigSchema,
musicSignUrl: Type.String({ default: '' }),
enableLocalFile2Url: Type.Boolean({ default: false }),
parseMultMsg: Type.Boolean({ default: false }),
imageDownloadProxy: Type.String({ default: '' }),
timeout: TimeoutConfigSchema,
});
export type OneBotConfig = Static<typeof OneBotConfigSchema>;
@@ -108,3 +116,21 @@ export function loadConfig (config: Partial<OneBotConfig>): OneBotConfig {
}
return data as OneBotConfig;
}
export function calculateTimeout (
config: OneBotConfig['timeout'],
dataSizeBytes: number,
speedKBps: number
): number {
return Math.min(
config.baseTimeout + (dataSizeBytes / 1024 / Math.max(speedKBps, 1) * 1000),
config.maxTimeout
);
}
export function capTimeout (
config: OneBotConfig['timeout'],
timeoutMs: number
): number {
return Math.min(timeoutMs, config.maxTimeout);
}