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.
46 lines
972 B
TypeScript
46 lines
972 B
TypeScript
import { PayloadAction, createSlice } from '@reduxjs/toolkit';
|
|
|
|
import type { RootState } from '@/store';
|
|
|
|
interface ConfigState {
|
|
value: OneBotConfig;
|
|
}
|
|
|
|
const initialState: ConfigState = {
|
|
value: {
|
|
network: {
|
|
httpServers: [],
|
|
httpClients: [],
|
|
httpSseServers: [],
|
|
websocketServers: [],
|
|
websocketClients: [],
|
|
},
|
|
musicSignUrl: '',
|
|
enableLocalFile2Url: false,
|
|
parseMultMsg: true,
|
|
imageDownloadProxy: '',
|
|
timeout: {
|
|
baseTimeout: 10000,
|
|
uploadSpeedKBps: 256,
|
|
downloadSpeedKBps: 256,
|
|
maxTimeout: 1800000,
|
|
},
|
|
},
|
|
};
|
|
|
|
export const configSlice = createSlice({
|
|
name: 'config',
|
|
initialState,
|
|
reducers: {
|
|
updateConfig: (state, action: PayloadAction<OneBotConfig>) => {
|
|
state.value = action.payload;
|
|
},
|
|
},
|
|
});
|
|
|
|
export const { updateConfig } = configSlice.actions;
|
|
|
|
export const selectCount = (state: RootState) => state.config.value;
|
|
|
|
export default configSlice.reducer;
|