increase the request timeout in frontend if the timeout of requesting third-party exchange rates api exceeds the default time

This commit is contained in:
MaysWind
2024-11-16 21:13:37 +08:00
parent f554fdefd3
commit 65a92042d6
4 changed files with 32 additions and 6 deletions
+14
View File
@@ -7,6 +7,7 @@ import (
"github.com/mayswind/ezbookkeeping/pkg/core"
"github.com/mayswind/ezbookkeeping/pkg/errs"
"github.com/mayswind/ezbookkeeping/pkg/settings"
"github.com/mayswind/ezbookkeeping/pkg/utils"
)
const ezbookkeepingServerSettingsGlobalVariableName = "EZBOOKKEEPING_SERVER_SETTINGS"
@@ -109,6 +110,10 @@ func (a *ServerSettingsApi) ServerSettingsJavascriptHandler(c *core.WebContext)
}
}
if config.ExchangeRatesRequestTimeoutExceedDefaultValue {
a.appendIntegerSetting(builder, "errt", int(config.ExchangeRatesRequestTimeout))
}
return []byte(builder.String()), "", nil
}
@@ -158,6 +163,15 @@ func (a *ServerSettingsApi) appendBooleanSetting(builder *strings.Builder, key s
builder.WriteString(";\n")
}
func (a *ServerSettingsApi) appendIntegerSetting(builder *strings.Builder, key string, value int) {
builder.WriteString(ezbookkeepingServerSettingsGlobalVariableFullName)
builder.WriteString("[")
a.appendEncodedString(builder, key)
builder.WriteString("]=")
builder.WriteString(utils.IntToString(value))
builder.WriteString(";\n")
}
func (a *ServerSettingsApi) appendEncodedString(builder *strings.Builder, content string) {
builder.WriteRune('\'')
runes := []rune(content)
+10 -4
View File
@@ -328,10 +328,11 @@ type Config struct {
CustomMapTileServerDefaultZoomLevel uint8
// Exchange Rates
ExchangeRatesDataSource string
ExchangeRatesRequestTimeout uint32
ExchangeRatesProxy string
ExchangeRatesSkipTLSVerify bool
ExchangeRatesDataSource string
ExchangeRatesRequestTimeout uint32
ExchangeRatesRequestTimeoutExceedDefaultValue bool
ExchangeRatesProxy string
ExchangeRatesSkipTLSVerify bool
}
// LoadConfiguration loads setting config from given config file path
@@ -910,6 +911,11 @@ func loadExchangeRatesConfiguration(config *Config, configFile *ini.File, sectio
config.ExchangeRatesProxy = getConfigItemStringValue(configFile, sectionName, "proxy", "system")
config.ExchangeRatesRequestTimeout = getConfigItemUint32Value(configFile, sectionName, "request_timeout", defaultExchangeRatesDataRequestTimeout)
if config.ExchangeRatesRequestTimeout > defaultExchangeRatesDataRequestTimeout {
config.ExchangeRatesRequestTimeoutExceedDefaultValue = true
}
config.ExchangeRatesSkipTLSVerify = getConfigItemBoolValue(configFile, sectionName, "skip_tls_verify", false)
return nil
+4
View File
@@ -103,3 +103,7 @@ export function getAmapApiExternalProxyUrl() {
export function getAmapApplicationSecret() {
return getServerSetting('amas');
}
export function getExchangeRatesRequestTimeout() {
return getServerSetting('errt');
}
+4 -2
View File
@@ -9,7 +9,8 @@ import {
import {
getGoogleMapAPIKey,
getBaiduMapAK,
getAmapApplicationKey
getAmapApplicationKey,
getExchangeRatesRequestTimeout
} from './server_settings.js';
import { getTimezoneOffsetMinutes } from './datetime.js';
import { generateRandomUUID } from './misc.js';
@@ -619,7 +620,8 @@ export default {
},
getLatestExchangeRates: ({ ignoreError }) => {
return axios.get('v1/exchange_rates/latest.json', {
ignoreError: !!ignoreError
ignoreError: !!ignoreError,
timeout: getExchangeRatesRequestTimeout() || apiConstants.defaultTimeout
});
},
generateQrCodeUrl: (qrCodeName) => {