mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-28 06:05:24 +00:00
Adds plugins/tailscale/ with a devices sidebar tab, admin settings section, and re-auth dialog. Host Metrics tailscale manager card and SSH re-auth banner parsing stay in core.
72 lines
1.8 KiB
TypeScript
72 lines
1.8 KiB
TypeScript
// Was part of src/ui/api/settings-api.ts, moved here with the rest of the
|
|
// Tailscale plugin. The backing routes stay in place: /users/tailscale-settings
|
|
// is general user-settings infrastructure in core, and /tailscale/devices is
|
|
// this plugin's own route (plugins/tailscale/backend/routes.ts).
|
|
|
|
import axios from "axios";
|
|
import { authApi, handleApiError } from "@/main-axios";
|
|
|
|
export async function getTailscaleSettings(): Promise<{
|
|
apiKey: string;
|
|
hasApiKey: boolean;
|
|
apiBaseUrl: string;
|
|
}> {
|
|
try {
|
|
const response = await authApi.get("/users/tailscale-settings");
|
|
return response.data;
|
|
} catch (error) {
|
|
handleApiError(error, "fetch Tailscale settings");
|
|
}
|
|
}
|
|
|
|
export async function updateTailscaleSettings(
|
|
apiKey: string,
|
|
apiBaseUrl?: string,
|
|
): Promise<{ hasApiKey: boolean }> {
|
|
try {
|
|
const response = await authApi.patch("/users/tailscale-settings", {
|
|
apiKey,
|
|
apiBaseUrl,
|
|
});
|
|
return response.data;
|
|
} catch (error) {
|
|
handleApiError(error, "update Tailscale settings");
|
|
}
|
|
}
|
|
|
|
export async function getTailscaleDevices(): Promise<{
|
|
devices: Array<{
|
|
id: string;
|
|
name: string;
|
|
hostname: string;
|
|
addresses: string[];
|
|
os: string;
|
|
lastSeen: string;
|
|
}>;
|
|
hasApiKey: boolean;
|
|
error?: string;
|
|
}> {
|
|
try {
|
|
const response = await authApi.get("/tailscale/devices");
|
|
return response.data;
|
|
} catch (error) {
|
|
if (axios.isAxiosError(error)) {
|
|
const data = error.response?.data;
|
|
if (
|
|
data &&
|
|
typeof data === "object" &&
|
|
"hasApiKey" in data &&
|
|
typeof data.hasApiKey === "boolean"
|
|
) {
|
|
return data as {
|
|
devices: [];
|
|
hasApiKey: boolean;
|
|
error?: string;
|
|
};
|
|
}
|
|
}
|
|
handleApiError(error, "fetch Tailscale devices");
|
|
throw error;
|
|
}
|
|
}
|