1.0.13
This commit is contained in:
1 parent
a88d3d5788
commit
8f3a7eb435
96 files changed
+5235
-1870
No files matched your search
@@ -8,13 +8,29 @@
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Plus, Trash2, HardDrive, Database, Server } from 'lucide-svelte';
|
||||
import { TogglePill } from '$lib/components/ui/toggle-pill';
|
||||
import { Plus, Trash2, HardDrive, Database, Server, ChevronDown } from 'lucide-svelte';
|
||||
|
||||
const VOLUME_DRIVERS = [
|
||||
{ value: 'local', label: 'Local', description: 'Default local driver', icon: HardDrive },
|
||||
{ value: 'nfs', label: 'NFS', description: 'Network file system', icon: Server },
|
||||
{ value: 'cifs', label: 'CIFS', description: 'Windows/SMB shares', icon: Database }
|
||||
];
|
||||
|
||||
const SMB_VERSIONS = [
|
||||
{ value: '2.0', label: 'SMB 2.0' },
|
||||
{ value: '2.1', label: 'SMB 2.1' },
|
||||
{ value: '3.0', label: 'SMB 3.0' },
|
||||
{ value: '3.1.1', label: 'SMB 3.1.1' }
|
||||
];
|
||||
|
||||
const NFS_VERSIONS = [
|
||||
{ value: '3', label: 'NFSv3' },
|
||||
{ value: '4', label: 'NFSv4' },
|
||||
{ value: '4.1', label: 'NFSv4.1' },
|
||||
{ value: '4.2', label: 'NFSv4.2' }
|
||||
];
|
||||
|
||||
import { currentEnvironment, appendEnvParam } from '$lib/stores/environment';
|
||||
import { focusFirstInput } from '$lib/utils';
|
||||
|
||||
@@ -32,9 +48,28 @@
|
||||
let driverOpts = $state<KeyValue[]>([]);
|
||||
let labels = $state<KeyValue[]>([]);
|
||||
|
||||
// CIFS fields
|
||||
let cifsServer = $state('');
|
||||
let cifsShare = $state('');
|
||||
let cifsUsername = $state('');
|
||||
let cifsPassword = $state('');
|
||||
let cifsVersion = $state('3.0');
|
||||
let cifsDomain = $state('');
|
||||
|
||||
// NFS fields
|
||||
let nfsServer = $state('');
|
||||
let nfsPath = $state('');
|
||||
let nfsVersion = $state('4');
|
||||
let nfsSoft = $state(true);
|
||||
let nfsNolock = $state(true);
|
||||
let nfsReadOnly = $state(false);
|
||||
|
||||
// Additional options visibility
|
||||
let showAdditionalOpts = $state(false);
|
||||
|
||||
let creating = $state(false);
|
||||
let error = $state('');
|
||||
let errors = $state<{ name?: string }>({});
|
||||
let errors = $state<{ name?: string; server?: string; share?: string; path?: string }>({});
|
||||
|
||||
function addDriverOpt() {
|
||||
driverOpts = [...driverOpts, { key: '', value: '' }];
|
||||
@@ -57,6 +92,19 @@
|
||||
driver = 'local';
|
||||
driverOpts = [];
|
||||
labels = [];
|
||||
cifsServer = '';
|
||||
cifsShare = '';
|
||||
cifsUsername = '';
|
||||
cifsPassword = '';
|
||||
cifsVersion = '3.0';
|
||||
cifsDomain = '';
|
||||
nfsServer = '';
|
||||
nfsPath = '';
|
||||
nfsVersion = '4';
|
||||
nfsSoft = true;
|
||||
nfsNolock = true;
|
||||
nfsReadOnly = false;
|
||||
showAdditionalOpts = false;
|
||||
error = '';
|
||||
errors = {};
|
||||
}
|
||||
@@ -66,22 +114,62 @@
|
||||
|
||||
if (!name.trim()) {
|
||||
errors.name = 'Volume name is required';
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate driver-specific required fields
|
||||
if (driver === 'cifs') {
|
||||
if (!cifsServer.trim()) errors.server = 'Server is required';
|
||||
if (!cifsShare.trim()) errors.share = 'Share path is required';
|
||||
} else if (driver === 'nfs') {
|
||||
if (!nfsServer.trim()) errors.server = 'Server is required';
|
||||
if (!nfsPath.trim()) errors.path = 'Export path is required';
|
||||
}
|
||||
|
||||
if (Object.keys(errors).length > 0) return;
|
||||
|
||||
creating = true;
|
||||
error = '';
|
||||
|
||||
try {
|
||||
const envId = $currentEnvironment?.id ?? null;
|
||||
|
||||
// Convert key-value arrays to objects
|
||||
// Build driverOpts based on driver type
|
||||
const driverOptsObj: Record<string, string> = {};
|
||||
driverOpts.forEach(({ key, value }) => {
|
||||
if (key && value) {
|
||||
driverOptsObj[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
if (driver === 'cifs') {
|
||||
driverOptsObj.type = 'cifs';
|
||||
const share = cifsShare.trim().replace(/^\/+/, '');
|
||||
driverOptsObj.device = `//${cifsServer.trim()}/${share}`;
|
||||
const opts = [`addr=${cifsServer.trim()}`, `username=${cifsUsername}`, `password=${cifsPassword}`, `vers=${cifsVersion}`];
|
||||
if (cifsDomain.trim()) opts.push(`domain=${cifsDomain.trim()}`);
|
||||
// Append additional options
|
||||
driverOpts.forEach(({ key, value }) => {
|
||||
if (key && value) opts.push(`${key}=${value}`);
|
||||
else if (key) opts.push(key);
|
||||
});
|
||||
driverOptsObj.o = opts.join(',');
|
||||
} else if (driver === 'nfs') {
|
||||
driverOptsObj.type = 'nfs';
|
||||
const path = nfsPath.trim().startsWith('/') ? nfsPath.trim() : `/${nfsPath.trim()}`;
|
||||
driverOptsObj.device = `:${path}`;
|
||||
const opts = [`addr=${nfsServer.trim()}`, `nfsvers=${nfsVersion}`];
|
||||
if (nfsSoft) opts.push('soft');
|
||||
if (nfsNolock) opts.push('nolock');
|
||||
if (nfsReadOnly) opts.push('ro');
|
||||
// Append additional options
|
||||
driverOpts.forEach(({ key, value }) => {
|
||||
if (key && value) opts.push(`${key}=${value}`);
|
||||
else if (key) opts.push(key);
|
||||
});
|
||||
driverOptsObj.o = opts.join(',');
|
||||
} else {
|
||||
// Local driver - use generic key-value pairs
|
||||
driverOpts.forEach(({ key, value }) => {
|
||||
if (key && value) {
|
||||
driverOptsObj[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const labelsObj: Record<string, string> = {};
|
||||
labels.forEach(({ key, value }) => {
|
||||
@@ -95,7 +183,7 @@
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name: name.trim(),
|
||||
driver,
|
||||
driver: driver === 'nfs' || driver === 'cifs' ? 'local' : driver,
|
||||
driverOpts: driverOptsObj,
|
||||
labels: labelsObj
|
||||
})
|
||||
@@ -186,53 +274,263 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Driver Options -->
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<Label>Driver options</Label>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onclick={addDriverOpt}
|
||||
disabled={creating}
|
||||
>
|
||||
<Plus class="w-3 h-3 mr-1" />
|
||||
Add option
|
||||
</Button>
|
||||
</div>
|
||||
{#if driverOpts.length > 0}
|
||||
<!-- Driver-specific fields -->
|
||||
{#if driver === 'cifs'}
|
||||
<!-- CIFS fields -->
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
{#each driverOpts as opt, i}
|
||||
<div class="flex gap-2">
|
||||
<Input
|
||||
bind:value={opt.key}
|
||||
placeholder="Key"
|
||||
disabled={creating}
|
||||
class="flex-1"
|
||||
/>
|
||||
<Input
|
||||
bind:value={opt.value}
|
||||
placeholder="Value"
|
||||
disabled={creating}
|
||||
class="flex-1"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
onclick={() => removeDriverOpt(i)}
|
||||
disabled={creating}
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
<Label for="cifs-server">Server / IP *</Label>
|
||||
<Input
|
||||
id="cifs-server"
|
||||
bind:value={cifsServer}
|
||||
placeholder="192.168.1.100"
|
||||
disabled={creating}
|
||||
class={errors.server ? 'border-destructive focus-visible:ring-destructive' : ''}
|
||||
oninput={() => errors.server = undefined}
|
||||
/>
|
||||
{#if errors.server}
|
||||
<p class="text-xs text-destructive">{errors.server}</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="cifs-share">Share path *</Label>
|
||||
<Input
|
||||
id="cifs-share"
|
||||
bind:value={cifsShare}
|
||||
placeholder="shared/folder"
|
||||
disabled={creating}
|
||||
class={errors.share ? 'border-destructive focus-visible:ring-destructive' : ''}
|
||||
oninput={() => errors.share = undefined}
|
||||
/>
|
||||
{#if errors.share}
|
||||
<p class="text-xs text-destructive">{errors.share}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="cifs-username">Username</Label>
|
||||
<Input
|
||||
id="cifs-username"
|
||||
bind:value={cifsUsername}
|
||||
placeholder="user"
|
||||
disabled={creating}
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="cifs-password">Password</Label>
|
||||
<Input
|
||||
id="cifs-password"
|
||||
type="password"
|
||||
bind:value={cifsPassword}
|
||||
placeholder="••••••••"
|
||||
disabled={creating}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="cifs-version">SMB version</Label>
|
||||
<Select.Root type="single" bind:value={cifsVersion} disabled={creating}>
|
||||
<Select.Trigger class="w-full h-9">
|
||||
{SMB_VERSIONS.find(v => v.value === cifsVersion)?.label ?? 'Select version'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each SMB_VERSIONS as v}
|
||||
<Select.Item value={v.value} label={v.label}>{v.label}</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="cifs-domain">Domain</Label>
|
||||
<Input
|
||||
id="cifs-domain"
|
||||
bind:value={cifsDomain}
|
||||
placeholder="WORKGROUP"
|
||||
disabled={creating}
|
||||
/>
|
||||
<p class="text-xs text-muted-foreground">Optional AD/workgroup domain</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Additional options (collapsible) -->
|
||||
<div class="space-y-2">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
onclick={() => showAdditionalOpts = !showAdditionalOpts}
|
||||
>
|
||||
<ChevronDown class="w-3.5 h-3.5 transition-transform {showAdditionalOpts ? 'rotate-180' : ''}" />
|
||||
Additional options
|
||||
</button>
|
||||
{#if showAdditionalOpts}
|
||||
<div class="space-y-2 pl-1">
|
||||
<div class="flex items-center justify-end">
|
||||
<Button type="button" size="sm" variant="outline" onclick={addDriverOpt} disabled={creating}>
|
||||
<Plus class="w-3 h-3 mr-1" />
|
||||
Add option
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
{#if driverOpts.length > 0}
|
||||
{#each driverOpts as opt, i}
|
||||
<div class="flex gap-2">
|
||||
<Input bind:value={opt.key} placeholder="Key" disabled={creating} class="flex-1" />
|
||||
<Input bind:value={opt.value} placeholder="Value (optional)" disabled={creating} class="flex-1" />
|
||||
<Button type="button" size="icon" variant="ghost" onclick={() => removeDriverOpt(i)} disabled={creating}>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-xs text-muted-foreground">Extra mount options appended to the mount string</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if driver === 'nfs'}
|
||||
<!-- NFS fields -->
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div class="space-y-2">
|
||||
<Label for="nfs-server">Server / IP *</Label>
|
||||
<Input
|
||||
id="nfs-server"
|
||||
bind:value={nfsServer}
|
||||
placeholder="192.168.1.100"
|
||||
disabled={creating}
|
||||
class={errors.server ? 'border-destructive focus-visible:ring-destructive' : ''}
|
||||
oninput={() => errors.server = undefined}
|
||||
/>
|
||||
{#if errors.server}
|
||||
<p class="text-xs text-destructive">{errors.server}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-xs text-muted-foreground">No driver options configured</p>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="nfs-path">Export path *</Label>
|
||||
<Input
|
||||
id="nfs-path"
|
||||
bind:value={nfsPath}
|
||||
placeholder="/exports/data"
|
||||
disabled={creating}
|
||||
class={errors.path ? 'border-destructive focus-visible:ring-destructive' : ''}
|
||||
oninput={() => errors.path = undefined}
|
||||
/>
|
||||
{#if errors.path}
|
||||
<p class="text-xs text-destructive">{errors.path}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<Label for="nfs-version">NFS version</Label>
|
||||
<Select.Root type="single" bind:value={nfsVersion} disabled={creating}>
|
||||
<Select.Trigger class="w-full max-w-[200px] h-9">
|
||||
{NFS_VERSIONS.find(v => v.value === nfsVersion)?.label ?? 'Select version'}
|
||||
</Select.Trigger>
|
||||
<Select.Content>
|
||||
{#each NFS_VERSIONS as v}
|
||||
<Select.Item value={v.value} label={v.label}>{v.label}</Select.Item>
|
||||
{/each}
|
||||
</Select.Content>
|
||||
</Select.Root>
|
||||
</div>
|
||||
<div class="flex items-center gap-6">
|
||||
<div class="flex items-center gap-2">
|
||||
<TogglePill bind:checked={nfsSoft} onLabel="Soft" offLabel="Hard" />
|
||||
<span class="text-xs text-muted-foreground">mount</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<TogglePill bind:checked={nfsNolock} />
|
||||
<span class="text-xs text-muted-foreground">No lock</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<TogglePill bind:checked={nfsReadOnly} />
|
||||
<span class="text-xs text-muted-foreground">Read-only</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Additional options (collapsible) -->
|
||||
<div class="space-y-2">
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
onclick={() => showAdditionalOpts = !showAdditionalOpts}
|
||||
>
|
||||
<ChevronDown class="w-3.5 h-3.5 transition-transform {showAdditionalOpts ? 'rotate-180' : ''}" />
|
||||
Additional options
|
||||
</button>
|
||||
{#if showAdditionalOpts}
|
||||
<div class="space-y-2 pl-1">
|
||||
<div class="flex items-center justify-end">
|
||||
<Button type="button" size="sm" variant="outline" onclick={addDriverOpt} disabled={creating}>
|
||||
<Plus class="w-3 h-3 mr-1" />
|
||||
Add option
|
||||
</Button>
|
||||
</div>
|
||||
{#if driverOpts.length > 0}
|
||||
{#each driverOpts as opt, i}
|
||||
<div class="flex gap-2">
|
||||
<Input bind:value={opt.key} placeholder="Key" disabled={creating} class="flex-1" />
|
||||
<Input bind:value={opt.value} placeholder="Value (optional)" disabled={creating} class="flex-1" />
|
||||
<Button type="button" size="icon" variant="ghost" onclick={() => removeDriverOpt(i)} disabled={creating}>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
<p class="text-xs text-muted-foreground">Extra mount options appended to the mount string</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Local driver - generic key-value options -->
|
||||
<div class="space-y-2">
|
||||
<div class="flex items-center justify-between">
|
||||
<Label>Driver options</Label>
|
||||
<Button
|
||||
type="button"
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onclick={addDriverOpt}
|
||||
disabled={creating}
|
||||
>
|
||||
<Plus class="w-3 h-3 mr-1" />
|
||||
Add option
|
||||
</Button>
|
||||
</div>
|
||||
{#if driverOpts.length > 0}
|
||||
<div class="space-y-2">
|
||||
{#each driverOpts as opt, i}
|
||||
<div class="flex gap-2">
|
||||
<Input
|
||||
bind:value={opt.key}
|
||||
placeholder="Key"
|
||||
disabled={creating}
|
||||
class="flex-1"
|
||||
/>
|
||||
<Input
|
||||
bind:value={opt.value}
|
||||
placeholder="Value"
|
||||
disabled={creating}
|
||||
class="flex-1"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
onclick={() => removeDriverOpt(i)}
|
||||
disabled={creating}
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</Button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="text-xs text-muted-foreground">No driver options configured</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Labels -->
|
||||
<div class="space-y-2">
|
||||
|
||||
Reference in new issue
Block a user