Files
notify-bridge/frontend/src/routes/providers/WebhookPayloadHistory.svelte
T
alexei.dolgolyov a7a2b4efa4 feat: large polish pass — UX fixes, per-chat scope, restore/backup, action events
Backend
- Per-chat album scope for Immich commands (search/latest/memory/...): new
  allowed_album_ids on CommandTrackerListener, threaded listener/page kwargs
  through ProviderCommandHandler.handle; PATCH listener-scope endpoint.
- /search and /find accept a trailing page number; Immich client search_smart
  / search_metadata take a page param.
- Immich person-asset lookup switched from removed GET /api/people/{id}/assets
  to POST /api/search/metadata with personIds (fixes /person command and
  auto_organize rules silently returning zero candidates on Immich 1.106+).
- Auto_organize rule now sets the target album's thumbnail to the first added
  image when missing (falls back to any asset type); failures do not fail the
  rule. add_assets_to_album surfaces the Immich error body on non-2xx.
- EventLog.user_id / action_id / action_name columns with defensive migration
  + backfill. Status query filters by user_id directly; Immich/webhook paths
  emit user_id explicitly. action_runner writes an action_success/partial/
  failed event on each non-dry-run.
- Dashboard DELETE /api/status/events (scoped to user_id) + rendering live
  tracker/provider/action names via FK join with snapshot fallback.
- PATCH /api/users/{id} for username/role change with last-admin guard.
- Deletion protection returns structured {message, entity, blocked_by}
  (ApiError carries .blockedBy; frontend opens BlockedByModal).
- Backup prepare-restore → AppSetting markers + atomic write of
  pending_restore.json; lifespan hook applies on next startup and archives
  under data/applied_restores/. apply-restart sends SIGTERM so the lifespan
  shutdown runs; NOTIFY_BRIDGE_SUPERVISED env override gates the button.
  Manual POST /api/backup/files (same format as scheduled).
- New periodic-summary test path reuses shared collect_scheduled_assets
  (limit=0) so test and future production code go through one primitive.
- Per-receiver locale for Telegram test messages (resolves
  TelegramChat.language_override per chat instead of applying the first
  receiver's locale to everyone).
- Bounded concurrency (semaphores) in NotificationDispatcher._preload_asset_data
  and _refresh_telegram_chat_titles; chat title sweep extended to 24h since
  save_chat_from_webhook covers active chats opportunistically.
- Telegram poller detects the \"webhook is active\" 409 and auto-calls
  deleteWebhook for bots whose DB update_mode is polling (throttled per bot).
- TelegramClient.get_chat added (CLAUDE.md rule 6); set_album_thumbnail added.
- Seeds: rename \"Default Commands\" → \"Default Immich Commands\";
  track_assets_removed default False.

Frontend
- Global provider selector visible when there is only one provider.
- Clear-events button + i18n + ConfirmModal on the dashboard; new icons/
  labels/filters/colors for action_success / action_partial / action_failed.
- Auto-select first available tracking/template/command/config + bot on
  create forms (trackers, command-trackers, targets, template/command
  configs).
- Telegram target disable_url_preview defaults to true.
- BlockedByModal wired into 8 deletion flows; fetchAuth helper for
  multipart/binary calls (reuses api()'s refresh + ApiError mapping).
- Immich tracker 'Checking links' parallelised (concurrency cap 6).
- Backup page: pending-restore banner + Apply-now / Apply-later modal,
  restarting overlay polling /api/health, manual 'Create backup' button.
- Command-trackers listener row gets an 'Edit album scope' modal with
  inherit/explicit multiselect.
- Users page: Edit user modal (username + role).
- parseDate helper for consistent UTC date rendering.

Migrations / schema
- event_log: + user_id, action_id, action_name (+ backfill user_id from
  notification_tracker).
- command_tracker_listener: + allowed_album_ids.
2026-04-22 01:13:11 +03:00

168 lines
6.3 KiB
Svelte

<script lang="ts">
import { t } from '$lib/i18n';
import { api, parseDate } from '$lib/api';
import MdiIcon from '$lib/components/MdiIcon.svelte';
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
import type { WebhookPayloadLog } from '$lib/types';
interface Props {
providerId: number;
}
let { providerId }: Props = $props();
let logs = $state<WebhookPayloadLog[]>([]);
let loading = $state(false);
let loaded = $state(false);
let expanded = $state(false);
let expandedId = $state<number | null>(null);
let showClearConfirm = $state(false);
async function loadLogs() {
loading = true;
try {
logs = await api(`/providers/${providerId}/webhook-logs`);
} catch (e) {
console.error('Failed to load webhook logs', e);
logs = [];
}
loading = false;
loaded = true;
}
function toggle() {
expanded = !expanded;
if (expanded && !loaded) loadLogs();
}
async function clearLogs() {
try {
await api(`/providers/${providerId}/webhook-logs`, { method: 'DELETE' });
logs = [];
} catch (e) { console.error('Failed to clear webhook logs', e); }
showClearConfirm = false;
}
function toggleExpand(id: number) {
expandedId = expandedId === id ? null : id;
}
function statusColor(status: string): string {
if (status === 'matched') return 'var(--color-success-fg)';
if (status === 'unmatched') return 'var(--color-warning-fg)';
return 'var(--color-error-fg)';
}
function statusIcon(status: string): string {
if (status === 'matched') return 'mdiCheckCircle';
if (status === 'unmatched') return 'mdiMinusCircle';
return 'mdiAlertCircle';
}
function statusLabel(status: string): string {
if (status === 'matched') return t('webhookLogs.statusMatched');
if (status === 'unmatched') return t('webhookLogs.statusUnmatched');
return t('webhookLogs.statusError');
}
function formatTime(iso: string): string {
return parseDate(iso).toLocaleString();
}
</script>
<div class="border-t border-[var(--color-border)] mt-3 pt-2">
<button onclick={toggle} class="w-full flex items-center gap-2 text-sm font-medium py-1 hover:opacity-80 transition-opacity">
<MdiIcon name={expanded ? 'mdiChevronDown' : 'mdiChevronRight'} size={16} />
{t('webhookLogs.title')}
{#if loaded && logs.length > 0}
<span class="text-xs px-1.5 py-0.5 rounded-full bg-[var(--color-muted)] text-[var(--color-muted-foreground)]">{logs.length}</span>
{/if}
</button>
{#if expanded}
<div class="mt-2">
{#if loading}
<div class="text-sm text-[var(--color-muted-foreground)] py-3 text-center">{t('common.loading')}</div>
{:else if logs.length === 0}
<div class="text-sm text-[var(--color-muted-foreground)] py-3 text-center">{t('webhookLogs.empty')}</div>
{:else}
<div class="flex justify-end mb-2">
<button
onclick={() => showClearConfirm = true}
class="text-xs px-2 py-1 rounded-md transition-colors hover:bg-[var(--color-error-bg)] text-[var(--color-error-fg)]"
>
{t('webhookLogs.clear')}
</button>
</div>
<div class="space-y-1">
{#each logs as log}
<button
onclick={() => toggleExpand(log.id)}
class="w-full text-left px-3 py-2 rounded-md text-sm transition-colors hover:bg-[var(--color-sidebar-active)]"
style="background: {expandedId === log.id ? 'var(--color-sidebar-active)' : 'transparent'};"
>
<div class="flex items-center gap-2">
<MdiIcon name={expandedId === log.id ? 'mdiChevronDown' : 'mdiChevronRight'} size={14} />
<span class="text-xs text-[var(--color-muted-foreground)] tabular-nums">{formatTime(log.created_at)}</span>
<span class="text-xs font-mono px-1 py-0.5 rounded bg-[var(--color-muted)]">{log.method}</span>
<span class="flex items-center gap-1" style="color: {statusColor(log.status)};">
<MdiIcon name={statusIcon(log.status)} size={14} />
<span class="text-xs font-medium">{statusLabel(log.status)}</span>
</span>
{#if log.error_message && log.status === 'error'}
<span class="text-xs text-[var(--color-muted-foreground)] truncate max-w-[200px]">{log.error_message}</span>
{/if}
</div>
</button>
{#if expandedId === log.id}
<div class="ml-6 mr-2 mb-2 space-y-2">
{#if Object.keys(log.headers).length > 0}
<div>
<div class="text-xs font-medium text-[var(--color-muted-foreground)] mb-1">{t('webhookLogs.headers')}</div>
<div class="bg-[var(--color-background)] border border-[var(--color-border)] rounded-md p-2 text-xs font-mono">
{#each Object.entries(log.headers) as [key, value]}
<div><span class="text-[var(--color-primary)]">{key}</span>: {value}</div>
{/each}
</div>
</div>
{/if}
<div>
<div class="text-xs font-medium text-[var(--color-muted-foreground)] mb-1">{t('webhookLogs.body')}</div>
<pre class="bg-[var(--color-background)] border border-[var(--color-border)] rounded-md p-2 text-xs font-mono overflow-x-auto whitespace-pre-wrap break-all" style="max-height: 300px; overflow-y: auto;">{JSON.stringify(log.body, null, 2)}</pre>
</div>
{#if log.status === 'matched' && Object.keys(log.extracted_fields).length > 0}
<div>
<div class="text-xs font-medium text-[var(--color-muted-foreground)] mb-1">{t('webhookLogs.extractedFields')}</div>
<div class="bg-[var(--color-background)] border border-[var(--color-border)] rounded-md p-2 text-xs font-mono">
{#each Object.entries(log.extracted_fields) as [key, value]}
<div><span class="text-[var(--color-primary)]">{key}</span>: {typeof value === 'object' ? JSON.stringify(value) : String(value)}</div>
{/each}
</div>
</div>
{/if}
{#if log.status === 'error' && log.error_message}
<div>
<div class="text-xs font-medium text-[var(--color-error-fg)] mb-1">{t('webhookLogs.errorMessage')}</div>
<div class="bg-[var(--color-error-bg)] text-[var(--color-error-fg)] rounded-md p-2 text-xs">{log.error_message}</div>
</div>
{/if}
</div>
{/if}
{/each}
</div>
{/if}
</div>
{/if}
</div>
<ConfirmModal
open={showClearConfirm}
title={t('webhookLogs.clear')}
message={t('webhookLogs.confirmClear')}
onconfirm={clearLogs}
oncancel={() => showClearConfirm = false}
/>