Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion webui/src/components/CiTokens.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@
</ListView>
{#if error}<p class="error">{error}</p>{/if}
{#if newToken}
<OneTimeSecret value={newToken} />
<OneTimeSecret
title="Deploy Token"
value={newToken}
onclose={() => (newToken = null)}
/>
{/if}
<div class="row-buttons">
<Button onclick={addToken}>New Token…</Button>
Expand Down
56 changes: 52 additions & 4 deletions webui/src/components/OneTimeSecret.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,58 @@
<script lang="ts">
// a token (or a command with one) that the server shows this once
import type { Snippet } from 'svelte';
import { copyText } from '@/lib/clipboard';
import Button from './win/Button.svelte';
import Dialog from './win/Dialog.svelte';

// a token (or a command with one) that the server shows this once, in
// its own window over the one that made it: a click beside it doesn't
// close it, only OK, Escape or the title bar's close
let {
title,
value,
label = 'Copy it now, it is shown only once:',
}: { value: string; label?: string } = $props();
onclose,
children,
}: {
title: string;
value: string;
label?: string;
onclose: () => void;
/** what to do with it, below the value */
children?: Snippet;
} = $props();

let copied = $state(false);
let error = $state<string | null>(null);

let copiedTimer: ReturnType<typeof setTimeout> | undefined;

async function copy() {
error = null;
try {
await copyText(value);
copied = true;
clearTimeout(copiedTimer);
copiedTimer = setTimeout(() => (copied = false), 2000);
} catch (e: any) {
error = e.message;
}
}
</script>

<p><b>{label}</b></p>
<pre class="code selectable">{value}</pre>
<Dialog {title} icon="key" {onclose} keep={() => true} width={520}>
<p><b>{label}</b></p>
<pre class="code selectable">{value}</pre>
{#if error}<p class="error">{error}</p>{/if}
{@render children?.()}
<div class="row-buttons center">
<Button onclick={copy}>{copied ? 'Copied' : 'Copy'}</Button>
<Button primary onclick={onclose}>OK</Button>
</div>
</Dialog>

<style>
p {
margin: 0 0 8px;
}
</style>
13 changes: 8 additions & 5 deletions webui/src/components/dialogs/AgentsDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,16 @@
{#if testResult}<p class="selectable">{testResult}</p>{/if}
{#if key}
<OneTimeSecret
title="AI Agent Key"
value={key}
label="The agent's key, copy it now, it is shown only once:"
/>
{#each examples as e (e.text)}
<p>{e.text}</p>
<pre class="code selectable">{e.code}</pre>
{/each}
onclose={() => (key = null)}
>
{#each examples as e (e.text)}
<p>{e.text}</p>
<pre class="code selectable">{e.code}</pre>
{/each}
</OneTimeSecret>
{/if}
<div class="row-buttons">
<Button onclick={() => edit(null)}>New Agent…</Button>
Expand Down
2 changes: 1 addition & 1 deletion webui/src/components/dialogs/ApproveDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
: ''}. Its answer goes to {proposal.from}.
</p>
<Form onsubmit={approve} oncancel={onclose} ok="Approve">
<SecondFactor bind:password bind:code />
<SecondFactor bind:password bind:code autofocus />
</Form>
</Dialog>

Expand Down
14 changes: 7 additions & 7 deletions webui/src/components/dialogs/BackupSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,18 @@
{/if}

{#if generated}
<fieldset>
<legend>Repository Password</legend>
<OneTimeSecret
value={generated}
label="The remote repository's password, shown only this once:"
/>
<OneTimeSecret
title="Repository Password"
value={generated}
label="The remote repository's password, shown only this once:"
onclose={() => (generated = null)}
>
<p class="error">
Keep it outside this server, e.g. in your password manager, with the
bucket's key. Without it the remote copy can't be read when the
server is lost.
</p>
</fieldset>
</OneTimeSecret>
{/if}

{#if saved}
Expand Down
3 changes: 2 additions & 1 deletion webui/src/components/dialogs/PasswordsDialog.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { formatTime, get, post } from '@/lib/api';
import { copyText } from '@/lib/clipboard';
import { dialogs, confirmDelete } from '@/lib/dialogs.svelte';
import { tree } from '@/lib/tree.svelte';
import Button from '../win/Button.svelte';
Expand Down Expand Up @@ -102,7 +103,7 @@
try {
const v = shown ?? (await value());
if (v === null) return;
await navigator.clipboard.writeText(v);
await copyText(v);
copied = true;
setTimeout(() => (copied = false), 2000);
} catch (e: any) {
Expand Down
2 changes: 2 additions & 0 deletions webui/src/components/dialogs/RunnerSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@
{/if}
{#if created}
<OneTimeSecret
title="New Runner"
label="On the build box, copy it now (the token is shown only once):"
value={`genco runner install\n${created}\nsystemctl restart genco-runner`}
onclose={() => (created = null)}
/>
{/if}
{#if target}
Expand Down
20 changes: 12 additions & 8 deletions webui/src/components/dialogs/TokensDialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@
await load();
}

const auth = $derived(
`curl -fsS -H "Authorization: Bearer ${created ?? '<token>'}" \\\n `,
);
const example = $derived(
`${auth} ${location.origin}/api/databases/<name>/dump -o db.sql.gz`,
);
const example = (token: string) =>
`curl -fsS -H "Authorization: Bearer ${token}" \\\n ` +
` ${location.origin}/api/databases/<name>/dump -o db.sql.gz`;
</script>

<Dialog title="API Tokens" resizable icon="key" {onclose} width={560}>
Expand Down Expand Up @@ -113,10 +110,17 @@
</ListView>
{#if error}<p class="error">{error}</p>{/if}
{#if created}
<OneTimeSecret value={created} />
<OneTimeSecret
title="API Token"
value={created}
onclose={() => (created = null)}
>
<p>Download a database:</p>
<pre class="code selectable">{example(created)}</pre>
</OneTimeSecret>
{/if}
<p>Download a database:</p>
<pre class="code selectable">{example}</pre>
<pre class="code selectable">{example('<token>')}</pre>
<p class="hint">
Deploy tokens are made in a group's Deploy tab, the keys of AI
agents in Start → AI Agents.
Expand Down
8 changes: 8 additions & 0 deletions webui/src/lib/clipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** copies text, with a readable error where the browser has no clipboard
* (plain http) */
export async function copyText(text: string): Promise<void> {
if (!navigator.clipboard)
throw new Error('This page may not copy, select it and copy by hand.');

await navigator.clipboard.writeText(text);
}
4 changes: 4 additions & 0 deletions webui/src/pages/ProposalLink.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,22 @@
<Form onsubmit={approve} ok="Approve">
{#if link.totp}
<label for="pl-code">Two-factor code:</label>
<!-- svelte-ignore a11y_autofocus -->
<input
id="pl-code"
inputmode="numeric"
autocomplete="one-time-code"
autofocus
bind:value={code}
/>
{:else}
<label for="pl-password">Your password:</label>
<!-- svelte-ignore a11y_autofocus -->
<input
id="pl-password"
type="password"
autocomplete="current-password"
autofocus
bind:value={password}
/>
{/if}
Expand Down
Loading