From 1324416784f82c625e9592edb55581ee42fa05f9 Mon Sep 17 00:00:00 2001 From: Matt Gibson Date: Mon, 1 Mar 2021 15:03:04 -0600 Subject: [PATCH] Direct download for send (#288) * Allow for responding with time-limited download URL * Re-verify access on download link request --- src/abstractions/api.service.ts | 4 ++++ src/models/api/sendFileApi.ts | 2 -- src/models/data/sendFileData.ts | 2 -- src/models/domain/sendFile.ts | 4 +--- src/models/response/sendFileDownloadDataResponse.ts | 12 ++++++++++++ src/models/view/sendFileView.ts | 2 -- src/services/api.service.ts | 9 +++++++++ 7 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 src/models/response/sendFileDownloadDataResponse.ts diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index 63935f17ea..2994ba4296 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -106,6 +106,7 @@ import { PreloginResponse } from '../models/response/preloginResponse'; import { ProfileResponse } from '../models/response/profileResponse'; import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; import { SendAccessResponse } from '../models/response/sendAccessResponse'; +import { SendFileDownloadDataResponse } from '../models/response/sendFileDownloadDataResponse'; import { SendResponse } from '../models/response/sendResponse'; import { SubscriptionResponse } from '../models/response/subscriptionResponse'; import { SyncResponse } from '../models/response/syncResponse'; @@ -123,6 +124,8 @@ import { import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse'; import { UserKeyResponse } from '../models/response/userKeyResponse'; +import { SendAccessView } from '../models/view/sendAccessView'; + export abstract class ApiService { urlsSet: boolean; apiBaseUrl: string; @@ -181,6 +184,7 @@ export abstract class ApiService { putSend: (id: string, request: SendRequest) => Promise; putSendRemovePassword: (id: string) => Promise; deleteSend: (id: string) => Promise; + getSendFileDownloadData: (send: SendAccessView, request: SendAccessRequest) => Promise; getCipher: (id: string) => Promise; getCipherAdmin: (id: string) => Promise; diff --git a/src/models/api/sendFileApi.ts b/src/models/api/sendFileApi.ts index 96d386711d..fc4feeee66 100644 --- a/src/models/api/sendFileApi.ts +++ b/src/models/api/sendFileApi.ts @@ -2,7 +2,6 @@ import { BaseResponse } from '../response/baseResponse'; export class SendFileApi extends BaseResponse { id: string; - url: string; fileName: string; key: string; size: string; @@ -14,7 +13,6 @@ export class SendFileApi extends BaseResponse { return; } this.id = this.getResponseProperty('Id'); - this.url = this.getResponseProperty('Url'); this.fileName = this.getResponseProperty('FileName'); this.key = this.getResponseProperty('Key'); this.size = this.getResponseProperty('Size'); diff --git a/src/models/data/sendFileData.ts b/src/models/data/sendFileData.ts index 5301f7d11e..cb7b085012 100644 --- a/src/models/data/sendFileData.ts +++ b/src/models/data/sendFileData.ts @@ -2,7 +2,6 @@ import { SendFileApi } from '../api/sendFileApi'; export class SendFileData { id: string; - url: string; fileName: string; key: string; size: string; @@ -14,7 +13,6 @@ export class SendFileData { } this.id = data.id; - this.url = data.url; this.fileName = data.fileName; this.key = data.key; this.size = data.size; diff --git a/src/models/domain/sendFile.ts b/src/models/domain/sendFile.ts index 876529ecf7..bed7e9bbff 100644 --- a/src/models/domain/sendFile.ts +++ b/src/models/domain/sendFile.ts @@ -8,7 +8,6 @@ import { SendFileView } from '../view/sendFileView'; export class SendFile extends Domain { id: string; - url: string; size: string; sizeName: string; fileName: CipherString; @@ -22,10 +21,9 @@ export class SendFile extends Domain { this.size = obj.size; this.buildDomainModel(this, obj, { id: null, - url: null, sizeName: null, fileName: null, - }, alreadyEncrypted, ['id', 'url', 'sizeName']); + }, alreadyEncrypted, ['id', 'sizeName']); } async decrypt(key: SymmetricCryptoKey): Promise { diff --git a/src/models/response/sendFileDownloadDataResponse.ts b/src/models/response/sendFileDownloadDataResponse.ts new file mode 100644 index 0000000000..734ef2243c --- /dev/null +++ b/src/models/response/sendFileDownloadDataResponse.ts @@ -0,0 +1,12 @@ +import { BaseResponse } from './baseResponse'; + +export class SendFileDownloadDataResponse extends BaseResponse { + + id: string = null; + url: string = null; + constructor(response: any) { + super(response); + this.id = this.getResponseProperty('Id'); + this.url = this.getResponseProperty('Url'); + } +} diff --git a/src/models/view/sendFileView.ts b/src/models/view/sendFileView.ts index 07ddb8c857..97192607bb 100644 --- a/src/models/view/sendFileView.ts +++ b/src/models/view/sendFileView.ts @@ -4,7 +4,6 @@ import { SendFile } from '../domain/sendFile'; export class SendFileView implements View { id: string = null; - url: string = null; size: string = null; sizeName: string = null; fileName: string = null; @@ -15,7 +14,6 @@ export class SendFileView implements View { } this.id = f.id; - this.url = f.url; this.size = f.size; this.sizeName = f.sizeName; } diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 29c94b65e8..a9ce9942b3 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -112,6 +112,7 @@ import { PreloginResponse } from '../models/response/preloginResponse'; import { ProfileResponse } from '../models/response/profileResponse'; import { SelectionReadOnlyResponse } from '../models/response/selectionReadOnlyResponse'; import { SendAccessResponse } from '../models/response/sendAccessResponse'; +import { SendFileDownloadDataResponse } from '../models/response/sendFileDownloadDataResponse'; import { SendResponse } from '../models/response/sendResponse'; import { SubscriptionResponse } from '../models/response/subscriptionResponse'; import { SyncResponse } from '../models/response/syncResponse'; @@ -129,6 +130,8 @@ import { import { TwoFactorYubiKeyResponse } from '../models/response/twoFactorYubiKeyResponse'; import { UserKeyResponse } from '../models/response/userKeyResponse'; +import { SendAccessView } from '../models/view/sendAccessView'; + export class ApiService implements ApiServiceAbstraction { urlsSet: boolean = false; apiBaseUrl: string; @@ -416,6 +419,12 @@ export class ApiService implements ApiServiceAbstraction { return new SendAccessResponse(r); } + + async getSendFileDownloadData(send: SendAccessView, request: SendAccessRequest): Promise { + const r = await this.send('POST', '/sends/' + send.id + '/access/file/' + send.file.id, request, false, true); + return new SendFileDownloadDataResponse(r); + } + async getSends(): Promise> { const r = await this.send('GET', '/sends', null, true, true); return new ListResponse(r, SendResponse);