mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
Add BNB_TOKEN_CLEANUP_INTERVAL variable and re-design login page
This commit is contained in:
@@ -107,7 +107,8 @@ const app = server(
|
||||
version,
|
||||
smapiAuthTokens: new JWTSmapiLoginTokens(clock, config.secret, config.authTimeout),
|
||||
externalImageResolver: artistImageFetcher,
|
||||
smapiTokenStore
|
||||
smapiTokenStore,
|
||||
tokenCleanupIntervalMinutes: config.tokenStore.cleanupIntervalMinutes
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ export default function () {
|
||||
bnbEnvVar<boolean>("REPORT_NOW_PLAYING", { default: true, parser: asBoolean }),
|
||||
tokenStore: {
|
||||
dbPath: bnbEnvVar<string>("TOKEN_DB_PATH", { default: "/config/tokens.db" })!,
|
||||
cleanupIntervalMinutes: bnbEnvVar<number>("TOKEN_CLEANUP_INTERVAL", { default: 60, parser: asInt })!,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ export type ServerOpts = {
|
||||
smapiAuthTokens: SmapiAuthTokens;
|
||||
externalImageResolver: ImageFetcher;
|
||||
smapiTokenStore: SmapiTokenStore;
|
||||
tokenCleanupIntervalMinutes: number;
|
||||
};
|
||||
|
||||
const DEFAULT_SERVER_OPTS: ServerOpts = {
|
||||
@@ -130,6 +131,7 @@ const DEFAULT_SERVER_OPTS: ServerOpts = {
|
||||
),
|
||||
externalImageResolver: axiosImageFetcher,
|
||||
smapiTokenStore: new InMemorySmapiTokenStore(),
|
||||
tokenCleanupIntervalMinutes: 60,
|
||||
};
|
||||
|
||||
function server(
|
||||
@@ -747,7 +749,8 @@ function server(
|
||||
i8n,
|
||||
serverOpts.smapiAuthTokens,
|
||||
serverOpts.smapiTokenStore,
|
||||
serverOpts.logRequests
|
||||
serverOpts.logRequests,
|
||||
serverOpts.tokenCleanupIntervalMinutes
|
||||
);
|
||||
|
||||
if (serverOpts.applyContextPath) {
|
||||
|
||||
@@ -406,7 +406,8 @@ function bindSmapiSoapServiceToExpress(
|
||||
i8n: I8N,
|
||||
smapiAuthTokens: SmapiAuthTokens,
|
||||
tokenStore: SmapiTokenStore,
|
||||
_logRequests: boolean
|
||||
_logRequests: boolean,
|
||||
tokenCleanupIntervalMinutes: number = 60
|
||||
) {
|
||||
const sonosSoap = new SonosSoap(bonobUrl, linkCodes, smapiAuthTokens, clock, tokenStore);
|
||||
|
||||
@@ -420,14 +421,16 @@ function bindSmapiSoapServiceToExpress(
|
||||
logger.error("Failed to cleanup expired tokens on startup", { error });
|
||||
}
|
||||
|
||||
// Clean up expired tokens every hour
|
||||
// Clean up expired tokens periodically
|
||||
const cleanupIntervalMs = tokenCleanupIntervalMinutes * 60 * 1000;
|
||||
logger.info(`Token cleanup will run every ${tokenCleanupIntervalMinutes} minute(s)`);
|
||||
setInterval(() => {
|
||||
try {
|
||||
tokenStore.cleanupExpired(smapiAuthTokens);
|
||||
} catch (error) {
|
||||
logger.error("Failed to cleanup expired tokens", { error });
|
||||
}
|
||||
}, 60 * 60 * 1000).unref(); // Run every hour, but don't prevent process exit
|
||||
}, cleanupIntervalMs).unref(); // Don't prevent process exit
|
||||
|
||||
const urlWithToken = (accessToken: string) =>
|
||||
bonobUrl.append({
|
||||
|
||||
Reference in New Issue
Block a user