mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
remove legacy attachment upload (#15237)
This commit is contained in:
@@ -228,16 +228,6 @@ export abstract class ApiService {
|
|||||||
request: CipherBulkRestoreRequest,
|
request: CipherBulkRestoreRequest,
|
||||||
) => Promise<ListResponse<CipherResponse>>;
|
) => Promise<ListResponse<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.
|
|
||||||
*/
|
|
||||||
postCipherAttachmentLegacy: (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.
|
|
||||||
*/
|
|
||||||
postCipherAttachmentAdminLegacy: (id: string, data: FormData) => Promise<CipherResponse>;
|
|
||||||
postCipherAttachment: (
|
postCipherAttachment: (
|
||||||
id: string,
|
id: string,
|
||||||
request: AttachmentRequest,
|
request: AttachmentRequest,
|
||||||
|
|||||||
@@ -639,24 +639,6 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
return new AttachmentUploadDataResponse(r);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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);
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
|
deleteCipherAttachment(id: string, attachmentId: string): Promise<any> {
|
||||||
return this.send("DELETE", "/ciphers/" + id + "/attachment/" + attachmentId, null, true, true);
|
return this.send("DELETE", "/ciphers/" + id + "/attachment/" + attachmentId, null, true, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
FileUploadApiMethods,
|
FileUploadApiMethods,
|
||||||
FileUploadService,
|
FileUploadService,
|
||||||
} from "../../../platform/abstractions/file-upload/file-upload.service";
|
} from "../../../platform/abstractions/file-upload/file-upload.service";
|
||||||
import { Utils } from "../../../platform/misc/utils";
|
|
||||||
import { EncArrayBuffer } from "../../../platform/models/domain/enc-array-buffer";
|
import { EncArrayBuffer } from "../../../platform/models/domain/enc-array-buffer";
|
||||||
import { EncString } from "../../../platform/models/domain/enc-string";
|
import { EncString } from "../../../platform/models/domain/enc-string";
|
||||||
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
|
import { SymmetricCryptoKey } from "../../../platform/models/domain/symmetric-crypto-key";
|
||||||
@@ -47,18 +46,7 @@ export class CipherFileUploadService implements CipherFileUploadServiceAbstracti
|
|||||||
this.generateMethods(uploadDataResponse, response, request.adminRequest),
|
this.generateMethods(uploadDataResponse, response, request.adminRequest),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (
|
if (e instanceof ErrorResponse) {
|
||||||
(e instanceof ErrorResponse && (e as ErrorResponse).statusCode === 404) ||
|
|
||||||
(e as ErrorResponse).statusCode === 405
|
|
||||||
) {
|
|
||||||
response = await this.legacyServerAttachmentFileUpload(
|
|
||||||
request.adminRequest,
|
|
||||||
cipher.id,
|
|
||||||
encFileName,
|
|
||||||
encData,
|
|
||||||
dataEncKey[1],
|
|
||||||
);
|
|
||||||
} else if (e instanceof ErrorResponse) {
|
|
||||||
throw new Error((e as ErrorResponse).getSingleMessage());
|
throw new Error((e as ErrorResponse).getSingleMessage());
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
@@ -113,50 +101,4 @@ export class CipherFileUploadService implements CipherFileUploadServiceAbstracti
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 legacyServerAttachmentFileUpload(
|
|
||||||
admin: boolean,
|
|
||||||
cipherId: string,
|
|
||||||
encFileName: EncString,
|
|
||||||
encData: EncArrayBuffer,
|
|
||||||
key: EncString,
|
|
||||||
) {
|
|
||||||
const fd = new FormData();
|
|
||||||
try {
|
|
||||||
const blob = new Blob([encData.buffer], { type: "application/octet-stream" });
|
|
||||||
fd.append("key", key.encryptedString);
|
|
||||||
fd.append("data", blob, encFileName.encryptedString);
|
|
||||||
} catch (e) {
|
|
||||||
if (Utils.isNode && !Utils.isBrowser) {
|
|
||||||
fd.append("key", key.encryptedString);
|
|
||||||
fd.append(
|
|
||||||
"data",
|
|
||||||
Buffer.from(encData.buffer) as any,
|
|
||||||
{
|
|
||||||
filepath: encFileName.encryptedString,
|
|
||||||
contentType: "application/octet-stream",
|
|
||||||
} as any,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let response: CipherResponse;
|
|
||||||
try {
|
|
||||||
if (admin) {
|
|
||||||
response = await this.apiService.postCipherAttachmentAdminLegacy(cipherId, fd);
|
|
||||||
} else {
|
|
||||||
response = await this.apiService.postCipherAttachmentLegacy(cipherId, fd);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error((e as ErrorResponse).getSingleMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user