1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 16:23:44 +00:00

Await file upload service (#314)

* Await file upload service

* Await file deletion on exception for file upload
This commit is contained in:
Matt Gibson
2021-03-29 08:18:07 -05:00
committed by GitHub
parent d71bd092ef
commit 5c961ce847
3 changed files with 6 additions and 6 deletions

View File

@@ -631,7 +631,7 @@ export class CipherService implements CipherServiceAbstraction {
try { try {
const uploadDataResponse = await this.apiService.postCipherAttachment(cipher.id, request); const uploadDataResponse = await this.apiService.postCipherAttachment(cipher.id, request);
response = admin ? uploadDataResponse.cipherMiniResponse : uploadDataResponse.cipherResponse; response = admin ? uploadDataResponse.cipherMiniResponse : uploadDataResponse.cipherResponse;
this.fileUploadService.uploadCipherAttachment(admin, uploadDataResponse, filename, data); await this.fileUploadService.uploadCipherAttachment(admin, uploadDataResponse, filename, data);
} catch (e) { } catch (e) {
if (e instanceof ErrorResponse && (e as ErrorResponse).statusCode === 404 || (e as ErrorResponse).statusCode === 405) { if (e instanceof ErrorResponse && (e as ErrorResponse).statusCode === 404 || (e as ErrorResponse).statusCode === 405) {
response = await this.legacyServerAttachmentFileUpload(admin, cipher.id, encFileName, encData, dataEncKey[1]); response = await this.legacyServerAttachmentFileUpload(admin, cipher.id, encFileName, encData, dataEncKey[1]);

View File

@@ -40,7 +40,7 @@ export class FileUploadService implements FileUploadServiceAbstraction {
throw new Error('Unknown file upload type'); throw new Error('Unknown file upload type');
} }
} catch (e) { } catch (e) {
this.apiService.deleteSend(uploadData.sendResponse.id); await this.apiService.deleteSend(uploadData.sendResponse.id);
throw e; throw e;
} }
} }
@@ -59,16 +59,16 @@ export class FileUploadService implements FileUploadServiceAbstraction {
uploadData.attachmentId); uploadData.attachmentId);
return renewalResponse.url; return renewalResponse.url;
}; };
this.azureFileUploadService.upload(uploadData.url, encryptedFileData, renewalCallback); await this.azureFileUploadService.upload(uploadData.url, encryptedFileData, renewalCallback);
break; break;
default: default:
throw new Error('Unknown file upload type.'); throw new Error('Unknown file upload type.');
} }
} catch (e) { } catch (e) {
if (admin) { if (admin) {
this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId); await this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId);
} else { } else {
this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId); await this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId);
} }
throw e; throw e;
} }

View File

@@ -142,7 +142,7 @@ export class SendService implements SendServiceAbstraction {
const uploadDataResponse = await this.apiService.postFileTypeSend(request); const uploadDataResponse = await this.apiService.postFileTypeSend(request);
response = uploadDataResponse.sendResponse; response = uploadDataResponse.sendResponse;
this.fileUploadService.uploadSendFile(uploadDataResponse, sendData[0].file.fileName, sendData[1]); await this.fileUploadService.uploadSendFile(uploadDataResponse, sendData[0].file.fileName, sendData[1]);
} catch (e) { } catch (e) {
if (e instanceof ErrorResponse && (e as ErrorResponse).statusCode === 404) { if (e instanceof ErrorResponse && (e as ErrorResponse).statusCode === 404) {
response = await this.legacyServerSendFileUpload(sendData, request); response = await this.legacyServerSendFileUpload(sendData, request);