Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f763777477 | ||
|
|
50d8059d8b | ||
|
|
4affa135cd | ||
|
|
f2a9e1762f | ||
|
|
c1a80cc7c7 | ||
|
|
77f15ed7c3 |
No files matched your search
@@ -19,6 +19,18 @@ jobs:
|
||||
- name: Check out source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Gitea rejects a workflow file it can't parse without running
|
||||
# anything, which for release.yml only shows up when a tag is pushed.
|
||||
# Parsing them all here catches that on master, before tagging.
|
||||
- name: Check workflow files parse
|
||||
run: |
|
||||
python3 - <<'PY'
|
||||
import glob, yaml
|
||||
for f in sorted(glob.glob(".gitea/workflows/*.yml")):
|
||||
yaml.safe_load(open(f))
|
||||
print("ok", f)
|
||||
PY
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
|
||||
@@ -23,8 +23,12 @@ jobs:
|
||||
- name: Type check
|
||||
run: npm run check
|
||||
|
||||
# The API is its own origin when deployed. Overridable with the
|
||||
# TERN_API_URL repository variable.
|
||||
- name: Build
|
||||
run: npm run build
|
||||
env:
|
||||
VITE_TERN_API: ${{ vars.TERN_API_URL || 'https://tern-api.mtps.pl' }}
|
||||
|
||||
- name: Create release archive
|
||||
run: |
|
||||
@@ -45,39 +49,14 @@ jobs:
|
||||
tern-web-*.tgz
|
||||
tern-web-*.tgz.sha256
|
||||
|
||||
# Deploys the release to tern.mtps.pl (kara, deploy/compose). It lives
|
||||
# here rather than in tern-server because tags are pushed server-first and
|
||||
# the single runner works through them in order, so by the time this runs
|
||||
# both the server image and this webapp release exist. A deploy job in
|
||||
# tern-server would have to wait for this repo's release while holding
|
||||
# the only runner.
|
||||
# Deploys the release just published to tern.mtps.pl (deploy/static on
|
||||
# the swarm; see deploy/static.yml).
|
||||
deploy:
|
||||
needs: release
|
||||
runs-on: rocky-10
|
||||
steps:
|
||||
# The deployment definition is versioned with the server it deploys.
|
||||
- name: Check out deployment definition
|
||||
- name: Check out source
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: mtps/tern-server
|
||||
ref: ${{ gitea.ref_name }}
|
||||
|
||||
- name: Check the server image exists
|
||||
env:
|
||||
IMAGE: git.app.ygg/mtps/tern-server
|
||||
TAG: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
# Fails fast with a clear message if the server release didn't
|
||||
# publish this version (failed, or still running on another
|
||||
# runner), instead of a deploy that can't pull its image.
|
||||
VERSION="${TAG#v}"
|
||||
for i in $(seq 1 20); do
|
||||
docker manifest inspect "$IMAGE:$VERSION" >/dev/null 2>&1 && exit 0
|
||||
echo "waiting for $IMAGE:$VERSION ($i/20)"
|
||||
sleep 30
|
||||
done
|
||||
echo "::error::$IMAGE:$VERSION not found in the registry — did the tern-server release succeed?"
|
||||
exit 1
|
||||
|
||||
- name: Derive version
|
||||
id: version
|
||||
@@ -88,10 +67,9 @@ jobs:
|
||||
- name: Deploy
|
||||
uses: https://git.app.ygg/ygg/actions/deploy@v2
|
||||
with:
|
||||
type: compose
|
||||
dist-path: deploy/tern.yml
|
||||
type: static
|
||||
dist-path: deploy/static.yml
|
||||
extra-vars: |
|
||||
version=${{ steps.version.outputs.version }}
|
||||
ssh-key: ${{ secrets.DEPLOY_SSH_KEY }}
|
||||
known-hosts: ${{ secrets.DEPLOY_KNOWN_HOSTS }}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# tern-web's deployment: a Swarm stack of ygg/static-server serving this
|
||||
# version's release asset, on tern.mtps.pl (deploy/static in the ygg
|
||||
# management repo). Run by this repo's release workflow through
|
||||
# ygg/actions/deploy; `version` arrives as an extra var (the tag without
|
||||
# its v) and is templated in by Ansible.
|
||||
#
|
||||
# The webapp talks to tern-server at tern-api.mtps.pl, baked in at build
|
||||
# time (VITE_TERN_API in the release workflow).
|
||||
|
||||
static_stack_name: tern-web
|
||||
|
||||
domain: tern.mtps.pl
|
||||
cert: mtps.pl
|
||||
|
||||
static_service:
|
||||
name: static
|
||||
image: git.app.ygg/ygg/static-server:latest
|
||||
environment:
|
||||
GITEA_REPOSITORY_URL: https://git.app.ygg/mtps/tern-web
|
||||
GITEA_RELEASE: "v{{ version }}"
|
||||
GITEA_ASSET_NAME: "tern-web-{{ version }}.tgz"
|
||||
SSL_CERT_FILE: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
|
||||
volumes:
|
||||
- /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:ro
|
||||
ports:
|
||||
- target: 8080
|
||||
published: 11902
|
||||
protocol: tcp
|
||||
mode: ingress
|
||||
replicas: 2
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "tern-web",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "tern-web",
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.4",
|
||||
"devDependencies": {
|
||||
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
||||
"@tsconfig/svelte": "^5.0.4",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "tern-web",
|
||||
"private": true,
|
||||
"version": "0.8.1",
|
||||
"version": "0.8.4",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -0,0 +1,370 @@
|
||||
<script lang="ts">
|
||||
// The mail accounts Tern syncs, with how each one's sync is going, and
|
||||
// the form to connect another. Only the server ever talks to the mail
|
||||
// server (server-architecture-spec.md §2); this screen just hands it the
|
||||
// settings and shows what it reports back.
|
||||
import { createAccount, deleteAccount, listAccounts, type Account } from './api';
|
||||
import { formatFullDate } from './format';
|
||||
|
||||
let {
|
||||
reloadKey = 0,
|
||||
onChanged,
|
||||
}: {
|
||||
/** Bumped by the parent when accounts change elsewhere (another tab). */
|
||||
reloadKey?: number;
|
||||
/** Tells the parent the account list changed (sidebar, compose). */
|
||||
onChanged?: () => void;
|
||||
} = $props();
|
||||
|
||||
/** Sync status isn't pushed as an event, so an open screen polls it. */
|
||||
const STATUS_POLL_MS = 5_000;
|
||||
|
||||
let accounts = $state<Account[]>([]);
|
||||
let loaded = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
let adding = $state(false);
|
||||
let saving = $state(false);
|
||||
let formError = $state<string | null>(null);
|
||||
|
||||
// Form fields. Login and hosts follow the address until edited by hand.
|
||||
let email = $state('');
|
||||
let displayName = $state('');
|
||||
let imapHost = $state('');
|
||||
let imapPort = $state(993);
|
||||
let smtpHost = $state('');
|
||||
let smtpPort = $state(587);
|
||||
let login = $state('');
|
||||
let password = $state('');
|
||||
let loginEdited = $state(false);
|
||||
let hostsEdited = $state(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
accounts = await listAccounts();
|
||||
error = null;
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'failed to load accounts';
|
||||
} finally {
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Loads on mount and whenever the parent bumps reloadKey; polls while open.
|
||||
$effect(() => {
|
||||
void reloadKey;
|
||||
load();
|
||||
});
|
||||
$effect(() => {
|
||||
const timer = setInterval(load, STATUS_POLL_MS);
|
||||
return () => clearInterval(timer);
|
||||
});
|
||||
|
||||
// With no account yet, the form is the whole point of the screen.
|
||||
$effect(() => {
|
||||
if (loaded && accounts.length === 0) adding = true;
|
||||
});
|
||||
|
||||
function emailChanged() {
|
||||
const domain = email.includes('@') ? email.split('@')[1] : '';
|
||||
if (!loginEdited) login = email;
|
||||
if (!hostsEdited) {
|
||||
imapHost = domain ? `mail.${domain}` : '';
|
||||
smtpHost = imapHost;
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
email = displayName = imapHost = smtpHost = login = password = '';
|
||||
imapPort = 993;
|
||||
smtpPort = 587;
|
||||
loginEdited = hostsEdited = false;
|
||||
formError = null;
|
||||
}
|
||||
|
||||
async function add(event: SubmitEvent) {
|
||||
event.preventDefault();
|
||||
saving = true;
|
||||
formError = null;
|
||||
try {
|
||||
await createAccount({
|
||||
name: email.split('@')[1] || email,
|
||||
imap_host: imapHost.trim(),
|
||||
imap_port: Number(imapPort),
|
||||
smtp_host: smtpHost.trim(),
|
||||
smtp_port: Number(smtpPort),
|
||||
username: login.trim(),
|
||||
password,
|
||||
email_address: email.trim() || null,
|
||||
display_name: displayName.trim() || null,
|
||||
});
|
||||
resetForm();
|
||||
adding = false;
|
||||
await load();
|
||||
onChanged?.();
|
||||
} catch (e) {
|
||||
formError = e instanceof Error ? e.message : 'failed to add the account';
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(a: Account) {
|
||||
const what = a.email_address ?? a.username;
|
||||
const count = a.sync?.messages ?? 0;
|
||||
if (
|
||||
!confirm(
|
||||
`Remove ${what}?\n\nTern stops syncing it and deletes the ${count} message${count === 1 ? '' : 's'} it synced from it, ` +
|
||||
`including anything you've tagged or filed. Mail on your mail server isn't touched — adding the account again re-syncs the inbox.`,
|
||||
)
|
||||
)
|
||||
return;
|
||||
try {
|
||||
await deleteAccount(a.id);
|
||||
await load();
|
||||
onChanged?.();
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : 'failed to remove the account';
|
||||
}
|
||||
}
|
||||
|
||||
function statusText(a: Account): string {
|
||||
const s = a.sync;
|
||||
if (!s || s.status === 'pending') return 'Waiting to connect…';
|
||||
switch (s.status) {
|
||||
case 'syncing':
|
||||
return s.caught_up ? 'Connecting…' : 'First sync in progress…';
|
||||
case 'idle':
|
||||
return 'Connected — new mail arrives as it lands';
|
||||
case 'error':
|
||||
return 'Can’t sync — retrying';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="accounts">
|
||||
<header>
|
||||
<h2>Accounts</h2>
|
||||
{#if !adding}
|
||||
<button class="primary" onclick={() => { resetForm(); adding = true; }}>Add account</button>
|
||||
{/if}
|
||||
</header>
|
||||
<p class="hint">
|
||||
The mailboxes Tern syncs. Your Tern server connects to each one itself — IMAP over TLS on port 993 to
|
||||
read, SMTP on 587 (STARTTLS) or 465 to send — so the mail server has to be reachable from it.
|
||||
</p>
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
|
||||
{#if accounts.length > 0}
|
||||
<ul>
|
||||
{#each accounts as a (a.id)}
|
||||
<li>
|
||||
<span class="dot state-{a.sync?.status ?? 'pending'}" aria-hidden="true"></span>
|
||||
<div class="body">
|
||||
<strong>{a.display_name ? `${a.display_name} <${a.email_address ?? a.username}>` : (a.email_address ?? a.username)}</strong>
|
||||
<span class="detail">IMAP {a.imap_host}:{a.imap_port} · SMTP {a.smtp_host}:{a.smtp_port} · login {a.username}</span>
|
||||
<span class="status state-{a.sync?.status ?? 'pending'}">
|
||||
{statusText(a)}{#if a.sync}{` · ${a.sync.messages} message${a.sync.messages === 1 ? '' : 's'}`}{/if}
|
||||
</span>
|
||||
{#if a.sync?.status === 'error' && a.sync.last_error}
|
||||
<span class="last-error">{a.sync.last_error}</span>
|
||||
{/if}
|
||||
{#if a.sync}<span class="detail">Last update {formatFullDate(a.sync.updated_at)}</span>{/if}
|
||||
</div>
|
||||
<button onclick={() => remove(a)}>Remove</button>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
|
||||
{#if adding}
|
||||
<form onsubmit={add}>
|
||||
<h3>{accounts.length === 0 ? 'Connect your first mailbox' : 'Add an account'}</h3>
|
||||
<label class="wide">Email address
|
||||
<input type="email" bind:value={email} oninput={emailChanged} required autocomplete="email" />
|
||||
</label>
|
||||
<label class="wide">Your name <span class="optional">(optional, shown on mail you send)</span>
|
||||
<input bind:value={displayName} autocomplete="name" />
|
||||
</label>
|
||||
<label>IMAP server
|
||||
<input bind:value={imapHost} oninput={() => (hostsEdited = true)} required />
|
||||
</label>
|
||||
<label class="port">Port
|
||||
<input type="number" min="1" max="65535" bind:value={imapPort} required />
|
||||
</label>
|
||||
<label>SMTP server
|
||||
<input bind:value={smtpHost} oninput={() => (hostsEdited = true)} required />
|
||||
</label>
|
||||
<label class="port">Port
|
||||
<input type="number" min="1" max="65535" bind:value={smtpPort} required />
|
||||
</label>
|
||||
<label class="wide">Login
|
||||
<input bind:value={login} oninput={() => (loginEdited = true)} required autocomplete="username" />
|
||||
</label>
|
||||
<label class="wide">Password
|
||||
<input type="password" bind:value={password} required autocomplete="current-password" />
|
||||
</label>
|
||||
<p class="hint wide">
|
||||
Stored encrypted on your Tern server, never in this browser. Tern only reads your inbox and sends —
|
||||
it never changes anything on the mail server.
|
||||
</p>
|
||||
{#if formError}<p class="error wide">{formError}</p>{/if}
|
||||
<div class="actions wide">
|
||||
{#if accounts.length > 0}
|
||||
<button type="button" onclick={() => { adding = false; resetForm(); }}>Cancel</button>
|
||||
{/if}
|
||||
<button type="submit" class="primary" disabled={saving}>{saving ? 'Adding…' : 'Add account'}</button>
|
||||
</div>
|
||||
</form>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.accounts {
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
}
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 1.25rem 1.25rem 0;
|
||||
}
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
h3 {
|
||||
grid-column: 1 / -1;
|
||||
margin: 0 0 0.25rem;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
.hint,
|
||||
.error {
|
||||
padding: 0 1.25rem;
|
||||
font-size: 0.82rem;
|
||||
color: var(--primary);
|
||||
max-width: 48rem;
|
||||
}
|
||||
.error {
|
||||
color: var(--accent);
|
||||
}
|
||||
ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 1.25rem 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
li {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.75rem;
|
||||
padding: 0.7rem 0.75rem;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.45rem;
|
||||
}
|
||||
.body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
.detail {
|
||||
font-size: 0.78rem;
|
||||
color: var(--primary);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.status {
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
.status.state-error {
|
||||
color: var(--accent);
|
||||
}
|
||||
.last-error {
|
||||
font-family: ui-monospace, monospace;
|
||||
font-size: 0.75rem;
|
||||
color: var(--accent);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.dot {
|
||||
flex-shrink: 0;
|
||||
width: 0.6rem;
|
||||
height: 0.6rem;
|
||||
margin-top: 0.35rem;
|
||||
border-radius: 50%;
|
||||
border: 1px solid var(--primary);
|
||||
}
|
||||
.dot.state-idle {
|
||||
background: var(--primary);
|
||||
}
|
||||
.dot.state-syncing {
|
||||
border-style: dashed;
|
||||
}
|
||||
.dot.state-error {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
form {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 6rem;
|
||||
gap: 0.6rem 0.75rem;
|
||||
margin: 0 1.25rem 1.25rem;
|
||||
padding: 1rem;
|
||||
max-width: 34rem;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.45rem;
|
||||
}
|
||||
form .hint,
|
||||
form .error {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
.wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
.optional {
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
input {
|
||||
font: inherit;
|
||||
font-size: 0.88rem;
|
||||
color: var(--text);
|
||||
background: var(--background);
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.3rem;
|
||||
padding: 0.35rem 0.5rem;
|
||||
}
|
||||
.actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
button {
|
||||
font: inherit;
|
||||
font-size: 0.82rem;
|
||||
color: var(--text);
|
||||
background: none;
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.3rem;
|
||||
padding: 0.25rem 0.6rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: default;
|
||||
}
|
||||
.primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
@@ -29,6 +29,7 @@
|
||||
import ThreadView from './ThreadView.svelte';
|
||||
import OutboxView from './OutboxView.svelte';
|
||||
import RulesView from './RulesView.svelte';
|
||||
import AccountsView from './AccountsView.svelte';
|
||||
import ActionMenu from './ActionMenu.svelte';
|
||||
import Compose from './Compose.svelte';
|
||||
import ShortcutHelp from './ShortcutHelp.svelte';
|
||||
@@ -48,7 +49,7 @@
|
||||
let nextCursor = $state<string | null>(null);
|
||||
let loadingMore = $state(false);
|
||||
let outbox = $state<OutboxItem[]>([]);
|
||||
let section = $state<'mail' | 'outbox' | 'rules'>('mail');
|
||||
let section = $state<'mail' | 'outbox' | 'rules' | 'accounts'>('mail');
|
||||
let mailView = $state<MailView>({ kind: 'inbox' });
|
||||
let selected = $state<ThreadSummary | null>(null);
|
||||
let threadMessages = $state<MessageDetail[]>([]);
|
||||
@@ -64,6 +65,9 @@
|
||||
let liveStatus = $state<LiveStatus>('connecting');
|
||||
let alerts = $state<AlertState>(alertState());
|
||||
let rulesReloadKey = $state(0);
|
||||
let accountsReloadKey = $state(0);
|
||||
/** Accounts have been fetched at least once (so "none" means none). */
|
||||
let accountsLoaded = $state(false);
|
||||
/** In-page notices for new mail; OS alerts replace them while the tab is hidden. */
|
||||
let toasts = $state<{ key: number; threadId: string | null; from: string; subject: string }[]>([]);
|
||||
let toastSeq = 0;
|
||||
@@ -138,6 +142,15 @@
|
||||
[folders, tags] = await Promise.all([listFolders(), listTags()]);
|
||||
}
|
||||
|
||||
async function refreshAccounts() {
|
||||
try {
|
||||
accounts = await listAccounts();
|
||||
accountsLoaded = true;
|
||||
} catch {
|
||||
// Non-critical here; the Accounts screen shows its own errors.
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshOutbox() {
|
||||
try {
|
||||
outbox = await listOutbox();
|
||||
@@ -148,7 +161,7 @@
|
||||
|
||||
function reloadAll() {
|
||||
refreshMeta().catch(() => {});
|
||||
listAccounts().then((a) => (accounts = a)).catch(() => {});
|
||||
refreshAccounts();
|
||||
refreshList();
|
||||
refreshOutbox();
|
||||
rulesReloadKey++;
|
||||
@@ -181,7 +194,10 @@
|
||||
outboxChanged = true;
|
||||
break;
|
||||
case 'config_changed':
|
||||
if (e.data.what === 'accounts') listAccounts().then((a) => (accounts = a)).catch(() => {});
|
||||
if (e.data.what === 'accounts') {
|
||||
refreshAccounts();
|
||||
accountsReloadKey++;
|
||||
}
|
||||
else if (e.data.what === 'rules') rulesReloadKey++;
|
||||
else {
|
||||
refreshMeta().catch(() => {});
|
||||
@@ -545,6 +561,7 @@
|
||||
|
||||
<div class="bottom">
|
||||
<button class:active={section === 'rules'} onclick={() => { section = 'rules'; selected = null; }}>Rules</button>
|
||||
<button class:active={section === 'accounts'} onclick={() => { section = 'accounts'; selected = null; }}>Accounts</button>
|
||||
{#if alerts === 'on' || alerts === 'off'}
|
||||
<button class="help-hint" onclick={toggleAlerts} title="OS notifications for new mail while this tab is open">
|
||||
{alerts === 'on' ? 'Desktop alerts: on' : 'Enable desktop alerts'}
|
||||
@@ -565,6 +582,10 @@
|
||||
<section class="wide-pane">
|
||||
<RulesView {folders} {tags} reloadKey={rulesReloadKey} />
|
||||
</section>
|
||||
{:else if section === 'accounts'}
|
||||
<section class="wide-pane">
|
||||
<AccountsView reloadKey={accountsReloadKey} onChanged={() => { refreshAccounts(); refreshList(); }} />
|
||||
</section>
|
||||
{:else}
|
||||
<section class="list-pane">
|
||||
{#if section === 'outbox'}
|
||||
@@ -574,6 +595,12 @@
|
||||
{#if error}<p class="note error">{error}</p>{/if}
|
||||
{#if loading}
|
||||
<p class="note">Loading…</p>
|
||||
{:else if accountsLoaded && accounts.length === 0}
|
||||
<p class="note">
|
||||
No mailbox connected yet.
|
||||
<button class="link" onclick={() => { section = 'accounts'; selected = null; }}>Connect one</button>
|
||||
and its mail will show up here.
|
||||
</p>
|
||||
{:else if threads.length === 0}
|
||||
<p class="note">
|
||||
{mailView.kind === 'inbox' ? 'Inbox zero.' : 'Nothing here.'}
|
||||
@@ -823,6 +850,15 @@
|
||||
color: var(--primary);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.link {
|
||||
background: none;
|
||||
border: none;
|
||||
padding: 0;
|
||||
font: inherit;
|
||||
color: var(--accent);
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
.error {
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
+45
-1
@@ -4,6 +4,13 @@
|
||||
|
||||
const SESSION_KEY = 'tern-session-token';
|
||||
|
||||
/**
|
||||
* Where tern-server lives, fixed at build time (VITE_TERN_API). Deployed,
|
||||
* the webapp and the API are separate origins; in development it's empty
|
||||
* and Vite's proxy forwards /api on the same origin.
|
||||
*/
|
||||
export const API_ORIGIN = (import.meta.env.VITE_TERN_API ?? '').replace(/\/+$/, '');
|
||||
|
||||
export function getSessionToken(): string | null {
|
||||
return localStorage.getItem(SESSION_KEY);
|
||||
}
|
||||
@@ -18,7 +25,7 @@ export function clearSessionToken(): void {
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const token = getSessionToken();
|
||||
const res = await fetch(`/api${path}`, {
|
||||
const res = await fetch(`${API_ORIGIN}/api${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -165,6 +172,34 @@ export interface Account {
|
||||
username: string;
|
||||
email_address: string | null;
|
||||
display_name: string | null;
|
||||
imap_host: string;
|
||||
imap_port: number;
|
||||
smtp_host: string;
|
||||
smtp_port: number;
|
||||
created_at: string;
|
||||
/** Null until the sync engine first touches the account. */
|
||||
sync: AccountSync | null;
|
||||
}
|
||||
|
||||
export interface AccountSync {
|
||||
status: 'pending' | 'syncing' | 'idle' | 'error';
|
||||
last_error: string | null;
|
||||
updated_at: string;
|
||||
/** The first full pass over the mailbox has finished. */
|
||||
caught_up: boolean;
|
||||
messages: number;
|
||||
}
|
||||
|
||||
export interface NewAccount {
|
||||
name: string;
|
||||
imap_host: string;
|
||||
imap_port: number;
|
||||
smtp_host: string;
|
||||
smtp_port: number;
|
||||
username: string;
|
||||
password: string;
|
||||
email_address: string | null;
|
||||
display_name: string | null;
|
||||
}
|
||||
|
||||
export type OutboxStatus = 'draft' | 'pending' | 'sending' | 'sent' | 'failed';
|
||||
@@ -197,6 +232,15 @@ export function listAccounts(): Promise<Account[]> {
|
||||
return request('/accounts');
|
||||
}
|
||||
|
||||
export function createAccount(account: NewAccount): Promise<Account> {
|
||||
return request('/accounts', { method: 'POST', body: JSON.stringify(account) });
|
||||
}
|
||||
|
||||
/** Removes the account and every message synced from it. */
|
||||
export function deleteAccount(id: string): Promise<{ ok: boolean }> {
|
||||
return request(`/accounts/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
export function markThreadRead(threadId: string): Promise<{ messages: number }> {
|
||||
return request(`/threads/${threadId}/read`, { method: 'POST' });
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
// polling the same event log while it isn't. Both carry the same cursor,
|
||||
// so switching between them neither drops nor repeats a change.
|
||||
|
||||
import { getSessionToken, pollEvents, type LiveEvent } from './api';
|
||||
import { API_ORIGIN, getSessionToken, pollEvents, type LiveEvent } from './api';
|
||||
|
||||
export type LiveStatus = 'connecting' | 'live' | 'polling';
|
||||
|
||||
@@ -55,7 +55,7 @@ export function startLive(handlers: LiveHandlers): () => void {
|
||||
return;
|
||||
}
|
||||
handlers.onStatus(cursor === null ? 'connecting' : 'polling');
|
||||
const url = new URL('/api/ws', location.href);
|
||||
const url = new URL('/api/ws', API_ORIGIN || location.href);
|
||||
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const ws = new WebSocket(url);
|
||||
socket = ws;
|
||||
|
||||
Vendored
+5
@@ -1,2 +1,7 @@
|
||||
/// <reference types="svelte" />
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
/** tern-server's origin, e.g. https://tern-api.mtps.pl. Empty: same origin. */
|
||||
readonly VITE_TERN_API?: string;
|
||||
}
|
||||
Reference in new issue
Block a user