Browse Source

Add oneTimeConfigUrl to clientPersist

pull/2252/head
yuWorm 9 months ago
parent
commit
fa00ba196a
  1. 4
      src/app/components/ClientCard/OneTimeLink.vue
  2. 16
      src/app/components/ClientCard/OneTimeLinkBtn.vue
  3. 7
      src/app/stores/clients.ts

4
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 = `${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink} (00:00)`;
path.value = `${props.client.oneTimeConfigUrl} (00:00)`;
return;
}
@ -39,7 +39,7 @@ onMounted(() => {
date.setMinutes(minutes);
date.setSeconds(seconds);
path.value = `${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink} (${formatter.format(date)})`;
path.value = `${props.client.oneTimeConfigUrl} (${formatter.format(date)})`;
}, 1000);
});

16
src/app/components/ClientCard/OneTimeLinkBtn.vue

@ -14,10 +14,6 @@ const props = defineProps<{ client: LocalClient }>();
const clientsStore = useClientsStore();
const toast = useToast();
const { copy, copied, isSupported } = useClipboard();
const oneTimeLink = computed(
() =>
`${document.location.protocol}//${document.location.host}/cnf/${props.client.oneTimeLink.oneTimeLink}`
);
const _showOneTimeLink = useSubmit(
`/api/client/${props.client.id}/generateOneTimeLink`,
@ -42,7 +38,17 @@ async function copyOneTimeLink() {
return;
}
await nextTick();
await copy(oneTimeLink.value);
if (!props.client.oneTimeConfigUrl) {
toast.showToast({
type: 'error',
message: $t('copy.error'),
});
return;
}
await copy(props.client.oneTimeConfigUrl);
if (!copied.value) {
toast.showToast({
type: 'error',

7
src/app/stores/clients.ts

@ -15,6 +15,7 @@ export type LocalClient = WGClientReturn & {
export type ClientPersist = {
transferRxHistory: number[];
oneTimeConfigUrl?: string;
transferRxPrevious: number;
transferRxCurrent: number;
transferRxSeries: { name: string; data: number[] }[];
@ -59,6 +60,7 @@ export const useClientsStore = defineStore('Clients', () => {
transferTxCurrent: 0,
transferRxSeries: [],
transferTxSeries: [],
oneTimeConfigUrl: '',
};
}
@ -110,6 +112,10 @@ export const useClientsStore = defineStore('Clients', () => {
);
}
if (client.oneTimeLink !== null) {
clientPersist.oneTimeConfigUrl = `${document?.location?.protocol}//${document?.location?.host}/cnf/${client.oneTimeLink.oneTimeLink}`;
}
return {
...client,
avatar,
@ -122,6 +128,7 @@ export const useClientsStore = defineStore('Clients', () => {
transferRxCurrent: clientPersist.transferRxCurrent,
hoverTx: clientPersist.hoverTx,
hoverRx: clientPersist.hoverRx,
oneTimeConfigUrl: clientPersist.oneTimeConfigUrl,
};
});

Loading…
Cancel
Save