From afa01f67f4f5f45506bb14ccb194bb22e11d803e Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 30 Dec 2020 16:23:52 -0500 Subject: [PATCH] send removePasswordWithServer and model updates (#242) --- src/abstractions/send.service.ts | 1 + src/models/view/sendView.ts | 18 ++++++++++++++++++ src/services/send.service.ts | 8 +++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/abstractions/send.service.ts b/src/abstractions/send.service.ts index 03862de6bc..ae0c76311c 100644 --- a/src/abstractions/send.service.ts +++ b/src/abstractions/send.service.ts @@ -19,4 +19,5 @@ export abstract class SendService { clear: (userId: string) => Promise; delete: (id: string | string[]) => Promise; deleteWithServer: (id: string) => Promise; + removePasswordWithServer: (id: string) => Promise; } diff --git a/src/models/view/sendView.ts b/src/models/view/sendView.ts index 61c565dcf0..701a932606 100644 --- a/src/models/view/sendView.ts +++ b/src/models/view/sendView.ts @@ -46,4 +46,22 @@ export class SendView implements View { get urlB64Key(): string { return Utils.fromBufferToUrlB64(this.key); } + + get maxAccessCountReached(): boolean { + if (this.maxAccessCount == null) { + return false; + } + return this.accessCount >= this.maxAccessCount; + } + + get expired(): boolean { + if (this.expirationDate == null) { + return false; + } + return this.expirationDate <= new Date(); + } + + get pendingDelete(): boolean { + return this.deletionDate <= new Date(); + } } diff --git a/src/services/send.service.ts b/src/services/send.service.ts index 06b866efd5..212bbff02e 100644 --- a/src/services/send.service.ts +++ b/src/services/send.service.ts @@ -152,7 +152,6 @@ export class SendService implements SendServiceAbstraction { const userId = await this.userService.getUserId(); const data = new SendData(response, userId); await this.upsert(data); - } async upsert(send: SendData | SendData[]): Promise { @@ -215,6 +214,13 @@ export class SendService implements SendServiceAbstraction { await this.delete(id); } + async removePasswordWithServer(id: string): Promise { + const response = await this.apiService.putSendRemovePassword(id); + const userId = await this.userService.getUserId(); + const data = new SendData(response, userId); + await this.upsert(data); + } + private parseFile(send: Send, file: File, key: SymmetricCryptoKey): Promise { return new Promise((resolve, reject) => { const reader = new FileReader();