Skip to content

Commit 359fab1

Browse files
committed
removed legacy API handles for routes
1 parent 5fad487 commit 359fab1

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

src/lib/devices/DeviceCard/DeviceRoutesAPI.svelte

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script context="module" lang="ts">
2-
import { Route } from '$lib/common/classes';
2+
import type { Route } from '$lib/common/classes';
33
44
export async function getDeviceRoutes(deviceID: string): Promise<Route[]> {
55
// variables in local storage
@@ -35,19 +35,7 @@
3535
});
3636
3737
await headscaleDeviceResponse.json().then((data) => {
38-
// check if the returned object is the legacy or current API object for routes
39-
// convert to a route object if it is legacy
40-
if (data.routes.advertisedRoutes) {
41-
let advertisedRoutesList: string[] = data.routes.advertisedRoutes;
42-
advertisedRoutesList.forEach((legacyRoute) => {
43-
let route = new Route();
44-
route.prefix = legacyRoute;
45-
route.enabled = data.routes.enabledRoutes.includes(legacyRoute);
46-
headscaleRouteList.push(route);
47-
});
48-
} else {
49-
headscaleRouteList = data.routes;
50-
}
38+
headscaleRouteList = data.routes;
5139
});
5240
return headscaleRouteList;
5341
}
@@ -59,30 +47,16 @@
5947
let endpointURL = '';
6048
6149
// change reply based on what API we are using. If the routeID is 0, it's the legacy API
62-
if (routeID == 0) {
63-
// endpoint url for getting users
64-
endpointURL = `/api/v1/machine/${deviceID}/routes?routes=`;
65-
66-
routeList.forEach((route) => {
50+
routeList.forEach((route) => {
51+
if (route.id == routeID) {
52+
endpointURL = `/api/v1/routes/${routeID}/`;
6753
if (route.enabled) {
68-
endpointURL += encodeURIComponent(route.prefix);
69-
endpointURL += '&routes=';
70-
}
71-
});
72-
// remove trailing ampersand and routes= expressions
73-
endpointURL = endpointURL.replace(/\&routes=$/, '').replace(/\?routes=$/, '?');
74-
} else {
75-
routeList.forEach((route) => {
76-
if (route.id == routeID) {
77-
endpointURL = `/api/v1/routes/${routeID}/`;
78-
if(route.enabled) {
79-
endpointURL += "enable";
80-
} else {
81-
endpointURL += "disable";
82-
}
54+
endpointURL += 'enable';
55+
} else {
56+
endpointURL += 'disable';
8357
}
84-
});
85-
}
58+
}
59+
});
8660
//returning variables
8761
let headscaleDeviceResponse: Response = new Response();
8862

0 commit comments

Comments
 (0)