refactor: encapsulate state management for spec and suggestions generation

- Made the generation status variables private and introduced getter functions for both spec and suggestions generation states.
- Updated relevant route handlers to utilize the new getter functions, improving encapsulation and reducing direct access to shared state.
- Enhanced code maintainability by centralizing state management logic.
This commit is contained in:
Cody Seibert
2025-12-14 18:18:11 -05:00
parent 01bae7d43e
commit 6733de9e0d
19 changed files with 321 additions and 33 deletions

View File

@@ -17,11 +17,37 @@ function getTerminalEnabledConfig(): boolean {
return process.env.TERMINAL_ENABLED !== "false"; // Enabled by default
}
// In-memory session tokens (would use Redis in production)
export const validTokens: Map<string, { createdAt: Date; expiresAt: Date }> =
// In-memory session tokens (would use Redis in production) - private
const validTokens: Map<string, { createdAt: Date; expiresAt: Date }> =
new Map();
const TOKEN_EXPIRY_MS = 24 * 60 * 60 * 1000; // 24 hours
/**
* Add a token to the valid tokens map
*/
export function addToken(
token: string,
data: { createdAt: Date; expiresAt: Date }
): void {
validTokens.set(token, data);
}
/**
* Delete a token from the valid tokens map
*/
export function deleteToken(token: string): void {
validTokens.delete(token);
}
/**
* Get token data for a given token
*/
export function getTokenData(
token: string
): { createdAt: Date; expiresAt: Date } | undefined {
return validTokens.get(token);
}
/**
* Generate a secure random token
*/