From 9b042150233a11788e7bfab081273c7ea248e7d2 Mon Sep 17 00:00:00 2001 From: scolastico Date: Fri, 29 Mar 2024 00:49:17 +0000 Subject: [PATCH] added: expire timer --- components/nav-bar.vue | 93 ++++++++++++++++++++++++++++++++++------ components/nav-entry.vue | 10 +++-- mixins/base.ts | 17 ++++++-- pages/index.vue | 1 + pages/q/[id].vue | 10 +++-- 5 files changed, 106 insertions(+), 25 deletions(-) diff --git a/components/nav-bar.vue b/components/nav-bar.vue index ace328b..b1c3602 100644 --- a/components/nav-bar.vue +++ b/components/nav-bar.vue @@ -1,13 +1,16 @@ + + diff --git a/mixins/base.ts b/mixins/base.ts index fc6a103..34bbb3f 100644 --- a/mixins/base.ts +++ b/mixins/base.ts @@ -10,8 +10,9 @@ export default defineNuxtComponent({ api: null as any, errorVisible: false, errorMessage: '', + defaultExpires: 0, }), - mounted() { + async mounted() { const handler = (event: any) => { if (event.origin !== location.origin) return; if (event.data?.type !== 'DUPLICATE_SHARE') return; @@ -19,7 +20,15 @@ export default defineNuxtComponent({ window.removeEventListener('message', handler); } window.addEventListener('message', handler); - this.getApi() + const api = await this.getApi() + try { + const info = await api.get('info'); + this.defaultExpires = info.data.defaultExpires; + } catch (e) { + console.error(e); + this.errorMessage = 'Error connecting to API. Please try again later.'; + this.errorVisible = true; + } }, methods: { async showError(message: string) { @@ -32,8 +41,8 @@ export default defineNuxtComponent({ const secret = Math.random().toString(36).substring(2); const encrypted = CryptoJS.AES.encrypt(this.content, secret).toString(); const res = await (await this.getApi()).post('create', { content: encrypted }); - window.location.href = `/q/${res.data.id}#${secret}`; - console.log(res.data, secret); + // window.location.href = `/q/${res.data.id}#${secret}`; + this.$router.push('/q/' + res.data.id + '#' + secret); }, async duplicateD() { if (!this.content) return this.showError('No content to duplicate'); diff --git a/pages/index.vue b/pages/index.vue index 9220481..89172cd 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -10,6 +10,7 @@ ({ isReady: false, decryptURL: '', + expires: null, }), async mounted() { try { const api = await this.getApi(); const secret = location.hash.substring(1); this.decryptURL = api.defaults.baseURL + `decrypt/${this.$route.params.id}/${secret}`; - const res = await (await this.getApi()).get(`raw/${this.$route.params.id}`); - this.content = CryptoJS.AES.decrypt(res.data, secret).toString(CryptoJS.enc.Utf8); + const res = await api.get(`json/${this.$route.params.id}`); + this.content = CryptoJS.AES.decrypt(res.data.content, secret).toString(CryptoJS.enc.Utf8); this.isReady = true; this.readOnly = true; + this.expires = res.data.expires; } catch (e) { console.error(e); - window.location.href = '/'; + this.$router.push('/'); } }, })