1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 00:33:44 +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:
Matt Gibson
2021-03-26 16:57:07 -05:00
committed by GitHub
parent 0735569479
commit afac694e9a
11 changed files with 189 additions and 29 deletions

View File

@@ -7,6 +7,7 @@ import { TokenService } from '../abstractions/token.service';
import { EnvironmentUrls } from '../models/domain/environmentUrls';
import { AttachmentRequest } from '../models/request/attachmentRequest';
import { BitPayInvoiceRequest } from '../models/request/bitPayInvoiceRequest';
import { CipherBulkDeleteRequest } from '../models/request/cipherBulkDeleteRequest';
import { CipherBulkMoveRequest } from '../models/request/cipherBulkMoveRequest';
@@ -75,6 +76,8 @@ import { VerifyEmailRequest } from '../models/request/verifyEmailRequest';
import { Utils } from '../misc/utils';
import { ApiKeyResponse } from '../models/response/apiKeyResponse';
import { AttachmentResponse } from '../models/response/attachmentResponse';
import { AttachmentUploadDataResponse } from '../models/response/attachmentUploadDataResponse';
import { BillingResponse } from '../models/response/billingResponse';
import { BreachAccountResponse } from '../models/response/breachAccountResponse';
import { CipherResponse } from '../models/response/cipherResponse';
@@ -600,12 +603,33 @@ export class ApiService implements ApiServiceAbstraction {
// Attachments APIs
async postCipherAttachment(id: string, data: FormData): Promise<CipherResponse> {
async getAttachmentData(cipherId: string, attachmentId: string, emergencyAccessId?: string): Promise<AttachmentResponse> {
const path = (emergencyAccessId != null ?
'/emergency-access/' + emergencyAccessId + '/' :
'/ciphers/') + cipherId + '/attachment/' + attachmentId;
const r = await this.send('GET', path, null, true, true);
return new AttachmentResponse(r);
}
async postCipherAttachment(id: string, request: AttachmentRequest): Promise<AttachmentUploadDataResponse> {
const r = await this.send('POST', '/ciphers/' + id + '/attachment/v2', request, true, true);
return new AttachmentUploadDataResponse(r);
}
/**
* @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads.
* This method still exists for backward compatibility with old server versions.
*/
async postCipherAttachmentLegacy(id: string, data: FormData): Promise<CipherResponse> {
const r = await this.send('POST', '/ciphers/' + id + '/attachment', data, true, true);
return new CipherResponse(r);
}
async postCipherAttachmentAdmin(id: string, data: FormData): Promise<CipherResponse> {
/**
* @deprecated Mar 25 2021: This method has been deprecated in favor of direct uploads.
* This method still exists for backward compatibility with old server versions.
*/
async postCipherAttachmentAdminLegacy(id: string, data: FormData): Promise<CipherResponse> {
const r = await this.send('POST', '/ciphers/' + id + '/attachment-admin', data, true, true);
return new CipherResponse(r);
}
@@ -624,6 +648,15 @@ export class ApiService implements ApiServiceAbstraction {
attachmentId + '/share?organizationId=' + organizationId, data, true, false);
}
async renewAttachmentUploadUrl(id: string, attachmentId: string): Promise<AttachmentUploadDataResponse> {
const r = await this.send('GET', '/ciphers/' + id + '/attachment/' + attachmentId, null, true, true);
return new AttachmentUploadDataResponse(r);
}
postAttachmentFile(id: string, attachmentId: string, data: FormData): Promise<any> {
return this.send('POST', '/ciphers/' + id + '/attachment/' + attachmentId + '/renew', data, true, false);
}
// Collections APIs
async getCollectionDetails(organizationId: string, id: string): Promise<CollectionGroupDetailsResponse> {