1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-11 14:48:46 +01:00

[PM-13923] [CLI] fix: resolve CLI file upload issue in Node.js 18+ (#11652)

* fix: resolve CLI file upload issue in Node.js 18+

* remove useless try catch

Signed-off-by: xinghejd <31512683+xinghejd@users.noreply.github.com>

---------

Signed-off-by: xinghejd <31512683+xinghejd@users.noreply.github.com>
Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com>
This commit is contained in:
xinghejd 2024-11-27 18:04:30 +08:00 committed by GitHub
parent 4c43c72dca
commit 35764b53dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,22 +8,21 @@ export class BitwardenFileUploadService {
apiCall: (fd: FormData) => Promise<any>, apiCall: (fd: FormData) => Promise<any>,
) { ) {
const fd = new FormData(); const fd = new FormData();
try {
if (Utils.isBrowser) {
const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" }); const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" });
fd.append("data", blob, encryptedFileName); fd.append("data", blob, encryptedFileName);
} catch (e) { } else if (Utils.isNode) {
if (Utils.isNode && !Utils.isBrowser) {
fd.append( fd.append(
"data", "data",
Buffer.from(encryptedFileData.buffer) as any, Buffer.from(encryptedFileData.buffer) as any,
{ {
filepath: encryptedFileName, filename: encryptedFileName,
contentType: "application/octet-stream", contentType: "application/octet-stream",
} as any, } as any,
); );
} else { } else {
throw e; throw new Error("Unsupported environment");
}
} }
await apiCall(fd); await apiCall(fd);