Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/src/unraid-api/auth/api-key.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,29 @@ export class ApiKeyService implements OnModuleInit {

async onModuleInit() {
this.memoryApiKeys = await this.loadAllFromDisk();
await this.cleanupLegacyInternalKeys();
if (environment.IS_MAIN_PROCESS) {
this.setupWatch();
}
}

private async cleanupLegacyInternalKeys() {
const legacyNames = ['CliInternal', 'ConnectInternal'];
const keysToDelete = this.memoryApiKeys.filter((key) => legacyNames.includes(key.name));

if (keysToDelete.length > 0) {
try {
await this.deleteApiKeys(keysToDelete.map((key) => key.id));
this.logger.log(`Cleaned up ${keysToDelete.length} legacy internal keys`);
} catch (error) {
this.logger.debug(
error,
`Failed to delete legacy internal keys: ${keysToDelete.map((key) => key.name).join(', ')}`
);
}
}
}

public async findAll(): Promise<ApiKey[]> {
return this.memoryApiKeys;
}
Expand Down
Loading