1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-02 13:23:29 +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,23 +8,22 @@ export class BitwardenFileUploadService {
apiCall: (fd: FormData) => Promise<any>,
) {
const fd = new FormData();
try {
const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" });
fd.append("data", blob, encryptedFileName);
} catch (e) {
if (Utils.isNode && !Utils.isBrowser) {
if (Utils.isBrowser) {
const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" });
fd.append("data", blob, encryptedFileName);
} else if (Utils.isNode) {
fd.append(
"data",
Buffer.from(encryptedFileData.buffer) as any,
{
filepath: encryptedFileName,
filename: encryptedFileName,
contentType: "application/octet-stream",
} as any,
);
} else {
throw e;
throw new Error("Unsupported environment");
}
}
await apiCall(fd);
}