From 03cc855a1cc20ddd63671ec4950556913490fc8a Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Wed, 29 Jun 2022 14:32:02 +0200 Subject: [PATCH] add expire date to plugin --- plugin/main.ts | 4 +-- plugin/src/NoteSharingService.ts | 27 ++++++++++++------ .../src/ui/SharedNoteSuccessComponent.svelte | 13 +++++++-- plugin/src/ui/SharedNoteSuccessModal.ts | 8 ++++-- server/prisma/dev.db | Bin 815104 -> 815104 bytes server/server.ts | 5 +++- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/plugin/main.ts b/plugin/main.ts index dcea995..4ebc72a 100644 --- a/plugin/main.ts +++ b/plugin/main.ts @@ -76,7 +76,7 @@ export default class NoteSharingPlugin extends Plugin { } async shareNote(mdText: string) { - const url = await this.noteSharingService.shareNote(mdText); - new SharedNoteSuccessModal(this, url).open(); + const res = await this.noteSharingService.shareNote(mdText); + new SharedNoteSuccessModal(this, res.view_url, res.expire_time).open(); } } diff --git a/plugin/src/NoteSharingService.ts b/plugin/src/NoteSharingService.ts index d66179a..f371c74 100644 --- a/plugin/src/NoteSharingService.ts +++ b/plugin/src/NoteSharingService.ts @@ -1,6 +1,12 @@ +import moment, { type Moment } from "moment"; import { requestUrl } from "obsidian"; import { encryptMarkdown } from "./crypto/encryption"; +type Response = { + view_url: string; + expire_time: Moment; +}; + export class NoteSharingService { private _url: string; @@ -12,16 +18,20 @@ export class NoteSharingService { * @param mdText Markdown file to share. * @returns link to shared note with attached decryption key. */ - public async shareNote(mdText: string): Promise { + public async shareNote(mdText: string): Promise { mdText = this.sanitizeNote(mdText); const cryptData = encryptMarkdown(mdText); - let url = await this.postNote(cryptData.ciphertext, cryptData.hmac); - url += `#${cryptData.key}`; - console.log(`Note shared: ${url}`); - return url; + const res = await this.postNote(cryptData.ciphertext, cryptData.hmac); + console.log(res); + res.view_url += `#${cryptData.key}`; + console.log(`Note shared: ${res.view_url}`); + return res; } - private async postNote(ciphertext: string, hmac: string): Promise { + private async postNote( + ciphertext: string, + hmac: string + ): Promise { const res = await requestUrl({ url: `${this._url}/note`, method: "POST", @@ -30,7 +40,9 @@ export class NoteSharingService { }); if (res.status == 200 && res.json != null) { - return res.json.view_url; + const returnValue = res.json; + returnValue.expire_time = moment(returnValue.expire_time); + return returnValue; } throw Error("Did not get expected response from server on note POST."); } @@ -43,7 +55,6 @@ export class NoteSharingService { if (match) { mdText = match[1].trim(); } - console.log(mdText); return mdText; } diff --git a/plugin/src/ui/SharedNoteSuccessComponent.svelte b/plugin/src/ui/SharedNoteSuccessComponent.svelte index 4903006..86955c8 100644 --- a/plugin/src/ui/SharedNoteSuccessComponent.svelte +++ b/plugin/src/ui/SharedNoteSuccessComponent.svelte @@ -1,6 +1,9 @@