1.0.12
This commit is contained in:
1 parent
a3cc26d958
commit
86a06d9de0
32 files changed
+799
-522
No files matched your search
+62
-51
@@ -2,6 +2,7 @@
|
||||
import '../app.css';
|
||||
import { onMount } from 'svelte';
|
||||
import { browser } from '$app/environment';
|
||||
import { page } from '$app/stores';
|
||||
import { Toaster } from '$lib/components/ui/sonner';
|
||||
import AppSidebar from '$lib/components/app-sidebar.svelte';
|
||||
import ThemeToggle from '$lib/components/theme-toggle.svelte';
|
||||
@@ -19,6 +20,9 @@
|
||||
import { shouldShowWhatsNew } from '$lib/utils/version';
|
||||
import { AlertTriangle, Search } from 'lucide-svelte';
|
||||
|
||||
// Check if current route is login page (no sidebar needed)
|
||||
const isLoginPage = $derived($page.url.pathname === '/login');
|
||||
|
||||
let { children } = $props();
|
||||
let envId = $state<number | null>(null);
|
||||
let commandPaletteOpen = $state(false);
|
||||
@@ -116,60 +120,67 @@
|
||||
<title>Dockhand - Docker Management</title>
|
||||
</svelte:head>
|
||||
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<MainContent>
|
||||
<header class="h-14 shrink-0 flex items-center justify-between gap-4 border-b bg-background px-4">
|
||||
<div class="flex items-center gap-2 min-w-0">
|
||||
<SidebarTrigger class="md:hidden shrink-0" />
|
||||
<HostInfo />
|
||||
</div>
|
||||
<div class="flex items-center gap-3 shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => commandPaletteOpen = true}
|
||||
class="flex items-center gap-2 px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground border rounded-md hover:bg-muted/50 transition-colors"
|
||||
>
|
||||
<Search class="w-3.5 h-3.5" />
|
||||
<span class="hidden sm:inline">Search...</span>
|
||||
<kbd class="pointer-events-none hidden sm:inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-2xs font-medium text-muted-foreground">
|
||||
{#if isMac}
|
||||
<span class="text-xs">⌘</span>
|
||||
{:else}
|
||||
<span class="text-xs">Ctrl</span>
|
||||
{/if}
|
||||
K
|
||||
</kbd>
|
||||
</button>
|
||||
{#if $licenseStore.isEnterprise && $daysUntilExpiry !== null && $daysUntilExpiry <= 30}
|
||||
<a
|
||||
href="/settings?tab=license"
|
||||
class="flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors
|
||||
{$daysUntilExpiry <= 7
|
||||
? 'bg-red-100 text-red-800 hover:bg-red-200 dark:bg-red-900/30 dark:text-red-400 dark:hover:bg-red-900/50'
|
||||
: 'bg-amber-100 text-amber-800 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-400 dark:hover:bg-amber-900/50'}"
|
||||
{#if isLoginPage}
|
||||
<!-- Login page: no sidebar, no header -->
|
||||
{@render children?.()}
|
||||
<Toaster richColors position="bottom-right" />
|
||||
{:else}
|
||||
<!-- Main app: full layout with sidebar -->
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
<MainContent>
|
||||
<header class="h-14 shrink-0 flex items-center justify-between gap-4 border-b bg-background px-4">
|
||||
<div class="flex items-center gap-2 min-w-0">
|
||||
<SidebarTrigger class="md:hidden shrink-0" />
|
||||
<HostInfo />
|
||||
</div>
|
||||
<div class="flex items-center gap-3 shrink-0">
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => commandPaletteOpen = true}
|
||||
class="flex items-center gap-2 px-2.5 py-1.5 text-xs text-muted-foreground hover:text-foreground border rounded-md hover:bg-muted/50 transition-colors"
|
||||
>
|
||||
<AlertTriangle class="w-3.5 h-3.5" />
|
||||
{#if $daysUntilExpiry <= 0}
|
||||
License expired
|
||||
{:else if $daysUntilExpiry === 1}
|
||||
License expires tomorrow
|
||||
{:else}
|
||||
License expires in {$daysUntilExpiry} days
|
||||
{/if}
|
||||
</a>
|
||||
{/if}
|
||||
<ThemeToggle />
|
||||
<Search class="w-3.5 h-3.5" />
|
||||
<span class="hidden sm:inline">Search...</span>
|
||||
<kbd class="pointer-events-none hidden sm:inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-2xs font-medium text-muted-foreground">
|
||||
{#if isMac}
|
||||
<span class="text-xs">⌘</span>
|
||||
{:else}
|
||||
<span class="text-xs">Ctrl</span>
|
||||
{/if}
|
||||
K
|
||||
</kbd>
|
||||
</button>
|
||||
{#if $licenseStore.isEnterprise && $daysUntilExpiry !== null && $daysUntilExpiry <= 30}
|
||||
<a
|
||||
href="/settings?tab=license"
|
||||
class="flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium transition-colors
|
||||
{$daysUntilExpiry <= 7
|
||||
? 'bg-red-100 text-red-800 hover:bg-red-200 dark:bg-red-900/30 dark:text-red-400 dark:hover:bg-red-900/50'
|
||||
: 'bg-amber-100 text-amber-800 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-400 dark:hover:bg-amber-900/50'}"
|
||||
>
|
||||
<AlertTriangle class="w-3.5 h-3.5" />
|
||||
{#if $daysUntilExpiry <= 0}
|
||||
License expired
|
||||
{:else if $daysUntilExpiry === 1}
|
||||
License expires tomorrow
|
||||
{:else}
|
||||
License expires in {$daysUntilExpiry} days
|
||||
{/if}
|
||||
</a>
|
||||
{/if}
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
</header>
|
||||
<div class="flex-1 min-h-0 h-[calc(100%-3.5rem)] overflow-auto py-2 px-3 flex flex-col">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</header>
|
||||
<div class="flex-1 min-h-0 h-[calc(100%-3.5rem)] overflow-auto py-2 px-3 flex flex-col">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</MainContent>
|
||||
</SidebarProvider>
|
||||
</MainContent>
|
||||
</SidebarProvider>
|
||||
|
||||
<Toaster richColors position="bottom-right" />
|
||||
<CommandPalette bind:open={commandPaletteOpen} />
|
||||
<Toaster richColors position="bottom-right" />
|
||||
<CommandPalette bind:open={commandPaletteOpen} />
|
||||
{/if}
|
||||
|
||||
{#if showWhatsNewModal && currentVersion}
|
||||
<WhatsNewModal
|
||||
|
||||
@@ -12,9 +12,11 @@ import {
|
||||
isAuthEnabled
|
||||
} from '$lib/server/auth';
|
||||
import { getUser, getUserByUsername } from '$lib/server/db';
|
||||
import { auditAuth } from '$lib/server/audit';
|
||||
|
||||
// POST /api/auth/login - Authenticate user
|
||||
export const POST: RequestHandler = async ({ request, cookies, getClientAddress }) => {
|
||||
export const POST: RequestHandler = async (event) => {
|
||||
const { request, cookies, getClientAddress } = event;
|
||||
// Check if auth is enabled
|
||||
if (!(await isAuthEnabled())) {
|
||||
return json({ error: 'Authentication is not enabled' }, { status: 400 });
|
||||
@@ -80,6 +82,12 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
||||
const session = await createUserSession(user.id, authProviderType, cookies);
|
||||
clearRateLimit(rateLimitKey);
|
||||
|
||||
// Audit log
|
||||
await auditAuth(event, 'login', user.username, {
|
||||
provider: authProviderType,
|
||||
mfa: true
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
user: {
|
||||
@@ -97,6 +105,11 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
||||
const session = await createUserSession(result.user.id, authProviderType, cookies);
|
||||
clearRateLimit(rateLimitKey);
|
||||
|
||||
// Audit log
|
||||
await auditAuth(event, 'login', result.user.username, {
|
||||
provider: authProviderType
|
||||
});
|
||||
|
||||
return json({
|
||||
success: true,
|
||||
user: {
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { destroySession } from '$lib/server/auth';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import { auditAuth } from '$lib/server/audit';
|
||||
|
||||
// POST /api/auth/logout - End session
|
||||
export const POST: RequestHandler = async ({ cookies }) => {
|
||||
export const POST: RequestHandler = async (event) => {
|
||||
const { cookies } = event;
|
||||
try {
|
||||
// Get current user before destroying session for audit log
|
||||
const auth = await authorize(cookies);
|
||||
const username = auth.user?.username || 'unknown';
|
||||
|
||||
await destroySession(cookies);
|
||||
|
||||
// Audit log
|
||||
await auditAuth(event, 'logout', username);
|
||||
|
||||
return json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Logout error:', error);
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { json, redirect } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { handleOidcCallback, createUserSession, isAuthEnabled } from '$lib/server/auth';
|
||||
import { auditAuth } from '$lib/server/audit';
|
||||
|
||||
// GET /api/auth/oidc/callback - Handle OIDC callback from IdP
|
||||
export const GET: RequestHandler = async ({ url, cookies }) => {
|
||||
export const GET: RequestHandler = async (event) => {
|
||||
const { url, cookies } = event;
|
||||
// Check if auth is enabled
|
||||
if (!isAuthEnabled()) {
|
||||
throw redirect(302, '/login?error=auth_disabled');
|
||||
@@ -38,6 +40,13 @@ export const GET: RequestHandler = async ({ url, cookies }) => {
|
||||
// Create session
|
||||
await createUserSession(result.user.id, 'oidc', cookies);
|
||||
|
||||
// Audit log
|
||||
await auditAuth(event, 'login', result.user.username, {
|
||||
provider: 'oidc',
|
||||
providerId: result.providerId,
|
||||
providerName: result.providerName
|
||||
});
|
||||
|
||||
// Redirect to the original destination or home
|
||||
const redirectUrl = result.redirectUrl || '/';
|
||||
throw redirect(302, redirectUrl);
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
downStack,
|
||||
removeStack
|
||||
} from '$lib/server/stacks';
|
||||
import { deleteAutoUpdateSchedule, getAutoUpdateSetting } from '$lib/server/db';
|
||||
import { deleteAutoUpdateSchedule, getAutoUpdateSetting, removePendingContainerUpdate } from '$lib/server/db';
|
||||
import { unregisterSchedule } from '$lib/server/scheduler';
|
||||
|
||||
// SSE Event types
|
||||
@@ -375,6 +375,15 @@ async function executeContainerOperation(
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
|
||||
// Clean up pending container update if exists
|
||||
try {
|
||||
if (envIdNum) {
|
||||
await removePendingContainerUpdate(envIdNum, id);
|
||||
}
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported container operation: ${operation}`);
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
removeContainer,
|
||||
getContainerLogs
|
||||
} from '$lib/server/docker';
|
||||
import { deleteAutoUpdateSchedule, getAutoUpdateSetting } from '$lib/server/db';
|
||||
import { deleteAutoUpdateSchedule, getAutoUpdateSetting, removePendingContainerUpdate } from '$lib/server/db';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import { auditContainer } from '$lib/server/audit';
|
||||
import { unregisterSchedule } from '$lib/server/scheduler';
|
||||
@@ -85,6 +85,16 @@ export const DELETE: RequestHandler = async (event) => {
|
||||
// Don't fail the deletion if schedule cleanup fails
|
||||
}
|
||||
|
||||
// Clean up pending container update if exists
|
||||
try {
|
||||
if (envIdNum) {
|
||||
await removePendingContainerUpdate(envIdNum, params.id);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to cleanup pending container update:', error);
|
||||
// Don't fail the deletion if cleanup fails
|
||||
}
|
||||
|
||||
return json({ success: true });
|
||||
} catch (error) {
|
||||
console.error('Error removing container:', error);
|
||||
|
||||
@@ -182,6 +182,22 @@ export const POST: RequestHandler = async (event) => {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip digest-pinned images - they are explicitly locked to a specific version
|
||||
if (isDigestBasedImage(imageName)) {
|
||||
safeEnqueue({
|
||||
type: 'progress',
|
||||
containerId,
|
||||
containerName,
|
||||
step: 'skipped',
|
||||
current: i + 1,
|
||||
total: containerIds.length,
|
||||
success: true,
|
||||
message: `Skipping ${containerName} - image pinned to specific digest`
|
||||
});
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Step 1: Pull latest image
|
||||
safeEnqueue({
|
||||
type: 'progress',
|
||||
@@ -559,8 +575,18 @@ export const POST: RequestHandler = async (event) => {
|
||||
: `Updated ${successCount} of ${containerIds.length} containers`
|
||||
});
|
||||
|
||||
clearInterval(keepaliveInterval);
|
||||
controller.close();
|
||||
if (keepaliveInterval) {
|
||||
clearInterval(keepaliveInterval);
|
||||
}
|
||||
if (!controllerClosed) {
|
||||
try {
|
||||
controller.close();
|
||||
controllerClosed = true;
|
||||
} catch {
|
||||
// Controller already closed - ignore
|
||||
controllerClosed = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
cancel() {
|
||||
controllerClosed = true;
|
||||
|
||||
@@ -20,6 +20,9 @@ import { listComposeStacks } from '$lib/server/stacks';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import { parseLabels } from '$lib/utils/label-colors';
|
||||
|
||||
// Skip disk usage collection (Synology NAS performance fix)
|
||||
const SKIP_DF_COLLECTION = process.env.SKIP_DF_COLLECTION === 'true' || process.env.SKIP_DF_COLLECTION === '1';
|
||||
|
||||
// Helper to add timeout to promises
|
||||
function withTimeout<T>(promise: Promise<T>, ms: number, fallback: T): Promise<T> {
|
||||
return Promise.race([
|
||||
@@ -200,13 +203,14 @@ export const GET: RequestHandler = async ({ cookies, url }) => {
|
||||
envStats.online = true;
|
||||
|
||||
// Fetch all data in parallel (with 10 second timeout per operation)
|
||||
// Disk usage can be disabled with SKIP_DF_COLLECTION for Synology NAS devices
|
||||
const [containers, images, volumes, networks, stacks, diskUsage] = await Promise.all([
|
||||
withTimeout(listContainers(true, env.id).catch(() => []), 10000, []),
|
||||
withTimeout(listImages(env.id).catch(() => []), 10000, []),
|
||||
withTimeout(listVolumes(env.id).catch(() => []), 10000, []),
|
||||
withTimeout(listNetworks(env.id).catch(() => []), 10000, []),
|
||||
withTimeout(listComposeStacks(env.id).catch(() => []), 10000, []),
|
||||
withTimeout(getDiskUsage(env.id).catch(() => null), 10000, null)
|
||||
SKIP_DF_COLLECTION ? Promise.resolve(null) : withTimeout(getDiskUsage(env.id).catch(() => null), 10000, null)
|
||||
]);
|
||||
|
||||
// Process containers
|
||||
|
||||
@@ -21,6 +21,9 @@ import { authorize } from '$lib/server/authorize';
|
||||
import type { EnvironmentStats } from '../+server';
|
||||
import { parseLabels } from '$lib/utils/label-colors';
|
||||
|
||||
// Skip disk usage collection (Synology NAS performance fix)
|
||||
const SKIP_DF_COLLECTION = process.env.SKIP_DF_COLLECTION === 'true' || process.env.SKIP_DF_COLLECTION === '1';
|
||||
|
||||
// Helper to add timeout to promises
|
||||
function withTimeout<T>(promise: Promise<T>, ms: number, fallback: T): Promise<T> {
|
||||
return Promise.race([
|
||||
@@ -31,6 +34,7 @@ function withTimeout<T>(promise: Promise<T>, ms: number, fallback: T): Promise<T
|
||||
|
||||
// Disk usage cache - getDiskUsage() is very slow (30s timeout) but data changes rarely
|
||||
// Cache per environment with 5-minute TTL
|
||||
// DISABLED when SKIP_DF_COLLECTION is set (kills Synology NAS devices)
|
||||
interface DiskUsageCache {
|
||||
data: any;
|
||||
timestamp: number;
|
||||
@@ -344,37 +348,49 @@ async function getEnvironmentStatsProgressive(
|
||||
});
|
||||
|
||||
// PHASE 3: Disk usage (slow - includes volumes) - uses cache for better performance
|
||||
const diskUsagePromise = getCachedDiskUsage(env.id)
|
||||
.then((diskUsage) => {
|
||||
if (diskUsage) {
|
||||
// Update images with disk usage data (more accurate)
|
||||
envStats.images.total = diskUsage.Images?.length || envStats.images.total;
|
||||
envStats.images.totalSize = diskUsage.Images?.reduce((sum: number, img: any) => sum + getValidSize(img.Size), 0) || envStats.images.totalSize;
|
||||
|
||||
// Volumes from disk usage
|
||||
envStats.volumes.total = diskUsage.Volumes?.length || 0;
|
||||
envStats.volumes.totalSize = diskUsage.Volumes?.reduce((sum: number, vol: any) => sum + getValidSize(vol.UsageData?.Size), 0) || 0;
|
||||
|
||||
// Containers disk size
|
||||
envStats.containersSize = diskUsage.Containers?.reduce((sum: number, c: any) => sum + getValidSize(c.SizeRw), 0) || 0;
|
||||
|
||||
// Build cache
|
||||
envStats.buildCacheSize = diskUsage.BuildCache?.reduce((sum: number, bc: any) => sum + getValidSize(bc.Size), 0) || 0;
|
||||
}
|
||||
// Can be disabled with SKIP_DF_COLLECTION env var for Synology NAS
|
||||
const diskUsagePromise = SKIP_DF_COLLECTION
|
||||
? Promise.resolve(null).then(() => {
|
||||
envStats.loading!.volumes = false;
|
||||
envStats.loading!.diskUsage = false;
|
||||
|
||||
onPartialUpdate({
|
||||
id: env.id,
|
||||
images: { ...envStats.images },
|
||||
volumes: { ...envStats.volumes },
|
||||
containersSize: envStats.containersSize,
|
||||
buildCacheSize: envStats.buildCacheSize,
|
||||
loading: { ...envStats.loading! }
|
||||
});
|
||||
return null;
|
||||
})
|
||||
: getCachedDiskUsage(env.id)
|
||||
.then((diskUsage) => {
|
||||
if (diskUsage) {
|
||||
// Update images with disk usage data (more accurate)
|
||||
envStats.images.total = diskUsage.Images?.length || envStats.images.total;
|
||||
envStats.images.totalSize = diskUsage.Images?.reduce((sum: number, img: any) => sum + getValidSize(img.Size), 0) || envStats.images.totalSize;
|
||||
|
||||
return diskUsage;
|
||||
});
|
||||
// Volumes from disk usage
|
||||
envStats.volumes.total = diskUsage.Volumes?.length || 0;
|
||||
envStats.volumes.totalSize = diskUsage.Volumes?.reduce((sum: number, vol: any) => sum + getValidSize(vol.UsageData?.Size), 0) || 0;
|
||||
|
||||
// Containers disk size
|
||||
envStats.containersSize = diskUsage.Containers?.reduce((sum: number, c: any) => sum + getValidSize(c.SizeRw), 0) || 0;
|
||||
|
||||
// Build cache
|
||||
envStats.buildCacheSize = diskUsage.BuildCache?.reduce((sum: number, bc: any) => sum + getValidSize(bc.Size), 0) || 0;
|
||||
}
|
||||
envStats.loading!.volumes = false;
|
||||
envStats.loading!.diskUsage = false;
|
||||
|
||||
onPartialUpdate({
|
||||
id: env.id,
|
||||
images: { ...envStats.images },
|
||||
volumes: { ...envStats.volumes },
|
||||
containersSize: envStats.containersSize,
|
||||
buildCacheSize: envStats.buildCacheSize,
|
||||
loading: { ...envStats.loading! }
|
||||
});
|
||||
|
||||
return diskUsage;
|
||||
});
|
||||
|
||||
// PHASE 4: Top containers (slow - requires per-container stats)
|
||||
// Limited to TOP_CONTAINERS_LIMIT containers to reduce API calls
|
||||
|
||||
@@ -36,11 +36,30 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
const stream = new ReadableStream({
|
||||
async start(controller) {
|
||||
const encoder = new TextEncoder();
|
||||
let controllerClosed = false;
|
||||
|
||||
// Safe close helper - prevents "Controller is already closed" errors
|
||||
const safeClose = () => {
|
||||
if (controllerClosed) return;
|
||||
try {
|
||||
controller.close();
|
||||
controllerClosed = true;
|
||||
} catch {
|
||||
// Controller already closed - ignore
|
||||
controllerClosed = true;
|
||||
}
|
||||
};
|
||||
|
||||
// Send initial connection event
|
||||
const sendEvent = (type: string, data: any) => {
|
||||
const event = `event: ${type}\ndata: ${JSON.stringify(data)}\n\n`;
|
||||
controller.enqueue(encoder.encode(event));
|
||||
if (controllerClosed) return;
|
||||
try {
|
||||
const event = `event: ${type}\ndata: ${JSON.stringify(data)}\n\n`;
|
||||
controller.enqueue(encoder.encode(event));
|
||||
} catch {
|
||||
// Controller closed or errored - mark as closed
|
||||
controllerClosed = true;
|
||||
}
|
||||
};
|
||||
|
||||
// Send heartbeat to keep connection alive (every 5s to prevent Traefik 10s idle timeout)
|
||||
@@ -64,7 +83,7 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
if (!eventStream) {
|
||||
sendEvent('error', { message: 'Failed to connect to Docker events' });
|
||||
clearInterval(heartbeatInterval);
|
||||
controller.close();
|
||||
safeClose();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -108,11 +127,17 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('Docker event stream error:', error);
|
||||
sendEvent('error', { message: error.message });
|
||||
// Don't log full stack trace for expected connection errors
|
||||
const isConnectionError = error?.code === 'ECONNRESET' || error?.code === 'ECONNREFUSED';
|
||||
if (isConnectionError) {
|
||||
// Silent - these are handled by event-subprocess reconnection logic
|
||||
} else {
|
||||
console.error('Docker event stream error:', error?.message || error);
|
||||
}
|
||||
sendEvent('error', { message: error?.message || 'Stream connection lost' });
|
||||
} finally {
|
||||
clearInterval(heartbeatInterval);
|
||||
controller.close();
|
||||
safeClose();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -122,11 +147,15 @@ export const GET: RequestHandler = async ({ url }) => {
|
||||
// Expected error when environment doesn't exist - don't spam logs
|
||||
sendEvent('error', { message: 'Environment not found' });
|
||||
} else {
|
||||
console.error('Failed to connect to Docker events:', error);
|
||||
sendEvent('error', { message: error.message || 'Failed to connect to Docker' });
|
||||
// Don't log full stack trace for expected connection errors
|
||||
const isConnectionError = error?.code === 'ECONNRESET' || error?.code === 'ECONNREFUSED';
|
||||
if (!isConnectionError) {
|
||||
console.error('Failed to connect to Docker events:', error?.message || error);
|
||||
}
|
||||
sendEvent('error', { message: error?.message || 'Failed to connect to Docker' });
|
||||
}
|
||||
clearInterval(heartbeatInterval);
|
||||
controller.close();
|
||||
safeClose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getGitStack, updateGitStack, deleteGitStack, deleteStackSource, updateStackSourceName } from '$lib/server/db';
|
||||
import { getGitStack, updateGitStack, deleteGitStack, deleteStackSource, updateStackSourceName, updateStackEnvVarsName } from '$lib/server/db';
|
||||
import { deleteGitStackFiles, deployGitStack } from '$lib/server/git';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import { registerSchedule, unregisterSchedule } from '$lib/server/scheduler';
|
||||
@@ -71,9 +71,10 @@ export const PUT: RequestHandler = async ({ params, request, cookies }) => {
|
||||
webhookSecret: data.webhookSecret
|
||||
});
|
||||
|
||||
// If stack name changed, update the stack_sources record too
|
||||
// If stack name changed, update related records
|
||||
if (data.stackName && data.stackName !== oldStackName) {
|
||||
await updateStackSourceName(oldStackName, data.stackName, existing.environmentId);
|
||||
await updateStackEnvVarsName(oldStackName, data.stackName, existing.environmentId);
|
||||
}
|
||||
|
||||
// Register or unregister schedule with croner
|
||||
|
||||
@@ -3,6 +3,9 @@ import { getDiskUsage } from '$lib/server/docker';
|
||||
import { authorize } from '$lib/server/authorize';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
// Skip disk usage collection (Synology NAS performance fix)
|
||||
const SKIP_DF_COLLECTION = process.env.SKIP_DF_COLLECTION === 'true' || process.env.SKIP_DF_COLLECTION === '1';
|
||||
|
||||
const DISK_USAGE_TIMEOUT = 15000; // 15 second timeout
|
||||
|
||||
export const GET: RequestHandler = async ({ url, cookies }) => {
|
||||
@@ -23,6 +26,11 @@ export const GET: RequestHandler = async ({ url, cookies }) => {
|
||||
return json({ error: 'Access denied to this environment' }, { status: 403 });
|
||||
}
|
||||
|
||||
// Skip disk usage when disabled (Synology NAS performance fix)
|
||||
if (SKIP_DF_COLLECTION) {
|
||||
return json({ diskUsage: null });
|
||||
}
|
||||
|
||||
try {
|
||||
// Fetch disk usage with timeout
|
||||
const diskUsagePromise = getDiskUsage(envId);
|
||||
|
||||
@@ -68,20 +68,20 @@
|
||||
|
||||
interface AuditLogEntry {
|
||||
id: number;
|
||||
user_id: number | null;
|
||||
userId: number | null;
|
||||
username: string;
|
||||
action: string;
|
||||
entity_type: string;
|
||||
entity_id: string | null;
|
||||
entity_name: string | null;
|
||||
environment_id: number | null;
|
||||
environment_name: string | null;
|
||||
environment_icon: string | null;
|
||||
entityType: string;
|
||||
entityId: string | null;
|
||||
entityName: string | null;
|
||||
environmentId: number | null;
|
||||
environmentName: string | null;
|
||||
environmentIcon: string | null;
|
||||
description: string | null;
|
||||
details: any | null;
|
||||
ip_address: string | null;
|
||||
user_agent: string | null;
|
||||
timestamp: string;
|
||||
ipAddress: string | null;
|
||||
userAgent: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface Environment {
|
||||
@@ -555,16 +555,16 @@
|
||||
function handleNewAuditEvent(event: SSEAuditLogEntry) {
|
||||
// Check if event matches current filters
|
||||
if (filterUsernames.length > 0 && !filterUsernames.includes(event.username)) return;
|
||||
if (filterEntityTypes.length > 0 && !filterEntityTypes.includes(event.entity_type)) return;
|
||||
if (filterEntityTypes.length > 0 && !filterEntityTypes.includes(event.entityType)) return;
|
||||
if (filterActions.length > 0 && !filterActions.includes(event.action)) return;
|
||||
|
||||
// Check date filters
|
||||
if (filterFromDate) {
|
||||
const eventDate = new Date(event.timestamp).toISOString().split('T')[0];
|
||||
const eventDate = new Date(event.createdAt).toISOString().split('T')[0];
|
||||
if (eventDate < filterFromDate) return;
|
||||
}
|
||||
if (filterToDate) {
|
||||
const eventDate = new Date(event.timestamp).toISOString().split('T')[0];
|
||||
const eventDate = new Date(event.createdAt).toISOString().split('T')[0];
|
||||
if (eventDate > filterToDate) return;
|
||||
}
|
||||
|
||||
@@ -981,14 +981,14 @@
|
||||
onkeydown={(e) => e.key === 'Enter' && showDetails(log)}
|
||||
>
|
||||
<div class="px-2 font-mono whitespace-nowrap">
|
||||
{formatTimestamp(log.timestamp)}
|
||||
{formatTimestamp(log.createdAt)}
|
||||
</div>
|
||||
<div class="px-2">
|
||||
{#if log.environment_name}
|
||||
{@const LogEnvIcon = getIconComponent(log.environment_icon || 'globe')}
|
||||
{#if log.environmentName}
|
||||
{@const LogEnvIcon = getIconComponent(log.environmentIcon || 'globe')}
|
||||
<div class="flex items-center gap-1 truncate">
|
||||
<LogEnvIcon class="w-3 h-3 text-muted-foreground shrink-0" />
|
||||
<span class="truncate">{log.environment_name}</span>
|
||||
<span class="truncate">{log.environmentName}</span>
|
||||
</div>
|
||||
{:else}
|
||||
<span class="text-muted-foreground">-</span>
|
||||
@@ -1007,17 +1007,17 @@
|
||||
</div>
|
||||
<div class="px-2">
|
||||
<div class="flex items-center gap-1 truncate">
|
||||
<svelte:component this={getEntityIcon(log.entity_type)} class="w-3 h-3 text-muted-foreground shrink-0" />
|
||||
<span class="truncate">{log.entity_type}</span>
|
||||
<svelte:component this={getEntityIcon(log.entityType)} class="w-3 h-3 text-muted-foreground shrink-0" />
|
||||
<span class="truncate">{log.entityType}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="px-2">
|
||||
<span class="truncate" title={log.entity_name || log.entity_id || '-'}>
|
||||
{log.entity_name || log.entity_id || '-'}
|
||||
<span class="truncate" title={log.entityName || log.entityId || '-'}>
|
||||
{log.entityName || log.entityId || '-'}
|
||||
</span>
|
||||
</div>
|
||||
<div class="px-2 font-mono text-muted-foreground">
|
||||
{log.ip_address || '-'}
|
||||
{log.ipAddress || '-'}
|
||||
</div>
|
||||
<div class="px-2 flex items-center justify-center">
|
||||
<Button variant="ghost" size="sm" onclick={(e) => { e.stopPropagation(); showDetails(log); }}>
|
||||
@@ -1060,7 +1060,7 @@
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">Timestamp</label>
|
||||
<p class="font-mono text-sm">{formatTimestamp(selectedLog.timestamp)}</p>
|
||||
<p class="font-mono text-sm">{formatTimestamp(selectedLog.createdAt)}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">User</label>
|
||||
@@ -1081,32 +1081,32 @@
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">Entity type</label>
|
||||
<p class="flex items-center gap-1">
|
||||
<svelte:component this={getEntityIcon(selectedLog.entity_type)} class="w-4 h-4 text-muted-foreground" />
|
||||
{selectedLog.entity_type}
|
||||
<svelte:component this={getEntityIcon(selectedLog.entityType)} class="w-4 h-4 text-muted-foreground" />
|
||||
{selectedLog.entityType}
|
||||
</p>
|
||||
</div>
|
||||
{#if selectedLog.entity_name}
|
||||
{#if selectedLog.entityName}
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">Entity name</label>
|
||||
<p>{selectedLog.entity_name}</p>
|
||||
<p>{selectedLog.entityName}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if selectedLog.entity_id}
|
||||
{#if selectedLog.entityId}
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">Entity ID</label>
|
||||
<p class="font-mono text-sm break-all">{selectedLog.entity_id}</p>
|
||||
<p class="font-mono text-sm break-all">{selectedLog.entityId}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if selectedLog.environment_id}
|
||||
{#if selectedLog.environmentId}
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">Environment ID</label>
|
||||
<p>{selectedLog.environment_id}</p>
|
||||
<p>{selectedLog.environmentId}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{#if selectedLog.ip_address}
|
||||
{#if selectedLog.ipAddress}
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">IP address</label>
|
||||
<p class="font-mono text-sm">{selectedLog.ip_address}</p>
|
||||
<p class="font-mono text-sm">{selectedLog.ipAddress}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1118,10 +1118,10 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if selectedLog.user_agent}
|
||||
{#if selectedLog.userAgent}
|
||||
<div>
|
||||
<label class="text-sm font-medium text-muted-foreground">User agent</label>
|
||||
<p class="text-xs text-muted-foreground break-all">{selectedLog.user_agent}</p>
|
||||
<p class="text-xs text-muted-foreground break-all">{selectedLog.userAgent}</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
current_password: currentPassword,
|
||||
new_password: newPassword
|
||||
currentPassword: currentPassword,
|
||||
newPassword: newPassword
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -264,6 +264,16 @@
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
// Clear state BEFORE async loads to avoid race conditions
|
||||
formError = '';
|
||||
errors = {};
|
||||
copiedWebhookUrl = false;
|
||||
copiedWebhookSecret = false;
|
||||
envFiles = [];
|
||||
envVars = [];
|
||||
fileEnvVars = {};
|
||||
existingSecretKeys = new Set();
|
||||
|
||||
if (gitStack) {
|
||||
formRepoMode = 'existing';
|
||||
formRepositoryId = gitStack.repositoryId;
|
||||
@@ -275,7 +285,7 @@
|
||||
formWebhookEnabled = gitStack.webhookEnabled;
|
||||
formWebhookSecret = gitStack.webhookSecret || '';
|
||||
formDeployNow = false;
|
||||
// Load env files and overrides for editing
|
||||
// Load env files and overrides for editing (async - will populate envFiles, envVars, fileEnvVars)
|
||||
loadEnvFiles();
|
||||
loadEnvVarsOverrides();
|
||||
if (gitStack.envFilePath) {
|
||||
@@ -298,14 +308,6 @@
|
||||
formWebhookSecret = '';
|
||||
formDeployNow = false;
|
||||
}
|
||||
formError = '';
|
||||
errors = {};
|
||||
copiedWebhookUrl = false;
|
||||
copiedWebhookSecret = false;
|
||||
envFiles = [];
|
||||
envVars = [];
|
||||
fileEnvVars = {};
|
||||
existingSecretKeys = new Set();
|
||||
}
|
||||
|
||||
async function saveGitStack(deployAfterSave: boolean = false) {
|
||||
@@ -392,30 +394,29 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// Save environment variable overrides if we have any
|
||||
// Save environment variable overrides (always save to ensure DB is in sync)
|
||||
// This handles both adding new vars and clearing all vars
|
||||
const definedVars = envVars.filter(v => v.key.trim());
|
||||
if (definedVars.length > 0) {
|
||||
try {
|
||||
const envResponse = await fetch(
|
||||
`/api/stacks/${encodeURIComponent(formStackName)}/env${environmentId ? `?env=${environmentId}` : ''}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
variables: definedVars.map(v => ({
|
||||
key: v.key.trim(),
|
||||
value: v.value,
|
||||
isSecret: v.isSecret
|
||||
}))
|
||||
})
|
||||
}
|
||||
);
|
||||
if (!envResponse.ok) {
|
||||
console.error('Failed to save environment variables');
|
||||
try {
|
||||
const envResponse = await fetch(
|
||||
`/api/stacks/${encodeURIComponent(formStackName)}/env${environmentId ? `?env=${environmentId}` : ''}`,
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
variables: definedVars.map(v => ({
|
||||
key: v.key.trim(),
|
||||
value: v.value,
|
||||
isSecret: v.isSecret
|
||||
}))
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to save environment variables:', e);
|
||||
);
|
||||
if (!envResponse.ok) {
|
||||
console.error('Failed to save environment variables');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to save environment variables:', e);
|
||||
}
|
||||
|
||||
onSaved();
|
||||
|
||||
@@ -84,6 +84,9 @@
|
||||
// Path source info (for hint display)
|
||||
let pathSource = $state<'default' | 'custom' | 'browsed' | null>(null);
|
||||
|
||||
// Base directory when user browsed to a directory (without stack name yet)
|
||||
let browsedBaseDirectory = $state<string | null>(null);
|
||||
|
||||
// UI state
|
||||
let composePathCopied = $state(false);
|
||||
let envPathCopied = $state(false);
|
||||
@@ -112,7 +115,12 @@
|
||||
|
||||
// Derived: source hint text for the path bar (only in create mode)
|
||||
const pathSourceHint = $derived.by(() => {
|
||||
if (mode !== 'create' || !workingComposePath) return undefined;
|
||||
if (mode !== 'create') return undefined;
|
||||
// Show hint when user selected a directory but hasn't entered stack name yet
|
||||
if (browsedBaseDirectory && !workingComposePath) {
|
||||
return `Will create in ${browsedBaseDirectory}/`;
|
||||
}
|
||||
if (!workingComposePath) return undefined;
|
||||
switch (pathSource) {
|
||||
case 'browsed':
|
||||
return 'Custom location';
|
||||
@@ -372,25 +380,52 @@
|
||||
|
||||
if (isDirectory) {
|
||||
const stackName = newStackName.trim();
|
||||
// Store the base directory so effect can rebuild path if user changes stack name
|
||||
browsedBaseDirectory = baseDir;
|
||||
if (stackName) {
|
||||
// If we have a stack name, include the subfolder
|
||||
// If we have a stack name, build the full path with subfolder
|
||||
finalPath = `${baseDir}/${stackName}/compose.yaml`;
|
||||
} else {
|
||||
// No stack name yet - just show the selected directory
|
||||
finalPath = `${baseDir}/`;
|
||||
// No stack name yet - path will be completed when stack name is entered
|
||||
finalPath = ''; // Don't set incomplete path
|
||||
pathSource = 'browsed';
|
||||
showFileBrowser = false;
|
||||
isDirty = true;
|
||||
return; // Exit early - path will be completed when stack name is entered
|
||||
}
|
||||
} else {
|
||||
browsedBaseDirectory = null; // Selected a file, not a directory
|
||||
}
|
||||
|
||||
// In CREATE mode, we only want the content - don't store external paths
|
||||
// Files will be saved to internal stack directory
|
||||
if (mode === 'create') {
|
||||
pathSource = 'browsed';
|
||||
showFileBrowser = false;
|
||||
|
||||
// Load compose file content when selecting a file (not directory)
|
||||
if (!isDirectory) {
|
||||
// Build potential env path in same directory as compose file
|
||||
const dir = finalPath.replace(/\/[^/]+$/, '');
|
||||
const potentialEnvPath = `${dir}/.env`;
|
||||
await loadFilesFromLocalFilesystem(finalPath, potentialEnvPath);
|
||||
// Don't set workingComposePath/workingEnvPath - use internal defaults
|
||||
workingComposePath = '';
|
||||
workingEnvPath = '';
|
||||
}
|
||||
isDirty = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// EDIT mode - store the selected path
|
||||
workingComposePath = finalPath;
|
||||
pathSource = 'browsed';
|
||||
showFileBrowser = false;
|
||||
|
||||
// Auto-suggest .env in the same directory (only if we have a full path)
|
||||
if (!isDirectory || newStackName.trim()) {
|
||||
const dir = finalPath.replace(/\/[^/]+$/, '');
|
||||
if (!workingEnvPath) {
|
||||
workingEnvPath = `${dir}/.env`;
|
||||
}
|
||||
// Auto-suggest .env in the same directory
|
||||
const dir = finalPath.replace(/\/[^/]+$/, '');
|
||||
if (!workingEnvPath) {
|
||||
workingEnvPath = `${dir}/.env`;
|
||||
}
|
||||
|
||||
// Load compose file content when selecting a file (not directory)
|
||||
@@ -427,7 +462,6 @@
|
||||
finalPath = path.endsWith('/') ? `${path}.env` : `${path}/.env`;
|
||||
}
|
||||
|
||||
workingEnvPath = finalPath;
|
||||
showFileBrowser = false;
|
||||
|
||||
// Load env content when selecting a file (not directory)
|
||||
@@ -445,6 +479,14 @@
|
||||
console.error('Failed to load env file:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// In CREATE mode, don't store external path - content will be saved to internal directory
|
||||
// In EDIT mode, store the path for the file location
|
||||
if (mode !== 'create') {
|
||||
workingEnvPath = finalPath;
|
||||
}
|
||||
// If CREATE mode, workingEnvPath stays empty - will use internal default
|
||||
|
||||
isDirty = true;
|
||||
}
|
||||
|
||||
@@ -456,7 +498,10 @@
|
||||
if (composeResponse.ok) {
|
||||
const composeData = await composeResponse.json();
|
||||
composeContent = composeData.content || '';
|
||||
workingComposePath = composeFilePath;
|
||||
// Only set workingComposePath in EDIT mode - CREATE mode uses internal defaults
|
||||
if (mode !== 'create') {
|
||||
workingComposePath = composeFilePath;
|
||||
}
|
||||
// Clear the needsFileLocation flag since we now have content
|
||||
needsFileLocation = false;
|
||||
stackContainers = [];
|
||||
@@ -465,18 +510,23 @@
|
||||
console.error('Failed to load compose file:', err.error);
|
||||
}
|
||||
|
||||
// Try to load .env file (only set workingEnvPath if it exists)
|
||||
// Try to load .env file (only set workingEnvPath if it exists AND we're in edit mode)
|
||||
if (envFilePath) {
|
||||
const envResponse = await fetch(`/api/system/files/content?path=${encodeURIComponent(envFilePath)}`);
|
||||
if (envResponse.ok) {
|
||||
const envData = await envResponse.json();
|
||||
rawEnvContent = envData.content || '';
|
||||
workingEnvPath = envFilePath;
|
||||
// Only set workingEnvPath in EDIT mode - CREATE mode uses internal defaults
|
||||
if (mode !== 'create') {
|
||||
workingEnvPath = envFilePath;
|
||||
}
|
||||
parseEnvVarsFromRaw(rawEnvContent);
|
||||
} else {
|
||||
// .env file not found - clear env path
|
||||
rawEnvContent = '';
|
||||
workingEnvPath = '';
|
||||
if (mode !== 'create') {
|
||||
workingEnvPath = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -891,7 +941,7 @@ services:
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSave(restart = false, moveFromDir: string | null = null) {
|
||||
async function handleSave(restart = false, moveFromDir: string | null | undefined = undefined) {
|
||||
errors = {};
|
||||
|
||||
// Validate compose content (unless file location is needed and we have a path)
|
||||
@@ -909,7 +959,8 @@ services:
|
||||
const envId = $currentEnvironment?.id ?? null;
|
||||
|
||||
// Check if directory has changed (edit mode only, and not already confirmed)
|
||||
if (mode === 'edit' && !moveFromDir) {
|
||||
// Use === undefined to distinguish "not checked yet" from "keep files" (empty string)
|
||||
if (mode === 'edit' && moveFromDir === undefined) {
|
||||
const newComposePath = workingComposePath.trim() || null;
|
||||
|
||||
// Only check if compose path changed (which means directory changed)
|
||||
@@ -1070,7 +1121,7 @@ services:
|
||||
// Handle path change - keep old files and proceed (just save without moving)
|
||||
function confirmPathChangeKeepFiles() {
|
||||
showPathChangeConfirm = false;
|
||||
// Pass empty string to skip move check this time (not null, which means "not checked yet")
|
||||
// Pass empty string to skip move check (undefined means "not checked yet")
|
||||
handleSave(pendingSaveRestart, '');
|
||||
}
|
||||
|
||||
@@ -1111,6 +1162,7 @@ services:
|
||||
originalEnvPath = null;
|
||||
autoComputedComposePath = '';
|
||||
pathSource = null;
|
||||
browsedBaseDirectory = null;
|
||||
needsFileLocation = false;
|
||||
stackContainers = [];
|
||||
showFileBrowser = false;
|
||||
@@ -1169,16 +1221,14 @@ services:
|
||||
});
|
||||
|
||||
// Auto-update default paths when stack name changes in create mode
|
||||
// This unified effect handles both default paths and browsed directory paths
|
||||
$effect(() => {
|
||||
if (mode !== 'create' || !open) return;
|
||||
// Don't overwrite if user has browsed and selected a path
|
||||
if (pathSource === 'browsed') return;
|
||||
|
||||
const name = newStackName.trim();
|
||||
const location = $appSettings.primaryStackLocation;
|
||||
|
||||
// Case 1: No name entered yet - clear paths
|
||||
if (!name) {
|
||||
// Clear paths when no name
|
||||
workingComposePath = '';
|
||||
workingEnvPath = '';
|
||||
autoComputedComposePath = '';
|
||||
@@ -1186,8 +1236,35 @@ services:
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the actual absolute path from the backend
|
||||
// Case 2: User has browsed and selected a directory - use that as base
|
||||
// Keep updating as user types (don't clear browsedBaseDirectory!)
|
||||
if (browsedBaseDirectory) {
|
||||
workingComposePath = `${browsedBaseDirectory}/${name}/compose.yaml`;
|
||||
workingEnvPath = `${browsedBaseDirectory}/${name}/.env`;
|
||||
pathSource = 'browsed';
|
||||
return;
|
||||
}
|
||||
|
||||
// Case 3: User already has a browsed path set (from previous name entry)
|
||||
// Update the stack name portion in the existing path
|
||||
if (pathSource === 'browsed' && workingComposePath) {
|
||||
// Extract base directory from existing path and rebuild with new name
|
||||
// Path format: {baseDir}/{stackName}/compose.yaml
|
||||
const pathParts = workingComposePath.split('/');
|
||||
pathParts.pop(); // remove 'compose.yaml'
|
||||
pathParts.pop(); // remove old stack name
|
||||
const baseDir = pathParts.join('/');
|
||||
if (baseDir) {
|
||||
workingComposePath = `${baseDir}/${name}/compose.yaml`;
|
||||
workingEnvPath = `${baseDir}/${name}/.env`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Case 4: Default path from settings/API
|
||||
const location = $appSettings.primaryStackLocation;
|
||||
const envId = $currentEnvironment?.id ?? null;
|
||||
|
||||
const fetchDefaultPath = async () => {
|
||||
try {
|
||||
const params = new URLSearchParams({ name });
|
||||
|
||||
Reference in new issue
Block a user