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:
1 parent
df0795f2c5
commit
e9b74138d1
8 files changed
+173
-28
No files matched your search
@@ -4,6 +4,7 @@ import { FileNapCatOneBotUUID } from 'napcat-common/src/file-uuid';
|
||||
import { ActionName } from '@/napcat-onebot/action/router';
|
||||
import { OB11MessageImage, OB11MessageVideo } from '@/napcat-onebot/types';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { calculateTimeout } from '@/napcat-onebot/config/config';
|
||||
|
||||
import { FileActionsExamples } from '../example/FileActionsExamples';
|
||||
|
||||
@@ -96,7 +97,10 @@ export class GetFileBase extends OneBotAction<GetFilePayload, GetFileResponse> {
|
||||
// 搜索名字模式
|
||||
const searchResult = (await this.core.apis.FileApi.searchForFile([payload.file]));
|
||||
if (searchResult) {
|
||||
const downloadPath = await this.core.apis.FileApi.downloadFileById(searchResult.id, parseInt(searchResult.fileSize));
|
||||
const fileSize = parseInt(searchResult.fileSize);
|
||||
const timeoutConfig = this.obContext.configLoader.configData.timeout;
|
||||
const estimatedTime = calculateTimeout(timeoutConfig, fileSize, timeoutConfig.downloadSpeedKBps);
|
||||
const downloadPath = await this.core.apis.FileApi.downloadFileById(searchResult.id, fileSize, estimatedTime);
|
||||
const res: GetFileResponse = {
|
||||
file: downloadPath,
|
||||
url: downloadPath,
|
||||
|
||||
Reference in new issue
Block a user