mirror of
https://github.com/bitwarden/browser
synced 2025-12-31 23:53:37 +00:00
bulk move/delete apis
This commit is contained in:
@@ -6,6 +6,8 @@ import { TokenService } from '../abstractions/token.service';
|
||||
|
||||
import { EnvironmentUrls } from '../models/domain/environmentUrls';
|
||||
|
||||
import { CipherBulkDeleteRequest } from '../models/request/cipherBulkDeleteRequest';
|
||||
import { CipherBulkMoveRequest } from '../models/request/cipherBulkMoveRequest';
|
||||
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
||||
import { CipherRequest } from '../models/request/cipherRequest';
|
||||
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
||||
@@ -354,6 +356,48 @@ export class ApiService implements ApiServiceAbstraction {
|
||||
}
|
||||
}
|
||||
|
||||
async deleteManyCiphers(request: CipherBulkDeleteRequest): Promise<any> {
|
||||
const authHeader = await this.handleTokenState();
|
||||
const response = await fetch(new Request(this.baseUrl + '/ciphers', {
|
||||
body: JSON.stringify(request),
|
||||
cache: 'no-cache',
|
||||
credentials: this.getCredentials(),
|
||||
headers: new Headers({
|
||||
'Accept': 'application/json',
|
||||
'Authorization': authHeader,
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Device-Type': this.deviceType,
|
||||
}),
|
||||
method: 'DELETE',
|
||||
}));
|
||||
|
||||
if (response.status !== 200) {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
async putMoveCiphers(request: CipherBulkMoveRequest): Promise<any> {
|
||||
const authHeader = await this.handleTokenState();
|
||||
const response = await fetch(new Request(this.baseUrl + '/ciphers/move', {
|
||||
body: JSON.stringify(request),
|
||||
cache: 'no-cache',
|
||||
credentials: this.getCredentials(),
|
||||
headers: new Headers({
|
||||
'Accept': 'application/json',
|
||||
'Authorization': authHeader,
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
'Device-Type': this.deviceType,
|
||||
}),
|
||||
method: 'PUT',
|
||||
}));
|
||||
|
||||
if (response.status !== 200) {
|
||||
const error = await this.handleError(response, false);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
|
||||
async putShareCipher(id: string, request: CipherShareRequest): Promise<any> {
|
||||
const authHeader = await this.handleTokenState();
|
||||
const response = await fetch(new Request(this.baseUrl + '/ciphers/' + id + '/share', {
|
||||
|
||||
@@ -15,8 +15,11 @@ import { LoginUri } from '../models/domain/loginUri';
|
||||
import { SecureNote } from '../models/domain/secureNote';
|
||||
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
|
||||
|
||||
import { CipherBulkDeleteRequest } from '../models/request/cipherBulkDeleteRequest';
|
||||
import { CipherBulkMoveRequest } from '../models/request/cipherBulkMoveRequest';
|
||||
import { CipherCollectionsRequest } from '../models/request/cipherCollectionsRequest';
|
||||
import { CipherRequest } from '../models/request/cipherRequest';
|
||||
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
||||
|
||||
import { CipherResponse } from '../models/response/cipherResponse';
|
||||
import { ErrorResponse } from '../models/response/errorResponse';
|
||||
@@ -41,7 +44,6 @@ import { StorageService } from '../abstractions/storage.service';
|
||||
import { UserService } from '../abstractions/user.service';
|
||||
|
||||
import { Utils } from '../misc/utils';
|
||||
import { CipherShareRequest } from '../models/request/cipherShareRequest';
|
||||
|
||||
const Keys = {
|
||||
ciphersPrefix: 'ciphers_',
|
||||
@@ -492,6 +494,26 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
this.decryptedCipherCache = null;
|
||||
}
|
||||
|
||||
async moveManyWithServer(ids: string[], folderId: string): Promise<any> {
|
||||
await this.apiService.putMoveCiphers(new CipherBulkMoveRequest(ids, folderId));
|
||||
|
||||
const userId = await this.userService.getUserId();
|
||||
let ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||
Keys.ciphersPrefix + userId);
|
||||
if (ciphers == null) {
|
||||
ciphers = {};
|
||||
}
|
||||
|
||||
ids.forEach((id) => {
|
||||
if (ciphers.hasOwnProperty(id)) {
|
||||
ciphers[id].folderId = folderId;
|
||||
}
|
||||
});
|
||||
|
||||
await this.storageService.save(Keys.ciphersPrefix + userId, ciphers);
|
||||
this.decryptedCipherCache = null;
|
||||
}
|
||||
|
||||
async delete(id: string | string[]): Promise<any> {
|
||||
const userId = await this.userService.getUserId();
|
||||
const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||
@@ -518,6 +540,11 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
await this.delete(id);
|
||||
}
|
||||
|
||||
async deleteManyWithServer(ids: string[]): Promise<any> {
|
||||
await this.apiService.deleteManyCiphers(new CipherBulkDeleteRequest(ids));
|
||||
await this.delete(ids);
|
||||
}
|
||||
|
||||
async deleteAttachment(id: string, attachmentId: string): Promise<void> {
|
||||
const userId = await this.userService.getUserId();
|
||||
const ciphers = await this.storageService.get<{ [id: string]: CipherData; }>(
|
||||
|
||||
Reference in New Issue
Block a user