1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-10 05:30:01 +00:00

PM-919 move methods to sendDownload

This commit is contained in:
voommen-livefront
2025-04-02 10:11:46 -05:00
parent 5f7e7aef20
commit e26dd2f5a2
2 changed files with 50 additions and 3 deletions

View File

@@ -0,0 +1,47 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { firstValueFrom } from "rxjs";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { DownloadCommand } from "./download.command";
/**
* Used to download and save attachments
*/
export abstract class SendDownload extends DownloadCommand {
/**
* @param encryptService - Needed for decryption of the retrieved attachment
* @param apiService - Needed to override the existing nativeFetch which is available as of Node 18, to support proxies
*/
constructor(
protected encryptService: EncryptService,
protected apiService: ApiService,
protected environmentService: EnvironmentService,
protected platformUtilsService: PlatformUtilsService,
) {
super(encryptService, apiService);
}
protected getIdAndKey(url: URL): [string, string] {
const result = url.hash.slice(1).split("/").slice(-2);
return [result[0], result[1]];
}
protected async getApiUrl(url: URL) {
const env = await firstValueFrom(this.environmentService.environment$);
const urls = env.getUrls();
if (url.origin === "https://send.bitwarden.com") {
return "https://api.bitwarden.com";
} else if (url.origin === urls.api) {
return url.origin;
} else if (this.platformUtilsService.isDev() && url.origin === urls.webVault) {
return urls.api;
} else {
return url.origin + "/api";
}
}
}

View File

@@ -21,13 +21,13 @@ import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.s
import { KeyService } from "@bitwarden/key-management";
import { NodeUtils } from "@bitwarden/node/node-utils";
import { DownloadCommand } from "../../../commands/download.command";
import { SendDownload } from "../../../commands/send-download.command";
import { Response } from "../../../models/response";
import { SendAccessResponse } from "../models/send-access.response";
import { SendResponse } from "../models/send.response";
// Note: DownloadCommand is actually an abstract class
export class SendDownloadService extends DownloadCommand {
export class SendDownloadService extends SendDownload {
private decKey: SymmetricCryptoKey;
constructor(
@@ -39,7 +39,7 @@ export class SendDownloadService extends DownloadCommand {
private cryptoFunctionService: CryptoFunctionService,
private sendApiService: SendApiService,
) {
super(encryptService, apiService);
super(encryptService, apiService, environmentService, platformUtilsService);
}
async download(sends: SendView, options: OptionValues) {