|
1 | 1 | <script context="module" lang="ts"> |
2 | 2 | import { APIKey, Device, PreAuthKey, User } from '$lib/common/classes'; |
3 | | - import { deviceStore, userStore, apiTestStore, APIMachineOrNode } from '$lib/common/stores.js'; |
| 3 | + import { deviceStore, userStore, apiTestStore} from '$lib/common/stores.js'; |
4 | 4 | import { sortDevices, sortUsers } from '$lib/common/sorting.svelte'; |
5 | 5 | import { filterDevices, filterUsers } from './searching.svelte'; |
6 | 6 |
|
|
152 | 152 | } |
153 | 153 |
|
154 | 154 | export async function updateTags(deviceID: string, tags: string[]): Promise<any> { |
155 | | - // test the API routes whether we should try to use 'machines' or 'nodes' |
156 | | - await testMachineOrNode(); |
157 | 155 |
|
158 | 156 | // variables in local storage |
159 | 157 | let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
160 | 158 | let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
161 | 159 | let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
162 | 160 |
|
163 | 161 | // endpoint url for editing users |
164 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/tags`; |
| 162 | + let endpointURL = `/api/v1/node/${deviceID}/tags`; |
165 | 163 |
|
166 | 164 | await fetch(headscaleURL + endpointURL, { |
167 | 165 | method: 'POST', |
|
248 | 246 | }); |
249 | 247 | } |
250 | 248 |
|
251 | | - export async function testMachineOrNode() { |
252 | | - // variables in local storage |
253 | | - let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
254 | | - let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
255 | | - let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
256 | | -
|
257 | | - // endpoint url for getting devices |
258 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}`; |
259 | | - await fetch(headscaleURL + endpointURL, { |
260 | | - method: 'GET', |
261 | | - headers: { |
262 | | - Accept: 'application/json', |
263 | | - Authorization: `Bearer ${headscaleAPIKey}` |
264 | | - } |
265 | | - }).then((response) => { |
266 | | - if (!response.ok) { |
267 | | - // set APIMachineOrNode to the opposite value |
268 | | - if (headscaleAPIMachineOrNode == 'machine') { |
269 | | - APIMachineOrNode.set('node'); |
270 | | - } else { |
271 | | - APIMachineOrNode.set('machine'); |
272 | | - } |
273 | | - } |
274 | | - }); |
275 | | - } |
276 | | -
|
277 | 249 | export async function getDevices(): Promise<any> { |
278 | | - // test the API routes whether we should try to use 'machines' or 'nodes' |
279 | | - await testMachineOrNode(); |
280 | 250 |
|
281 | 251 | // variables in local storage |
282 | 252 | let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
283 | 253 | let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
284 | | - let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
285 | 254 |
|
286 | 255 | // endpoint url for getting devices |
287 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}`; |
| 256 | + let endpointURL = `/api/v1/node`; |
288 | 257 |
|
289 | 258 | //returning variables |
290 | 259 | let headscaleDevices = [new Device()]; |
|
315 | 284 | }); |
316 | 285 |
|
317 | 286 | await headscaleDeviceResponse.json().then((data) => { |
318 | | - headscaleDevices = data[`${headscaleAPIMachineOrNode}s`]; |
| 287 | + headscaleDevices = data[`nodes`]; |
319 | 288 | headscaleDevices = sortDevices(headscaleDevices); |
320 | 289 | }); |
321 | 290 | // set the stores |
|
467 | 436 | } |
468 | 437 |
|
469 | 438 | export async function newDevice(key: string, userName: string): Promise<any> { |
470 | | - // test the API routes whether we should try to use 'machines' or 'nodes' |
471 | | - await testMachineOrNode(); |
472 | 439 |
|
473 | 440 | // variables in local storage |
474 | 441 | let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
475 | 442 | let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
476 | 443 | let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
477 | 444 |
|
478 | 445 | // endpoint url for editing users |
479 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/register`; |
| 446 | + let endpointURL = `/api/v1/node/register`; |
480 | 447 |
|
481 | 448 | await fetch(headscaleURL + endpointURL + '?user=' + userName + '&key=' + key, { |
482 | 449 | method: 'POST', |
|
500 | 467 | } |
501 | 468 |
|
502 | 469 | export async function moveDevice(deviceID: string, user: string): Promise<any> { |
503 | | - // test the API routes whether we should try to use 'machines' or 'nodes' |
504 | | - await testMachineOrNode(); |
505 | 470 |
|
506 | 471 | // variables in local storage |
507 | 472 | let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
508 | 473 | let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
509 | 474 | let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
510 | 475 |
|
511 | 476 | // endpoint url for editing users |
512 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/user?user=${user}`; |
| 477 | + let endpointURL = `/api/v1/node/${deviceID}/user?user=${user}`; |
513 | 478 |
|
514 | 479 | await fetch(headscaleURL + endpointURL, { |
515 | 480 | method: 'POST', |
|
533 | 498 | } |
534 | 499 |
|
535 | 500 | export async function renameDevice(deviceID: string, name: string): Promise<any> { |
536 | | - // test the API routes whether we should try to use 'machines' or 'nodes' |
537 | | - await testMachineOrNode(); |
538 | 501 |
|
539 | 502 | // variables in local storage |
540 | 503 | let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
541 | 504 | let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
542 | 505 | let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
543 | 506 |
|
544 | 507 | // endpoint url for editing users |
545 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/rename/${name}`; |
| 508 | + let endpointURL = `/api/v1/node/${deviceID}/rename/${name}`; |
546 | 509 |
|
547 | 510 | await fetch(headscaleURL + endpointURL, { |
548 | 511 | method: 'POST', |
|
566 | 529 | } |
567 | 530 |
|
568 | 531 | export async function removeDevice(deviceID: string): Promise<any> { |
569 | | - // test the API routes whether we should try to use 'machines' or 'nodes' |
570 | | - await testMachineOrNode(); |
571 | 532 | |
572 | 533 | // variables in local storage |
573 | 534 | let headscaleURL = localStorage.getItem('headscaleURL') || ''; |
574 | 535 | let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || ''; |
575 | 536 | let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine'; |
576 | 537 |
|
577 | 538 | // endpoint url for removing devices |
578 | | - let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}`; |
| 539 | + let endpointURL = `/api/v1/node/${deviceID}`; |
579 | 540 |
|
580 | 541 | await fetch(headscaleURL + endpointURL, { |
581 | 542 | method: 'DELETE', |
|
0 commit comments