diff --git a/pkg/api/server_settings.go b/pkg/api/server_settings.go index 2afacb6e..4abb2094 100644 --- a/pkg/api/server_settings.go +++ b/pkg/api/server_settings.go @@ -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) diff --git a/pkg/settings/setting.go b/pkg/settings/setting.go index e883b19c..1f805f6c 100644 --- a/pkg/settings/setting.go +++ b/pkg/settings/setting.go @@ -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 diff --git a/src/lib/server_settings.js b/src/lib/server_settings.js index 73f0f94f..399fec28 100644 --- a/src/lib/server_settings.js +++ b/src/lib/server_settings.js @@ -103,3 +103,7 @@ export function getAmapApiExternalProxyUrl() { export function getAmapApplicationSecret() { return getServerSetting('amas'); } + +export function getExchangeRatesRequestTimeout() { + return getServerSetting('errt'); +} diff --git a/src/lib/services.js b/src/lib/services.js index 38948270..c4e85bbc 100644 --- a/src/lib/services.js +++ b/src/lib/services.js @@ -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) => {