Files
knock/src/lib/views/settings/FolderView.svelte
T
JoshiCodes 4b1590e750 Cookie jars per folder; pacman repository on Gitea; install guide per platform
- A folder can share its parent's cookie jar, keep its own, or use no
  cookies; sub folders follow. The Cookies tab shows the jar a request
  used. Jars are stored per collection and folder.
- The release workflow builds knock-bin from the deb and uploads it to
  the Gitea pacman repository (needs the GITEA_PACKAGES_TOKEN secret)
- knock-bin installs the desktop entry as knock-app.desktop
- README: install for Arch (signed pacman repo), Ubuntu/Debian,
  Fedora/openSUSE, AppImage, macOS (quarantine) and Windows (SmartScreen)
- release.sh works when the version is already set
2026-11-27 22:12:08 +01:00

95 lines
3.7 KiB
Svelte

<script lang="ts">
import { plain } from '$lib/plain.svelte';
import { toast } from '@joshicodes/cock';
import KeyValueTable from '$lib/ui/KeyValueTable.svelte';
import AuthPanel from '$lib/views/auth/AuthPanel.svelte';
import { api, errorText } from '$lib/api';
import { ws } from '$lib/state/workspace.svelte';
import { HEADER_NAMES, headerValues } from '$lib/headers';
import type { FolderMeta, KeyValue } from '$lib/types';
import { dialogs } from '$lib/state/dialogs.svelte';
let { col, id }: { col: string; id: string } = $props();
let meta = $state<FolderMeta | null>(null);
let saved = $state('');
let varRows = $state<KeyValue[]>([]);
async function load() {
const m = await api.folderGet(col, id);
m.headers ??= [];
m.auth ??= 'inherit';
meta = m;
varRows = Object.entries(m.vars ?? {}).map(([name, value]) => ({ name, value }));
saved = JSON.stringify(m);
}
$effect(() => {
load();
});
let dirty = $derived(meta ? JSON.stringify(meta) !== saved : false);
async function save() {
if (!meta) return;
meta.vars = Object.fromEntries(varRows.filter((r) => r.name).map((r) => [r.name, r.value]));
try {
ws.upsert(await api.folderSave(col, id, plain(meta)));
saved = JSON.stringify(meta);
toast.success('Folder saved');
} catch (e) {
toast.error('Could not save', { description: errorText(e) });
}
}
function onKey(e: KeyboardEvent) {
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
e.preventDefault();
e.stopPropagation();
save();
}
}
</script>
<svelte:window onkeydowncapture={onKey} />
{#if meta}
<div class="k-scroll h-full">
<div class="mx-auto flex max-w-3xl flex-col gap-8 px-6 py-6">
<div class="flex items-center gap-3">
<div class="flex-1">
<div class="k-label">Folder</div>
<h1 class="text-[20px] font-bold text-strong">{meta.name ?? id}</h1>
<div class="mono text-[12px] text-fg-subtle">{id}/folder.yaml</div>
</div>
<button class="rounded px-3 py-1.5 text-fg-muted hover:text-fg" onclick={() => dialogs.runner(col, id)}>Run folder</button>
{#if dirty}<button class="rounded bg-accent px-4 py-1.5 font-bold text-accent-fg hover:bg-accent-hover" onclick={save} title="Save (Ctrl+S)">Save</button>{:else}<span class="px-4 py-1.5 text-fg-subtle">Saved</span>{/if}
</div>
<section>
<h2 class="k-label mb-2">Auth</h2>
<p class="mb-2 text-[12px] text-fg-subtle">Requests in this folder that use "inherit" get this auth.</p>
<div class="-mx-3"><AuthPanel bind:auth={meta.auth!} level="folder" {col} /></div>
</section>
<section>
<h2 class="k-label mb-2">Cookies</h2>
<p class="mb-3 text-[12px] text-fg-subtle">A folder can keep its own cookies, for example a frontend session apart from OIDC tests. Sub folders follow unless they choose something else.</p>
<div class="flex flex-col gap-1.5">
{#each [[undefined, 'Share the cookie jar of the parent folder or collection'], ['own', 'Own cookie jar for this folder'], ['off', 'No cookies']] as [mode, label]}
<label class="flex items-center gap-2">
<input type="radio" name="cookie-mode" class="size-3.5 accent-[var(--knock-cyan)]" checked={meta.cookies === mode} onchange={() => (meta!.cookies = mode as FolderMeta['cookies'])} />
<span>{label}</span>
</label>
{/each}
</div>
</section>
<section>
<h2 class="k-label mb-2">Headers</h2>
<KeyValueTable bind:rows={meta.headers!} nameSuggestions={HEADER_NAMES} valueSuggestions={headerValues} />
</section>
<section>
<h2 class="k-label mb-2">Variables</h2>
<KeyValueTable bind:rows={varRows} onchange={() => (meta!.vars = Object.fromEntries(varRows.filter((r) => r.name).map((r) => [r.name, r.value])))} />
</section>
</div>
</div>
{/if}