Skip to content

Commit a6e53ba

Browse files
authored
removed backwards compatibility check
* removed backwards compatibility check
1 parent f91f88c commit a6e53ba

File tree

4 files changed

+9
-56
lines changed

4 files changed

+9
-56
lines changed

src/lib/common/Stores.svelte

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script>
22
import { onMount } from 'svelte';
3-
import { deviceSortStore, deviceSortDirectionStore, userSortStore, sortDirectionStore, themeStore, showACLPagesStore, APIMachineOrNode } from '$lib/common/stores.js';
3+
import { deviceSortStore, deviceSortDirectionStore, userSortStore, sortDirectionStore, themeStore, showACLPagesStore} from '$lib/common/stores.js';
44
import { URLStore } from '$lib/common/stores.js';
55
import { APIKeyStore } from '$lib/common/stores.js';
66
import { preAuthHideStore } from '$lib/common/stores.js';
@@ -28,9 +28,6 @@
2828
URLStore.subscribe((val) => localStorage.setItem('headscaleURL', val.replace(/\/+$/, '')));
2929
APIKeyStore.set(localStorage.getItem('headscaleAPIKey') || '');
3030
APIKeyStore.subscribe((val) => localStorage.setItem('headscaleAPIKey', val));
31-
// stores api version compatibility info
32-
APIMachineOrNode.set(localStorage.getItem('headscaleAPIMachineOrNode') || 'machine');
33-
APIMachineOrNode.subscribe((val) => localStorage.setItem('headscaleAPIMachineOrNode', val));
3431
3532
// stores whether preauthkeys get hidden when expired/used
3633
preAuthHideStore.set((localStorage.getItem('headscalePreAuthHide') || 'false') == 'true');

src/lib/common/apiFunctions.svelte

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script context="module" lang="ts">
22
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';
44
import { sortDevices, sortUsers } from '$lib/common/sorting.svelte';
55
import { filterDevices, filterUsers } from './searching.svelte';
66
@@ -152,16 +152,14 @@
152152
}
153153
154154
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();
157155
158156
// variables in local storage
159157
let headscaleURL = localStorage.getItem('headscaleURL') || '';
160158
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
161159
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
162160
163161
// endpoint url for editing users
164-
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/tags`;
162+
let endpointURL = `/api/v1/node/${deviceID}/tags`;
165163
166164
await fetch(headscaleURL + endpointURL, {
167165
method: 'POST',
@@ -248,43 +246,14 @@
248246
});
249247
}
250248
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-
277249
export async function getDevices(): Promise<any> {
278-
// test the API routes whether we should try to use 'machines' or 'nodes'
279-
await testMachineOrNode();
280250
281251
// variables in local storage
282252
let headscaleURL = localStorage.getItem('headscaleURL') || '';
283253
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
284-
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
285254
286255
// endpoint url for getting devices
287-
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}`;
256+
let endpointURL = `/api/v1/node`;
288257
289258
//returning variables
290259
let headscaleDevices = [new Device()];
@@ -315,7 +284,7 @@
315284
});
316285
317286
await headscaleDeviceResponse.json().then((data) => {
318-
headscaleDevices = data[`${headscaleAPIMachineOrNode}s`];
287+
headscaleDevices = data[`nodes`];
319288
headscaleDevices = sortDevices(headscaleDevices);
320289
});
321290
// set the stores
@@ -467,16 +436,14 @@
467436
}
468437
469438
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();
472439
473440
// variables in local storage
474441
let headscaleURL = localStorage.getItem('headscaleURL') || '';
475442
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
476443
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
477444
478445
// endpoint url for editing users
479-
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/register`;
446+
let endpointURL = `/api/v1/node/register`;
480447
481448
await fetch(headscaleURL + endpointURL + '?user=' + userName + '&key=' + key, {
482449
method: 'POST',
@@ -500,16 +467,14 @@
500467
}
501468
502469
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();
505470
506471
// variables in local storage
507472
let headscaleURL = localStorage.getItem('headscaleURL') || '';
508473
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
509474
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
510475
511476
// 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}`;
513478
514479
await fetch(headscaleURL + endpointURL, {
515480
method: 'POST',
@@ -533,16 +498,14 @@
533498
}
534499
535500
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();
538501
539502
// variables in local storage
540503
let headscaleURL = localStorage.getItem('headscaleURL') || '';
541504
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
542505
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
543506
544507
// endpoint url for editing users
545-
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/rename/${name}`;
508+
let endpointURL = `/api/v1/node/${deviceID}/rename/${name}`;
546509
547510
await fetch(headscaleURL + endpointURL, {
548511
method: 'POST',
@@ -566,16 +529,14 @@
566529
}
567530
568531
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();
571532
572533
// variables in local storage
573534
let headscaleURL = localStorage.getItem('headscaleURL') || '';
574535
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
575536
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
576537
577538
// endpoint url for removing devices
578-
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}`;
539+
let endpointURL = `/api/v1/node/${deviceID}`;
579540
580541
await fetch(headscaleURL + endpointURL, {
581542
method: 'DELETE',

src/lib/common/stores.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export const themeStore = writable('');
1010
// stores URL and API Key
1111
export const URLStore = writable('');
1212
export const APIKeyStore = writable('');
13-
// stores the type of device api call made for version compatibility
14-
export const APIMachineOrNode = writable('machine');
1513
// stores sorting preferences
1614
export const deviceSortStore = writable('id');
1715
export const deviceSortDirectionStore = writable('ascending');

src/lib/devices/DeviceCard/DeviceRoutesAPI.svelte

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<script context="module" lang="ts">
22
import type { Route } from '$lib/common/classes';
3-
import { testMachineOrNode } from '$lib/common/apiFunctions.svelte'
43
54
export async function getDeviceRoutes(deviceID: string): Promise<Route[]> {
6-
// test the API routes whether we should try to use 'machines' or 'nodes'
7-
await testMachineOrNode();
85
96
// variables in local storage
107
let headscaleURL = localStorage.getItem('headscaleURL') || '';

0 commit comments

Comments
 (0)