mirror of
https://github.com/gurucomputing/headscale-ui.git
synced 2026-01-23 02:34:43 +00:00
removed backwards compatibility check
* removed backwards compatibility check
This commit is contained in:
parent
f91f88cdda
commit
a6e53bae9c
4 changed files with 9 additions and 56 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { deviceSortStore, deviceSortDirectionStore, userSortStore, sortDirectionStore, themeStore, showACLPagesStore, APIMachineOrNode } from '$lib/common/stores.js';
|
||||
import { deviceSortStore, deviceSortDirectionStore, userSortStore, sortDirectionStore, themeStore, showACLPagesStore} from '$lib/common/stores.js';
|
||||
import { URLStore } from '$lib/common/stores.js';
|
||||
import { APIKeyStore } from '$lib/common/stores.js';
|
||||
import { preAuthHideStore } from '$lib/common/stores.js';
|
||||
|
|
@ -28,9 +28,6 @@
|
|||
URLStore.subscribe((val) => localStorage.setItem('headscaleURL', val.replace(/\/+$/, '')));
|
||||
APIKeyStore.set(localStorage.getItem('headscaleAPIKey') || '');
|
||||
APIKeyStore.subscribe((val) => localStorage.setItem('headscaleAPIKey', val));
|
||||
// stores api version compatibility info
|
||||
APIMachineOrNode.set(localStorage.getItem('headscaleAPIMachineOrNode') || 'machine');
|
||||
APIMachineOrNode.subscribe((val) => localStorage.setItem('headscaleAPIMachineOrNode', val));
|
||||
|
||||
// stores whether preauthkeys get hidden when expired/used
|
||||
preAuthHideStore.set((localStorage.getItem('headscalePreAuthHide') || 'false') == 'true');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script context="module" lang="ts">
|
||||
import { APIKey, Device, PreAuthKey, User } from '$lib/common/classes';
|
||||
import { deviceStore, userStore, apiTestStore, APIMachineOrNode } from '$lib/common/stores.js';
|
||||
import { deviceStore, userStore, apiTestStore} from '$lib/common/stores.js';
|
||||
import { sortDevices, sortUsers } from '$lib/common/sorting.svelte';
|
||||
import { filterDevices, filterUsers } from './searching.svelte';
|
||||
|
||||
|
|
@ -152,8 +152,6 @@
|
|||
}
|
||||
|
||||
export async function updateTags(deviceID: string, tags: string[]): Promise<any> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
|
|
@ -161,7 +159,7 @@
|
|||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for editing users
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/tags`;
|
||||
let endpointURL = `/api/v1/node/${deviceID}/tags`;
|
||||
|
||||
await fetch(headscaleURL + endpointURL, {
|
||||
method: 'POST',
|
||||
|
|
@ -248,43 +246,14 @@
|
|||
});
|
||||
}
|
||||
|
||||
export async function testMachineOrNode() {
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
|
||||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for getting devices
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}`;
|
||||
await fetch(headscaleURL + endpointURL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
Authorization: `Bearer ${headscaleAPIKey}`
|
||||
}
|
||||
}).then((response) => {
|
||||
if (!response.ok) {
|
||||
// set APIMachineOrNode to the opposite value
|
||||
if (headscaleAPIMachineOrNode == 'machine') {
|
||||
APIMachineOrNode.set('node');
|
||||
} else {
|
||||
APIMachineOrNode.set('machine');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function getDevices(): Promise<any> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
let headscaleAPIKey = localStorage.getItem('headscaleAPIKey') || '';
|
||||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for getting devices
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}`;
|
||||
let endpointURL = `/api/v1/node`;
|
||||
|
||||
//returning variables
|
||||
let headscaleDevices = [new Device()];
|
||||
|
|
@ -315,7 +284,7 @@
|
|||
});
|
||||
|
||||
await headscaleDeviceResponse.json().then((data) => {
|
||||
headscaleDevices = data[`${headscaleAPIMachineOrNode}s`];
|
||||
headscaleDevices = data[`nodes`];
|
||||
headscaleDevices = sortDevices(headscaleDevices);
|
||||
});
|
||||
// set the stores
|
||||
|
|
@ -467,8 +436,6 @@
|
|||
}
|
||||
|
||||
export async function newDevice(key: string, userName: string): Promise<any> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
|
|
@ -476,7 +443,7 @@
|
|||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for editing users
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/register`;
|
||||
let endpointURL = `/api/v1/node/register`;
|
||||
|
||||
await fetch(headscaleURL + endpointURL + '?user=' + userName + '&key=' + key, {
|
||||
method: 'POST',
|
||||
|
|
@ -500,8 +467,6 @@
|
|||
}
|
||||
|
||||
export async function moveDevice(deviceID: string, user: string): Promise<any> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
|
|
@ -509,7 +474,7 @@
|
|||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for editing users
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/user?user=${user}`;
|
||||
let endpointURL = `/api/v1/node/${deviceID}/user?user=${user}`;
|
||||
|
||||
await fetch(headscaleURL + endpointURL, {
|
||||
method: 'POST',
|
||||
|
|
@ -533,8 +498,6 @@
|
|||
}
|
||||
|
||||
export async function renameDevice(deviceID: string, name: string): Promise<any> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
|
|
@ -542,7 +505,7 @@
|
|||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for editing users
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}/rename/${name}`;
|
||||
let endpointURL = `/api/v1/node/${deviceID}/rename/${name}`;
|
||||
|
||||
await fetch(headscaleURL + endpointURL, {
|
||||
method: 'POST',
|
||||
|
|
@ -566,8 +529,6 @@
|
|||
}
|
||||
|
||||
export async function removeDevice(deviceID: string): Promise<any> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
|
|
@ -575,7 +536,7 @@
|
|||
let headscaleAPIMachineOrNode = localStorage.getItem('headscaleAPIMachineOrNode') || 'machine';
|
||||
|
||||
// endpoint url for removing devices
|
||||
let endpointURL = `/api/v1/${headscaleAPIMachineOrNode}/${deviceID}`;
|
||||
let endpointURL = `/api/v1/node/${deviceID}`;
|
||||
|
||||
await fetch(headscaleURL + endpointURL, {
|
||||
method: 'DELETE',
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ export const themeStore = writable('');
|
|||
// stores URL and API Key
|
||||
export const URLStore = writable('');
|
||||
export const APIKeyStore = writable('');
|
||||
// stores the type of device api call made for version compatibility
|
||||
export const APIMachineOrNode = writable('machine');
|
||||
// stores sorting preferences
|
||||
export const deviceSortStore = writable('id');
|
||||
export const deviceSortDirectionStore = writable('ascending');
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
<script context="module" lang="ts">
|
||||
import type { Route } from '$lib/common/classes';
|
||||
import { testMachineOrNode } from '$lib/common/apiFunctions.svelte'
|
||||
|
||||
export async function getDeviceRoutes(deviceID: string): Promise<Route[]> {
|
||||
// test the API routes whether we should try to use 'machines' or 'nodes'
|
||||
await testMachineOrNode();
|
||||
|
||||
// variables in local storage
|
||||
let headscaleURL = localStorage.getItem('headscaleURL') || '';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue