From 63041fd673d81da56e60d2b528a4991981eab746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=BB=E7=8C=AA?= Date: Wed, 5 Apr 2023 08:04:37 +0000 Subject: [PATCH] Add button to delete machine route --- .../devices/DeviceCard/DeviceRoutes.svelte | 28 ++++++++++++++++--- .../devices/DeviceCard/DeviceRoutesAPI.svelte | 26 +++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/lib/devices/DeviceCard/DeviceRoutes.svelte b/src/lib/devices/DeviceCard/DeviceRoutes.svelte index 59f606f..2168ba2 100644 --- a/src/lib/devices/DeviceCard/DeviceRoutes.svelte +++ b/src/lib/devices/DeviceCard/DeviceRoutes.svelte @@ -1,5 +1,5 @@ Device Routes diff --git a/src/lib/devices/DeviceCard/DeviceRoutesAPI.svelte b/src/lib/devices/DeviceCard/DeviceRoutesAPI.svelte index f43d34c..09f09c8 100644 --- a/src/lib/devices/DeviceCard/DeviceRoutesAPI.svelte +++ b/src/lib/devices/DeviceCard/DeviceRoutesAPI.svelte @@ -80,4 +80,30 @@ throw error; }); } + + export async function deleteDeviceRoute(routeID: number): Promise { + // variables in local storage + let headscaleURL = localStorage.getItem('headscaleURL') || ''; + let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; + let endpointURL = `/api/v1/routes/${routeID}`; + + await fetch(headscaleURL + endpointURL, { + method: 'DELETE', + headers: { + Accept: 'application/json', + Authorization: `Bearer ${headscaleAPIKey}` + } + }) + .then((response) => { + if (response.ok) { + } else { + return response.text().then((text) => { + throw JSON.parse(text).message; + }); + } + }) + .catch((error) => { + throw error; + }); + }