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

[PM-5214] [CLI] Add proxy support for file uploads (#7342)

* Add proxy support for file uploads

Instead of using node's native fetch we extend ApiService with NodeApiService to add support for proxies using `node-fetch`

* Fix constructors for FileUploadService in browser

* Fix dependency on ApiService within jslib-services.module

---------

Co-authored-by: Daniel James Smith <djsmith85@users.noreply.github.com>
This commit is contained in:
Daniel James Smith 2024-12-10 13:17:00 +01:00 committed by GitHub
parent b046c4965d
commit 161a358c49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 17 additions and 9 deletions

View File

@ -693,7 +693,7 @@ export default class MainBackground {
);
this.domainSettingsService = new DefaultDomainSettingsService(this.stateProvider);
this.fileUploadService = new FileUploadService(this.logService);
this.fileUploadService = new FileUploadService(this.logService, this.apiService);
this.cipherFileUploadService = new CipherFileUploadService(
this.apiService,
this.fileUploadService,

View File

@ -485,7 +485,7 @@ export class ServiceContainer {
this.domainSettingsService = new DefaultDomainSettingsService(this.stateProvider);
this.fileUploadService = new FileUploadService(this.logService);
this.fileUploadService = new FileUploadService(this.logService, this.apiService);
this.sendStateProvider = new SendStateProvider(this.stateProvider);

View File

@ -447,7 +447,7 @@ const safeProviders: SafeProvider[] = [
safeProvider({
provide: FileUploadServiceAbstraction,
useClass: FileUploadService,
deps: [LogService],
deps: [LogService, ApiServiceAbstraction],
}),
safeProvider({
provide: CipherFileUploadServiceAbstraction,

View File

@ -1,5 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ApiService } from "../../../abstractions/api.service";
import { LogService } from "../../abstractions/log.service";
import { Utils } from "../../misc/utils";
import { EncArrayBuffer } from "../../models/domain/enc-array-buffer";
@ -8,7 +9,10 @@ const MAX_SINGLE_BLOB_UPLOAD_SIZE = 256 * 1024 * 1024; // 256 MiB
const MAX_BLOCKS_PER_BLOB = 50000;
export class AzureFileUploadService {
constructor(private logService: LogService) {}
constructor(
private logService: LogService,
private apiService: ApiService,
) {}
async upload(url: string, data: EncArrayBuffer, renewalCallback: () => Promise<string>) {
if (data.buffer.byteLength <= MAX_SINGLE_BLOB_UPLOAD_SIZE) {
@ -33,7 +37,7 @@ export class AzureFileUploadService {
headers: headers,
});
const blobResponse = await fetch(request);
const blobResponse = await this.apiService.nativeFetch(request);
if (blobResponse.status !== 201) {
throw new Error(`Failed to create Azure blob: ${blobResponse.status}`);
@ -79,7 +83,7 @@ export class AzureFileUploadService {
headers: blockHeaders,
});
const blockResponse = await fetch(blockRequest);
const blockResponse = await this.apiService.nativeFetch(blockRequest);
if (blockResponse.status !== 201) {
const message = `Unsuccessful block PUT. Received status ${blockResponse.status}`;
@ -108,7 +112,7 @@ export class AzureFileUploadService {
headers: headers,
});
const response = await fetch(request);
const response = await this.apiService.nativeFetch(request);
if (response.status !== 201) {
const message = `Unsuccessful block list PUT. Received status ${response.status}`;

View File

@ -1,5 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ApiService } from "../../../abstractions/api.service";
import {
FileUploadApiMethods,
FileUploadService as FileUploadServiceAbstraction,
@ -16,8 +17,11 @@ export class FileUploadService implements FileUploadServiceAbstraction {
private azureFileUploadService: AzureFileUploadService;
private bitwardenFileUploadService: BitwardenFileUploadService;
constructor(protected logService: LogService) {
this.azureFileUploadService = new AzureFileUploadService(logService);
constructor(
protected logService: LogService,
apiService: ApiService,
) {
this.azureFileUploadService = new AzureFileUploadService(logService, apiService);
this.bitwardenFileUploadService = new BitwardenFileUploadService();
}