More webapp changes+fixes

This commit is contained in:
2025-12-05 16:52:02 +01:00
parent c66cd0568f
commit 8e7a540c97
40 changed files with 1944 additions and 272 deletions

View File

@@ -0,0 +1,58 @@
import { Injectable, inject } from '@angular/core';
import { Observable, of, map, shareReplay, catchError } from 'rxjs';
import { ApiService } from './api.service';
import { AuthService } from './auth.service';
import { KeyToken } from '../models';
export interface ResolvedKey {
keyId: string;
name: string;
}
@Injectable({
providedIn: 'root'
})
export class KeyCacheService {
private apiService = inject(ApiService);
private authService = inject(AuthService);
private keysCache$: Observable<Map<string, KeyToken>> | null = null;
resolveKey(keyId: string): Observable<ResolvedKey> {
return this.getKeysMap().pipe(
map(keysMap => {
const key = keysMap.get(keyId);
return {
keyId,
name: key?.name || keyId
};
})
);
}
private getKeysMap(): Observable<Map<string, KeyToken>> {
const userId = this.authService.getUserId();
if (!userId) {
return of(new Map());
}
if (!this.keysCache$) {
this.keysCache$ = this.apiService.getKeys(userId).pipe(
map(response => {
const map = new Map<string, KeyToken>();
for (const key of response.keys) {
map.set(key.keytoken_id, key);
}
return map;
}),
catchError(() => of(new Map())),
shareReplay(1)
);
}
return this.keysCache$;
}
clearCache(): void {
this.keysCache$ = null;
}
}