Sans ça isValidFeature retourne false → QuotaExceededError immédiat Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
35 lines
913 B
TypeScript
35 lines
913 B
TypeScript
export const VALID_FEATURES = [
|
|
'semantic_search',
|
|
'auto_tag',
|
|
'auto_title',
|
|
'reformulate',
|
|
'chat',
|
|
'brainstorm_create',
|
|
'brainstorm_expand',
|
|
'brainstorm_enrich',
|
|
'suggest_charts',
|
|
'slide_generate',
|
|
'excalidraw_generate',
|
|
] as const;
|
|
|
|
export type FeatureName = (typeof VALID_FEATURES)[number];
|
|
|
|
export function getCurrentPeriodKey(): string {
|
|
return new Date().toISOString().slice(0, 7);
|
|
}
|
|
|
|
export function getRedisKey(userId: string, feature: string): string {
|
|
const period = getCurrentPeriodKey();
|
|
return `usage:${userId}:${feature}:${period}`;
|
|
}
|
|
|
|
export function parseRedisInt(value: string | number | null | undefined): number {
|
|
if (value == null) return 0;
|
|
const n = Number(value);
|
|
return Number.isFinite(n) ? Math.round(n) : 1;
|
|
}
|
|
|
|
export function isValidFeature(feature: string): feature is FeatureName {
|
|
return (VALID_FEATURES as readonly string[]).includes(feature);
|
|
}
|