From e24e4e19cb28227391828744528b31c5698208f5 Mon Sep 17 00:00:00 2001 From: Maxime Cannoodt Date: Wed, 29 Jun 2022 15:44:07 +0200 Subject: [PATCH] add share date to page --- server/prisma/dev.db | Bin 815104 -> 815104 bytes webapp/src/lib/model/EncryptedNote.ts | 1 + webapp/src/routes/note/[id].svelte | 27 +++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/server/prisma/dev.db b/server/prisma/dev.db index 3bac5564b9e263cf0834bece18f3b8fcaf736ddd..b710468aca3c12b4caae7d73a1495c7d682fd4a3 100644 GIT binary patch delta 3625 zcmZ{mOXwt7R>rHQr^@N>>i**lh$zCWLdp6Gy?OrN8xP)l@XdFx z-n{ttpMLwr)6X9lo_+cBA5Xu0`o+^%Pd|VA-Q&wYeG465e(>%`$Cvoii%0m!AH4nQ zlb65#8y|lB?%C77Jbn4}gQq`!DxcIR@ab1S{@0KH;p2C2zx(OSzkB!9r!Rl<(eM4% zd*6E=RoGTXAvQx8N;S|pBV}Dg=z9C`zoY0DV-QLb{}m;QbnK}D`~KJU%Ll*m;9C#g zfAGP(uj>!L{rB&_d3-g$fB*1X-+S@m&tHG`(f|9v^FREjcmMdw^Uwb6C%^j#4k8S( zcq-2@ zDnYCa4Gg=-kqf}CD`;s8CBdO(OJ<7CjnJMGLFzPKy3{(R+GNBGi|lVIP#3CTUC;rV z9X@B1Vi(F_4j(AQKY%K|5N;_+*Be~Bx)~y!0_dvQ2x8Vl*V)w$%q1wI>N3_N1k`8V zxuc0Q3U=sFnp)n5Q5~!x;ku5qS(MbVQew=Yc9q^7PLCfV zjWl_It5EVW&C3e1;ii&2MHCNh;(IPr0cSX_98eBy*bWI2;hdV-2sCAboqvZTj91vU ztw0}j^=K4V)P^mREm4}C^b;}z0hEjDMe3Tu8XWi>9v~5_>k4x0Ze~*yKJClqM!_c{ zk|q3nnK}zgfOP>NA9VIKJImdYRAMWfLrB|a16YIvE^mq91Wh*Gubgn)@91S;#5Zz9 zcB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=tFq4lu76~eXbGEUyinrP~V zI95!#b2{F-x7pET)1h!-eoRvLtb}-ZC?L!)X`Jav0hHI)kr#I^Ol`kiq(y)wyB(xJ1 zeZMlhv1w%E;ZhS|79Qa#ID0!WqTNmmRjJXbwkl79u!;w0wm5)e=|p4^`bXBgC#^S* zobNCPd*=ZORO?saW@Ua&2w}0(o*~WN=^*wXJ11l#cyyHBh=#mrIw7u6fC1sDH8CfF zc6@1`Vj`xQeACkFCi+Fe1Ju0r|Je`4kZ&7cR*tb)n&v-GalxJXkx9v z%xQ17Zb_WFd7FA&5|!I*KLm!y;y#>UYNuTB$Hp;`Cx_P|T?T<)hUvh}R%&ZEeT0Xu zoEn7|oRbx2z^Lw-0+uJUqxiF!U!ht9p+-jz%i$g>UJo`x0g>k_Od&uqi2F7+!+IKCZuCK4lHqskeJ4uL9b#nNuWze#?u86`zgW;1DFLu z=xheCO0c`Yv0}bb6=iSaq!gqG6Bo-wAV{q|{tTHPzU)}C8!Jm%}b*uqV ztf&=IuaYY*q3+)@%&Rro^3{8y$7eB4*T65YT13`E5EY!4nU*w1!7Ls-Bs;-whPlkn zlp_8h-8#$2TGr;#?lFR1D4lM%5-B6bR2-ydUcW{ooCske!qS+;=s0+|&12C486zkS y#VCQ{bcjFO)MlEtSx}*iiM>}SpTnNjc={0~ zHs$G#tQ>ONKPj>Kv2g|EfrMw;Hu6qaOlFg0V{BZn{n{3!LUwzRCfg*o?JN#FWt`Ki SB6(Dp*B7qazA%y}UJL-iaah9u diff --git a/webapp/src/lib/model/EncryptedNote.ts b/webapp/src/lib/model/EncryptedNote.ts index 64d7dd4..e2accf9 100644 --- a/webapp/src/lib/model/EncryptedNote.ts +++ b/webapp/src/lib/model/EncryptedNote.ts @@ -1,6 +1,7 @@ export type EncryptedNote = { id: string; insert_time: Date; + expiry_time: Date; ciphertext: string; hmac: string; }; diff --git a/webapp/src/routes/note/[id].svelte b/webapp/src/routes/note/[id].svelte index d45d816..5e888f5 100644 --- a/webapp/src/routes/note/[id].svelte +++ b/webapp/src/routes/note/[id].svelte @@ -10,6 +10,7 @@ try { const note: EncryptedNote = await response.json(); note.insert_time = new Date(note.insert_time as unknown as string); + note.expiry_time = new Date(note.expiry_time as unknown as string); return { status: response.status, props: { note } @@ -39,21 +40,45 @@ export let note: EncryptedNote; let plaintext: string; + let timeString: string; onMount(() => { if (browser) { // Decrypt note + console.log(note); const key = location.hash.slice(1); plaintext = decrypt({ ...note, key }); } }); + + $: if (note.insert_time) { + const diff_ms = new Date().valueOf() - note.insert_time.valueOf(); + timeString = msToString(diff_ms); + } + + function msToString(ms: number): string { + const minutes = ms / 1000 / 60; + if (minutes < 60) { + return `${Math.floor(minutes)} minute${minutes >= 2 ? 's' : ''}`; + } + const hours = minutes / 60; + if (hours < 24) { + return `${Math.floor(hours)} hour${hours >= 2 ? 's' : ''}`; + } + const days = hours / 24; + if (days < 30.42) { + return `${Math.floor(days)} day${days >= 2 ? 's' : ''}`; + } + const months = days / 30.42; + return `${Math.floor(months)} month${months >= 2 ? 's' : ''}`; + }

- e2e encrypted | Shared ?? days ago + e2e encrypted | Shared {timeString} ago