refac
This commit is contained in:
@@ -5,6 +5,10 @@ export type FileEntry = {
|
|||||||
modified?: number;
|
modified?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TerminalFeatures = {
|
||||||
|
terminal?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
export type TerminalServer = {
|
export type TerminalServer = {
|
||||||
@@ -23,6 +27,18 @@ export const getTerminalServers = async (token: string): Promise<TerminalServer[
|
|||||||
return res.json().catch(() => []);
|
return res.json().catch(() => []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getTerminalConfig = async (
|
||||||
|
baseUrl: string,
|
||||||
|
apiKey: string
|
||||||
|
): Promise<{ features: TerminalFeatures } | null> => {
|
||||||
|
const url = `${baseUrl.replace(/\/$/, '')}/api/config`;
|
||||||
|
const res = await fetch(url, {
|
||||||
|
headers: { Authorization: `Bearer ${apiKey}` }
|
||||||
|
}).catch(() => null);
|
||||||
|
if (!res || !res.ok) return null;
|
||||||
|
return res.json().catch(() => null);
|
||||||
|
};
|
||||||
|
|
||||||
export const getCwd = async (baseUrl: string, apiKey: string): Promise<string | null> => {
|
export const getCwd = async (baseUrl: string, apiKey: string): Promise<string | null> => {
|
||||||
const url = `${baseUrl.replace(/\/$/, '')}/files/cwd`;
|
const url = `${baseUrl.replace(/\/$/, '')}/files/cwd`;
|
||||||
const res = await fetch(url, {
|
const res = await fetch(url, {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
import {
|
import {
|
||||||
getCwd,
|
getCwd,
|
||||||
|
getTerminalConfig,
|
||||||
listFiles,
|
listFiles,
|
||||||
readFile,
|
readFile,
|
||||||
downloadFileBlob,
|
downloadFileBlob,
|
||||||
@@ -50,6 +51,7 @@
|
|||||||
let containerEl: HTMLElement;
|
let containerEl: HTMLElement;
|
||||||
let terminalConnected = false;
|
let terminalConnected = false;
|
||||||
let terminalConnecting = false;
|
let terminalConnecting = false;
|
||||||
|
let terminalEnabled = true;
|
||||||
|
|
||||||
const toggleTerminal = () => {
|
const toggleTerminal = () => {
|
||||||
terminalExpanded = !terminalExpanded;
|
terminalExpanded = !terminalExpanded;
|
||||||
@@ -151,6 +153,10 @@
|
|||||||
if (terminal && terminal.url !== prevTerminalUrl) {
|
if (terminal && terminal.url !== prevTerminalUrl) {
|
||||||
prevTerminalUrl = terminal.url;
|
prevTerminalUrl = terminal.url;
|
||||||
(async () => {
|
(async () => {
|
||||||
|
// Discover server features (terminal enabled/disabled)
|
||||||
|
const config = await getTerminalConfig(terminal.url, terminal.key);
|
||||||
|
terminalEnabled = config?.features?.terminal !== false;
|
||||||
|
|
||||||
const cwd = await getCwd(terminal.url, terminal.key);
|
const cwd = await getCwd(terminal.url, terminal.key);
|
||||||
const dir = cwd ? (cwd.endsWith('/') ? cwd : cwd + '/') : '/';
|
const dir = cwd ? (cwd.endsWith('/') ? cwd : cwd + '/') : '/';
|
||||||
savedPath = dir;
|
savedPath = dir;
|
||||||
@@ -792,6 +798,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Terminal bottom panel -->
|
<!-- Terminal bottom panel -->
|
||||||
|
{#if terminalEnabled}
|
||||||
<div class="shrink-0 border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-850">
|
<div class="shrink-0 border-t border-gray-100 dark:border-gray-800 bg-white dark:bg-gray-850">
|
||||||
{#if terminalExpanded}
|
{#if terminalExpanded}
|
||||||
<!-- Drag handle (at top of panel) -->
|
<!-- Drag handle (at top of panel) -->
|
||||||
@@ -840,5 +847,6 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user