mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
decrypt many collections service function
This commit is contained in:
@@ -9,6 +9,7 @@ export abstract class CollectionService {
|
|||||||
|
|
||||||
clearCache: () => void;
|
clearCache: () => void;
|
||||||
encrypt: (model: CollectionView) => Promise<Collection>;
|
encrypt: (model: CollectionView) => Promise<Collection>;
|
||||||
|
decryptMany: (collections: Collection[]) => Promise<CollectionView[]>;
|
||||||
get: (id: string) => Promise<Collection>;
|
get: (id: string) => Promise<Collection>;
|
||||||
getAll: () => Promise<Collection[]>;
|
getAll: () => Promise<Collection[]>;
|
||||||
getAllDecrypted: () => Promise<CollectionView[]>;
|
getAllDecrypted: () => Promise<CollectionView[]>;
|
||||||
|
|||||||
@@ -41,6 +41,19 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async decryptMany(collections: Collection[]): Promise<CollectionView[]> {
|
||||||
|
if (collections == null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const decCollections: CollectionView[] = [];
|
||||||
|
const promises: Array<Promise<any>> = [];
|
||||||
|
collections.forEach((collection) => {
|
||||||
|
promises.push(collection.decrypt().then((c) => decCollections.push(c)));
|
||||||
|
});
|
||||||
|
await Promise.all(promises);
|
||||||
|
return decCollections.sort(this.getLocaleSortingFunction());
|
||||||
|
}
|
||||||
|
|
||||||
async get(id: string): Promise<Collection> {
|
async get(id: string): Promise<Collection> {
|
||||||
const userId = await this.userService.getUserId();
|
const userId = await this.userService.getUserId();
|
||||||
const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
const collections = await this.storageService.get<{ [id: string]: CollectionData; }>(
|
||||||
@@ -75,16 +88,8 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
throw new Error('No key.');
|
throw new Error('No key.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const decCollections: CollectionView[] = [];
|
|
||||||
const promises: Array<Promise<any>> = [];
|
|
||||||
const collections = await this.getAll();
|
const collections = await this.getAll();
|
||||||
collections.forEach((collection) => {
|
this.decryptedCollectionCache = await this.decryptMany(collections);
|
||||||
promises.push(collection.decrypt().then((c) => decCollections.push(c)));
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
decCollections.sort(this.getLocaleSortingFunction());
|
|
||||||
this.decryptedCollectionCache = decCollections;
|
|
||||||
return this.decryptedCollectionCache;
|
return this.decryptedCollectionCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user