mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 07:51:52 +00:00
Merge pull request #236 from PR0M3TH3AN/refactor/torch-config-helper-11721225630532365910
Refactor repetitive config retrieval in torch-config.mjs
This commit is contained in:
1 file changed
+40
-36
+40
-36
@@ -196,6 +196,18 @@ function parseEnvInteger(envValue, envName) {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
function resolveIntegerConfig(envKey, configValue, defaultValue, validator, configLabel) {
|
||||
const envValue = process.env[envKey];
|
||||
if (envValue) {
|
||||
const parsed = parseEnvInteger(envValue, envKey);
|
||||
validator(parsed, envKey);
|
||||
return parsed;
|
||||
}
|
||||
const value = configValue || defaultValue;
|
||||
validator(value, `effective ${configLabel}`);
|
||||
return value;
|
||||
}
|
||||
|
||||
export function getRelays() {
|
||||
const config = loadTorchConfig();
|
||||
const envRelays = process.env.NOSTR_LOCK_RELAYS;
|
||||
@@ -241,54 +253,46 @@ export function getTtl() {
|
||||
|
||||
export function getQueryTimeoutMs() {
|
||||
const config = loadTorchConfig();
|
||||
const envValue = process.env.NOSTR_LOCK_QUERY_TIMEOUT_MS;
|
||||
if (envValue) {
|
||||
const parsed = parseEnvInteger(envValue, 'NOSTR_LOCK_QUERY_TIMEOUT_MS');
|
||||
assertTimeoutInRange(parsed, 'NOSTR_LOCK_QUERY_TIMEOUT_MS');
|
||||
return parsed;
|
||||
}
|
||||
const value = config.nostrLock.queryTimeoutMs || DEFAULT_QUERY_TIMEOUT_MS;
|
||||
assertTimeoutInRange(value, 'effective query timeout');
|
||||
return value;
|
||||
return resolveIntegerConfig(
|
||||
'NOSTR_LOCK_QUERY_TIMEOUT_MS',
|
||||
config.nostrLock.queryTimeoutMs,
|
||||
DEFAULT_QUERY_TIMEOUT_MS,
|
||||
assertTimeoutInRange,
|
||||
'query timeout',
|
||||
);
|
||||
}
|
||||
|
||||
export function getPublishTimeoutMs() {
|
||||
const config = loadTorchConfig();
|
||||
const envValue = process.env.NOSTR_LOCK_PUBLISH_TIMEOUT_MS;
|
||||
if (envValue) {
|
||||
const parsed = parseEnvInteger(envValue, 'NOSTR_LOCK_PUBLISH_TIMEOUT_MS');
|
||||
assertTimeoutInRange(parsed, 'NOSTR_LOCK_PUBLISH_TIMEOUT_MS');
|
||||
return parsed;
|
||||
}
|
||||
const value = config.nostrLock.publishTimeoutMs || DEFAULT_PUBLISH_TIMEOUT_MS;
|
||||
assertTimeoutInRange(value, 'effective publish timeout');
|
||||
return value;
|
||||
return resolveIntegerConfig(
|
||||
'NOSTR_LOCK_PUBLISH_TIMEOUT_MS',
|
||||
config.nostrLock.publishTimeoutMs,
|
||||
DEFAULT_PUBLISH_TIMEOUT_MS,
|
||||
assertTimeoutInRange,
|
||||
'publish timeout',
|
||||
);
|
||||
}
|
||||
|
||||
export function getMinSuccessfulRelayPublishes() {
|
||||
const config = loadTorchConfig();
|
||||
const envValue = process.env.NOSTR_LOCK_MIN_SUCCESSFUL_PUBLISHES;
|
||||
if (envValue) {
|
||||
const parsed = parseEnvInteger(envValue, 'NOSTR_LOCK_MIN_SUCCESSFUL_PUBLISHES');
|
||||
assertPositiveCount(parsed, 'NOSTR_LOCK_MIN_SUCCESSFUL_PUBLISHES');
|
||||
return parsed;
|
||||
}
|
||||
const value = config.nostrLock.minSuccessfulRelayPublishes || DEFAULT_MIN_SUCCESSFUL_PUBLISHES;
|
||||
assertPositiveCount(value, 'effective min successful relay publishes');
|
||||
return value;
|
||||
return resolveIntegerConfig(
|
||||
'NOSTR_LOCK_MIN_SUCCESSFUL_PUBLISHES',
|
||||
config.nostrLock.minSuccessfulRelayPublishes,
|
||||
DEFAULT_MIN_SUCCESSFUL_PUBLISHES,
|
||||
assertPositiveCount,
|
||||
'min successful relay publishes',
|
||||
);
|
||||
}
|
||||
|
||||
export function getMinActiveRelayPool() {
|
||||
const config = loadTorchConfig();
|
||||
const envValue = process.env.NOSTR_LOCK_MIN_ACTIVE_RELAY_POOL;
|
||||
if (envValue) {
|
||||
const parsed = parseEnvInteger(envValue, 'NOSTR_LOCK_MIN_ACTIVE_RELAY_POOL');
|
||||
assertPositiveCount(parsed, 'NOSTR_LOCK_MIN_ACTIVE_RELAY_POOL');
|
||||
return parsed;
|
||||
}
|
||||
const value = config.nostrLock.minActiveRelayPool || DEFAULT_MIN_ACTIVE_RELAY_POOL;
|
||||
assertPositiveCount(value, 'effective min active relay pool');
|
||||
return value;
|
||||
return resolveIntegerConfig(
|
||||
'NOSTR_LOCK_MIN_ACTIVE_RELAY_POOL',
|
||||
config.nostrLock.minActiveRelayPool,
|
||||
DEFAULT_MIN_ACTIVE_RELAY_POOL,
|
||||
assertPositiveCount,
|
||||
'min active relay pool',
|
||||
);
|
||||
}
|
||||
|
||||
export function getHashtag() {
|
||||
|
||||
Reference in new issue
Block a user