fix: api key cache invalidated by config mtime - server picks up new key after reinstall

This commit is contained in:
2026-08-16 23:03:03 +08:00
parent a5019f1b11
commit cc02041b61

View File

@@ -15,11 +15,20 @@ function readApiKey() {
}
let cachedApiKey = null;
let cachedApiKeyMtime = 0;
function getApiKey() {
if (cachedApiKey === null) cachedApiKey = readApiKey();
try {
const stat = fs.statSync(CONFIG_PATH);
if (cachedApiKeyMtime === stat.mtimeMs) return cachedApiKey;
cachedApiKey = readApiKey();
cachedApiKeyMtime = stat.mtimeMs;
} catch {
cachedApiKey = null;
cachedApiKeyMtime = 0;
}
return cachedApiKey;
}
function clearApiKeyCache() { cachedApiKey = null; }
function clearApiKeyCache() { cachedApiKey = null; cachedApiKeyMtime = 0; }
const xssOptions = {
whiteList: {