mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
Attachment azure upload blobs (#312)
* Add direct attachment download and upload API endpoints * Use direct download method Enable download of emergency access attachments through EmergencyAccessId * Match new Server model items * New Server model for creating attachments. Provides a url to upload data to, the type of upload, and the Cipher Response expected by the previous call * Use direct upload url and scheme * Report Failed single shot azure uploads * Add cipher attachment upload to file upload service * Deprecate legacy api methods * Handle old servers missing new upload api methods * Improve Send error handling * Fallback attachment downloads on new endpoint not found Limit upload size to the new 500MB * Improve error handling * lint fixes
This commit is contained in:
@@ -5,6 +5,7 @@ import { LogService } from '../abstractions/log.service';
|
||||
import { FileUploadType } from '../enums/fileUploadType';
|
||||
|
||||
import { CipherString } from '../models/domain';
|
||||
import { AttachmentUploadDataResponse } from '../models/response/attachmentUploadDataResponse';
|
||||
import { SendFileUploadDataResponse } from '../models/response/sendFileUploadDataResponse';
|
||||
|
||||
import { AzureFileUploadService } from './azureFileUpload.service';
|
||||
@@ -23,7 +24,8 @@ export class FileUploadService implements FileUploadServiceAbstraction {
|
||||
try {
|
||||
switch (uploadData.fileUploadType) {
|
||||
case FileUploadType.Direct:
|
||||
await this.bitwardenFileUploadService.upload(uploadData.sendResponse, fileName, encryptedFileData);
|
||||
await this.bitwardenFileUploadService.upload(fileName.encryptedString, encryptedFileData,
|
||||
fd => this.apiService.postSendFile(uploadData.sendResponse.id, uploadData.sendResponse.file.id, fd));
|
||||
break;
|
||||
case FileUploadType.Azure:
|
||||
const renewalCallback = async () => {
|
||||
@@ -42,4 +44,33 @@ export class FileUploadService implements FileUploadServiceAbstraction {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
async uploadCipherAttachment(admin: boolean, uploadData: AttachmentUploadDataResponse, encryptedFileName: string, encryptedFileData: ArrayBuffer) {
|
||||
const response = admin ? uploadData.cipherMiniResponse : uploadData.cipherResponse;
|
||||
try {
|
||||
switch (uploadData.fileUploadType) {
|
||||
case FileUploadType.Direct:
|
||||
await this.bitwardenFileUploadService.upload(encryptedFileName, encryptedFileData,
|
||||
fd => this.apiService.postAttachmentFile(response.id, uploadData.attachmentId, fd));
|
||||
break;
|
||||
case FileUploadType.Azure:
|
||||
const renewalCallback = async () => {
|
||||
const renewalResponse = await this.apiService.renewAttachmentUploadUrl(response.id,
|
||||
uploadData.attachmentId);
|
||||
return renewalResponse.url;
|
||||
};
|
||||
this.azureFileUploadService.upload(uploadData.url, encryptedFileData, renewalCallback);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unknown file upload type.');
|
||||
}
|
||||
} catch (e) {
|
||||
if (admin) {
|
||||
this.apiService.deleteCipherAttachmentAdmin(response.id, uploadData.attachmentId);
|
||||
} else {
|
||||
this.apiService.deleteCipherAttachment(response.id, uploadData.attachmentId);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user