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

@@ -2,6 +2,7 @@ import { OneBotAction, OneBotRequestToolkit } from '@/napcat-onebot/action/OneBo
import { StreamPacket, StreamStatus } from './StreamBasic';
import fs from 'fs';
import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid';
import { calculateTimeout } from '@/napcat-onebot/config/config';
export interface ResolvedFileInfo {
downloadPath: string;
@@ -64,8 +65,11 @@ export abstract class BaseDownloadStream<PayloadType, ResultType> extends OneBot
const searchResult = (await this.core.apis.FileApi.searchForFile([target]));
if (searchResult) {
downloadPath = await this.core.apis.FileApi.downloadFileById(searchResult.id, parseInt(searchResult.fileSize));
fileSize = parseInt(searchResult.fileSize);
const fileSizeNum = parseInt(searchResult.fileSize);
const timeoutConfig = this.obContext.configLoader.configData.timeout;
const estimatedTime = calculateTimeout(timeoutConfig, fileSizeNum, timeoutConfig.downloadSpeedKBps);
downloadPath = await this.core.apis.FileApi.downloadFileById(searchResult.id, fileSizeNum, estimatedTime);
fileSize = fileSizeNum;
fileName = searchResult.fileName;
return { downloadPath, fileName, fileSize };
}