|
1 | 1 | <script context="module" lang="ts"> |
2 | | - import { Route } from '$lib/common/classes'; |
| 2 | + import type { Route } from '$lib/common/classes'; |
3 | 3 |
|
4 | 4 | export async function getDeviceRoutes(deviceID: string): Promise<Route[]> { |
5 | 5 | // variables in local storage |
|
35 | 35 | }); |
36 | 36 |
|
37 | 37 | 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; |
51 | 39 | }); |
52 | 40 | return headscaleRouteList; |
53 | 41 | } |
|
59 | 47 | let endpointURL = ''; |
60 | 48 |
|
61 | 49 | // 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}/`; |
67 | 53 | 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'; |
83 | 57 | } |
84 | | - }); |
85 | | - } |
| 58 | + } |
| 59 | + }); |
86 | 60 | //returning variables |
87 | 61 | let headscaleDeviceResponse: Response = new Response(); |
88 | 62 |
|
|
0 commit comments