From 17760d2f4390778eea1ea2c24d55f1d7895ee57c Mon Sep 17 00:00:00 2001 From: Bernd Storath <999999bst@gmail.com> Date: Mon, 3 Nov 2025 08:43:25 +0100 Subject: [PATCH] add format onetimelink helper --- src/app/components/ClientCard/OneTimeLink.vue | 4 ++-- src/app/components/ClientCard/OneTimeLinkBtn.vue | 10 +--------- src/app/stores/clients.ts | 7 ------- src/app/utils/format.ts | 6 ++++++ 4 files changed, 9 insertions(+), 18 deletions(-) create mode 100644 src/app/utils/format.ts diff --git a/src/app/components/ClientCard/OneTimeLink.vue b/src/app/components/ClientCard/OneTimeLink.vue index 9ace22f6..2febba6d 100644 --- a/src/app/components/ClientCard/OneTimeLink.vue +++ b/src/app/components/ClientCard/OneTimeLink.vue @@ -22,7 +22,7 @@ onMounted(() => { new Date(props.client.oneTimeLink.expiresAt).getTime() - Date.now(); if (timeLeft <= 0) { - path.value = `${props.client.oneTimeConfigUrl} (00:00)`; + path.value = `${formatOneTimeLink(document.location, props.client.oneTimeLink)} (00:00)`; return; } @@ -39,7 +39,7 @@ onMounted(() => { date.setMinutes(minutes); date.setSeconds(seconds); - path.value = `${props.client.oneTimeConfigUrl} (${formatter.format(date)})`; + path.value = `${formatOneTimeLink(document.location, props.client.oneTimeLink)} (${formatter.format(date)})`; }, 1000); }); diff --git a/src/app/components/ClientCard/OneTimeLinkBtn.vue b/src/app/components/ClientCard/OneTimeLinkBtn.vue index e26b37bf..c6da4475 100644 --- a/src/app/components/ClientCard/OneTimeLinkBtn.vue +++ b/src/app/components/ClientCard/OneTimeLinkBtn.vue @@ -39,15 +39,7 @@ async function copyOneTimeLink() { } await nextTick(); - if (!props.client.oneTimeConfigUrl) { - toast.showToast({ - type: 'error', - message: $t('copy.error'), - }); - return; - } - - await copy(props.client.oneTimeConfigUrl); + await copy(formatOneTimeLink(document.location, props.client.oneTimeLink)); if (!copied.value) { toast.showToast({ diff --git a/src/app/stores/clients.ts b/src/app/stores/clients.ts index 3e08eba5..e9c58fa5 100644 --- a/src/app/stores/clients.ts +++ b/src/app/stores/clients.ts @@ -15,7 +15,6 @@ export type LocalClient = WGClientReturn & { export type ClientPersist = { transferRxHistory: number[]; - oneTimeConfigUrl?: string; transferRxPrevious: number; transferRxCurrent: number; transferRxSeries: { name: string; data: number[] }[]; @@ -60,7 +59,6 @@ export const useClientsStore = defineStore('Clients', () => { transferTxCurrent: 0, transferRxSeries: [], transferTxSeries: [], - oneTimeConfigUrl: '', }; } @@ -112,10 +110,6 @@ export const useClientsStore = defineStore('Clients', () => { ); } - if (client.oneTimeLink !== null) { - clientPersist.oneTimeConfigUrl = `${document?.location?.protocol}//${document?.location?.host}/cnf/${client.oneTimeLink.oneTimeLink}`; - } - return { ...client, avatar, @@ -128,7 +122,6 @@ export const useClientsStore = defineStore('Clients', () => { transferRxCurrent: clientPersist.transferRxCurrent, hoverTx: clientPersist.hoverTx, hoverRx: clientPersist.hoverRx, - oneTimeConfigUrl: clientPersist.oneTimeConfigUrl, }; }); diff --git a/src/app/utils/format.ts b/src/app/utils/format.ts new file mode 100644 index 00000000..6fbd95b0 --- /dev/null +++ b/src/app/utils/format.ts @@ -0,0 +1,6 @@ +export function formatOneTimeLink( + location: Location, + oneTimeLink: { oneTimeLink: string } +) { + return `${location.protocol}//${location.host}/cnf/${oneTimeLink.oneTimeLink}`; +}