feat: person excludes for auto-organize rules, backup & restore system

Add person exclude criteria to Immich auto-organize — assets containing
excluded persons are filtered out after candidate gathering. Also adds
full backup/restore system with export, import, scheduled backups, and
retention management.
This commit is contained in:
2026-04-02 14:13:42 +03:00
parent 6e51164f8e
commit 6b2211353d
13 changed files with 2191 additions and 2 deletions
+65
View File
@@ -16,6 +16,7 @@
"cmdTemplateConfigs": "Cmd Templates",
"users": "Users",
"settings": "Settings",
"backup": "Backup",
"logout": "Logout",
"notification": "Notification",
"commands": "Commands",
@@ -1025,6 +1026,8 @@
"criteria": "Criteria",
"persons": "Persons",
"addPerson": "Add person...",
"excludePersons": "Exclude persons",
"addExcludePerson": "Add person to exclude...",
"searchQuery": "Smart Search Query",
"searchQueryPlaceholder": "e.g. sunset, beach, birthday...",
"assetType": "Asset type",
@@ -1053,5 +1056,67 @@
"triggerManual": "manual",
"triggerDryRun": "dry-run",
"triggerScheduled": "scheduled"
},
"backup": {
"title": "Backup & Restore",
"description": "Export and import your configuration, or set up automatic backups",
"export": "Export Configuration",
"exportDescription": "Download your configuration as a JSON file. Select which categories to include.",
"import": "Import Configuration",
"importDescription": "Upload a previously exported backup file to restore configuration.",
"categories": "Categories",
"selectAll": "Select all",
"deselectAll": "Deselect all",
"catProviders": "Providers",
"catTelegramBots": "Telegram Bots",
"catMatrixBots": "Matrix Bots",
"catEmailBots": "Email Bots",
"catTargets": "Targets",
"catTrackingConfigs": "Tracking Configs",
"catTemplateConfigs": "Template Configs",
"catCommandConfigs": "Command Configs",
"catCommandTemplateConfigs": "Cmd Template Configs",
"catNotificationTrackers": "Notif. Trackers",
"catCommandTrackers": "Cmd Trackers",
"catActions": "Actions",
"catAppSettings": "App Settings",
"secretsMode": "Secrets",
"secretsExclude": "Exclude secrets (safe)",
"secretsMasked": "Mask secrets (for review)",
"secretsInclude": "Include secrets (plaintext)",
"secretsWarningExport": "Warning: The export file will contain sensitive data (API keys, tokens, passwords) in plaintext.",
"exportBtn": "Export",
"exportSuccess": "Configuration exported",
"validateBtn": "Validate",
"validating": "Validating...",
"validationPassed": "Validation passed",
"validationFailed": "Validation failed",
"entities": "Entities",
"conflictMode": "Conflict resolution",
"conflictSkip": "Skip existing (keep current)",
"conflictRename": "Rename duplicates (add suffix)",
"conflictOverwrite": "Overwrite existing (replace)",
"importBtn": "Import",
"importing": "Importing...",
"importSuccess": "Configuration imported",
"importResults": "Import Results",
"resultCreated": "Created",
"resultSkipped": "Skipped",
"resultOverwritten": "Overwritten",
"resultErrors": "Errors",
"confirmExportTitle": "Export with secrets?",
"confirmExportMessage": "The exported file will contain all secrets (API keys, bot tokens, passwords) in plaintext. Only use this for secure transfers or trusted storage.",
"confirmImportTitle": "Import configuration?",
"confirmImportMessage": "This will create new entities in your database. Make sure you have validated the backup file first.",
"scheduled": "Scheduled Backups",
"enableScheduled": "Enable automatic backups",
"interval": "Interval",
"hours": "hours",
"retention": "Keep last",
"scheduleSaved": "Backup schedule saved",
"savedFiles": "Saved Backups",
"noFiles": "No backup files yet.",
"download": "Download",
"fileDeleted": "Backup file deleted"
}
}
+65
View File
@@ -16,6 +16,7 @@
"cmdTemplateConfigs": "Шаблоны команд",
"users": "Пользователи",
"settings": "Настройки",
"backup": "Бэкап",
"logout": "Выход",
"notification": "Уведомления",
"commands": "Команды",
@@ -1025,6 +1026,8 @@
"criteria": "Критерии",
"persons": "Люди",
"addPerson": "Добавить человека...",
"excludePersons": "Исключить людей",
"addExcludePerson": "Добавить человека для исключения...",
"searchQuery": "Умный поиск",
"searchQueryPlaceholder": "напр. закат, пляж, день рождения...",
"assetType": "Тип файла",
@@ -1053,5 +1056,67 @@
"triggerManual": "вручную",
"triggerDryRun": "пробный",
"triggerScheduled": "по расписанию"
},
"backup": {
"title": "Резервное копирование",
"description": "Экспорт и импорт конфигурации, настройка автоматических бэкапов",
"export": "Экспорт конфигурации",
"exportDescription": "Скачать конфигурацию в формате JSON. Выберите категории для включения.",
"import": "Импорт конфигурации",
"importDescription": "Загрузить ранее экспортированный файл бэкапа для восстановления.",
"categories": "Категории",
"selectAll": "Выбрать все",
"deselectAll": "Снять все",
"catProviders": "Провайдеры",
"catTelegramBots": "Telegram боты",
"catMatrixBots": "Matrix боты",
"catEmailBots": "Email боты",
"catTargets": "Цели",
"catTrackingConfigs": "Конфиги отслеживания",
"catTemplateConfigs": "Конфиги шаблонов",
"catCommandConfigs": "Конфиги команд",
"catCommandTemplateConfigs": "Шаблоны команд",
"catNotificationTrackers": "Трекеры уведомлений",
"catCommandTrackers": "Трекеры команд",
"catActions": "Действия",
"catAppSettings": "Настройки приложения",
"secretsMode": "Секреты",
"secretsExclude": "Исключить секреты (безопасно)",
"secretsMasked": "Маскировать секреты (для проверки)",
"secretsInclude": "Включить секреты (открытый текст)",
"secretsWarningExport": "Внимание: файл экспорта будет содержать конфиденциальные данные (API-ключи, токены, пароли) в открытом виде.",
"exportBtn": "Экспорт",
"exportSuccess": "Конфигурация экспортирована",
"validateBtn": "Проверить",
"validating": "Проверка...",
"validationPassed": "Проверка пройдена",
"validationFailed": "Проверка не пройдена",
"entities": "Сущности",
"conflictMode": "Разрешение конфликтов",
"conflictSkip": "Пропустить существующие (оставить текущие)",
"conflictRename": "Переименовать дубликаты (добавить суффикс)",
"conflictOverwrite": "Перезаписать существующие (заменить)",
"importBtn": "Импорт",
"importing": "Импорт...",
"importSuccess": "Конфигурация импортирована",
"importResults": "Результаты импорта",
"resultCreated": "Создано",
"resultSkipped": "Пропущено",
"resultOverwritten": "Перезаписано",
"resultErrors": "Ошибки",
"confirmExportTitle": "Экспорт с секретами?",
"confirmExportMessage": "Экспортированный файл будет содержать все секреты (API-ключи, токены ботов, пароли) в открытом виде. Используйте только для безопасной передачи.",
"confirmImportTitle": "Импортировать конфигурацию?",
"confirmImportMessage": "Это создаст новые сущности в базе данных. Убедитесь, что файл бэкапа прошёл проверку.",
"scheduled": "Автоматические бэкапы",
"enableScheduled": "Включить автоматическое резервное копирование",
"interval": "Интервал",
"hours": "часов",
"retention": "Хранить последних",
"scheduleSaved": "Расписание бэкапов сохранено",
"savedFiles": "Сохранённые бэкапы",
"noFiles": "Файлов бэкапа пока нет.",
"download": "Скачать",
"fileDeleted": "Файл бэкапа удалён"
}
}
+2
View File
@@ -193,6 +193,7 @@
key: 'nav.settings', icon: 'mdiCogOutline',
children: [
{ href: '/settings', key: 'nav.common', icon: 'mdiCogOutline' },
{ href: '/settings/backup', key: 'nav.backup', icon: 'mdiBackupRestore' },
{ href: '/users', key: 'nav.users', icon: 'mdiAccountGroup' },
],
},
@@ -236,6 +237,7 @@
{ href: '/command-template-configs', key: 'nav.templates', icon: 'mdiCodeBracesBox' },
...(auth.isAdmin ? [
{ href: '/settings', key: 'nav.settings', icon: 'mdiCogOutline' },
{ href: '/settings/backup', key: 'nav.backup', icon: 'mdiBackupRestore' },
{ href: '/users', key: 'nav.users', icon: 'mdiAccountGroup' },
] : []),
]);
+14 -2
View File
@@ -31,7 +31,7 @@
let newRule = $state({
name: '',
rule_config: {
criteria: { person_ids: [] as string[], person_names: [] as string[], query: '', asset_type: 'all', date_from: '', date_to: '', favorite_only: false },
criteria: { person_ids: [] as string[], person_names: [] as string[], exclude_person_ids: [] as string[], exclude_person_names: [] as string[], query: '', asset_type: 'all', date_from: '', date_to: '', favorite_only: false },
target_album_ids: [] as string[], target_album_names: [] as string[],
target_album_id: '', target_album_name: '',
create_album_if_missing: false, create_album_name: '',
@@ -111,7 +111,7 @@
newRule = {
name: '',
rule_config: {
criteria: { person_ids: [], person_names: [], query: '', asset_type: 'all', date_from: '', date_to: '', favorite_only: false },
criteria: { person_ids: [], person_names: [], exclude_person_ids: [] as string[], exclude_person_names: [] as string[], query: '', asset_type: 'all', date_from: '', date_to: '', favorite_only: false },
target_album_ids: [] as string[], target_album_names: [] as string[],
target_album_id: '', target_album_name: '',
create_album_if_missing: false, create_album_name: '',
@@ -228,6 +228,18 @@
ruleConfig.criteria.person_names = ids.map(id => people.find(p => p.id === id)?.name || id);
}} />
</div>
<!-- Person excludes -->
<div>
<label class="block text-xs font-medium mb-1">{t('actions.excludePersons')}</label>
<MultiEntitySelect items={personItems}
bind:values={ruleConfig.criteria.exclude_person_ids}
placeholder={t('actions.addExcludePerson')}
size="sm"
onchange={(ids) => {
ruleConfig.criteria.exclude_person_names = ids.map(id => people.find(p => p.id === id)?.name || id);
}} />
</div>
{/if}
<!-- Smart search query -->
@@ -0,0 +1,570 @@
<script lang="ts">
import { onMount } from 'svelte';
import { api } from '$lib/api';
import { t } from '$lib/i18n';
import PageHeader from '$lib/components/PageHeader.svelte';
import Card from '$lib/components/Card.svelte';
import Loading from '$lib/components/Loading.svelte';
import MdiIcon from '$lib/components/MdiIcon.svelte';
import Hint from '$lib/components/Hint.svelte';
import ErrorBanner from '$lib/components/ErrorBanner.svelte';
import Button from '$lib/components/Button.svelte';
import ConfirmModal from '$lib/components/ConfirmModal.svelte';
import { snackSuccess, snackError } from '$lib/stores/snackbar.svelte';
// --- Export state ---
let exportSecrets = $state('exclude');
let exporting = $state(false);
const categories = [
{ key: 'providers', label: 'backup.catProviders' },
{ key: 'telegram_bots', label: 'backup.catTelegramBots' },
{ key: 'matrix_bots', label: 'backup.catMatrixBots' },
{ key: 'email_bots', label: 'backup.catEmailBots' },
{ key: 'targets', label: 'backup.catTargets' },
{ key: 'tracking_configs', label: 'backup.catTrackingConfigs' },
{ key: 'template_configs', label: 'backup.catTemplateConfigs' },
{ key: 'command_configs', label: 'backup.catCommandConfigs' },
{ key: 'command_template_configs', label: 'backup.catCommandTemplateConfigs' },
{ key: 'notification_trackers', label: 'backup.catNotificationTrackers' },
{ key: 'command_trackers', label: 'backup.catCommandTrackers' },
{ key: 'actions', label: 'backup.catActions' },
{ key: 'app_settings', label: 'backup.catAppSettings' },
];
let selectedCategories = $state<Record<string, boolean>>(
Object.fromEntries(categories.map(c => [c.key, true]))
);
// --- Import state ---
let importFile: File | null = $state(null);
let importConflict = $state('skip');
let importing = $state(false);
let validating = $state(false);
let validationResult: any = $state(null);
let importResult: any = $state(null);
let confirmImportOpen = $state(false);
let confirmExportOpen = $state(false);
// --- Scheduled backup state ---
let loaded = $state(false);
let error = $state('');
let scheduledSettings = $state({
backup_scheduled_enabled: 'false',
backup_scheduled_interval_hours: '24',
backup_secrets_mode: 'exclude',
backup_retention_count: '5',
});
let savingSchedule = $state(false);
// --- Backup files ---
let backupFiles = $state<any[]>([]);
let loadingFiles = $state(false);
let confirmDeleteFile = $state('');
onMount(async () => {
try {
const [settings, files] = await Promise.all([
api('/backup/scheduled'),
api('/backup/files'),
]);
scheduledSettings = settings;
backupFiles = files;
} catch (err: any) {
error = err.message;
snackError(err.message);
} finally {
loaded = true;
}
});
// --- Export ---
async function doExport() {
if (exportSecrets === 'include') {
confirmExportOpen = true;
return;
}
await performExport();
}
async function performExport() {
confirmExportOpen = false;
exporting = true;
try {
const cats = Object.entries(selectedCategories)
.filter(([_, v]) => v)
.map(([k]) => k)
.join(',');
const data = await api(`/backup/export?secrets_mode=${exportSecrets}&categories=${cats}`);
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const ts = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19);
a.download = `notify-bridge-backup-${ts}.json`;
a.click();
URL.revokeObjectURL(url);
snackSuccess(t('backup.exportSuccess'));
} catch (err: any) {
snackError(err.message);
} finally {
exporting = false;
}
}
// --- Validate ---
async function validateFile() {
if (!importFile) return;
validating = true;
validationResult = null;
importResult = null;
try {
const formData = new FormData();
formData.append('file', importFile);
const token = localStorage.getItem('access_token');
const res = await fetch('/api/backup/validate', {
method: 'POST',
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
body: formData,
});
if (!res.ok) {
const err = await res.json().catch(() => ({ detail: res.statusText }));
throw new Error(err.detail || `HTTP ${res.status}`);
}
validationResult = await res.json();
} catch (err: any) {
snackError(err.message);
} finally {
validating = false;
}
}
// --- Import ---
async function doImport() {
confirmImportOpen = true;
}
async function performImport() {
confirmImportOpen = false;
if (!importFile) return;
importing = true;
importResult = null;
try {
const formData = new FormData();
formData.append('file', importFile);
const token = localStorage.getItem('access_token');
const res = await fetch(`/api/backup/import?conflict_mode=${importConflict}`, {
method: 'POST',
headers: token ? { 'Authorization': `Bearer ${token}` } : {},
body: formData,
});
if (!res.ok) {
const err = await res.json().catch(() => ({ detail: res.statusText }));
throw new Error(err.detail || `HTTP ${res.status}`);
}
importResult = await res.json();
snackSuccess(t('backup.importSuccess'));
} catch (err: any) {
snackError(err.message);
} finally {
importing = false;
}
}
// --- Scheduled settings ---
async function saveSchedule() {
savingSchedule = true;
try {
scheduledSettings = await api('/backup/scheduled', {
method: 'PUT',
body: JSON.stringify(scheduledSettings),
});
snackSuccess(t('backup.scheduleSaved'));
} catch (err: any) {
snackError(err.message);
} finally {
savingSchedule = false;
}
}
// --- File management ---
async function refreshFiles() {
loadingFiles = true;
try {
backupFiles = await api('/backup/files');
} catch (err: any) {
snackError(err.message);
} finally {
loadingFiles = false;
}
}
async function downloadFile(filename: string) {
try {
const data = await api(`/backup/files/${filename}`);
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
} catch (err: any) {
snackError(err.message);
}
}
async function deleteFile(filename: string) {
try {
await api(`/backup/files/${filename}`, { method: 'DELETE' });
snackSuccess(t('backup.fileDeleted'));
confirmDeleteFile = '';
await refreshFiles();
} catch (err: any) {
snackError(err.message);
}
}
function handleFileSelect(e: Event) {
const input = e.target as HTMLInputElement;
if (input.files?.length) {
importFile = input.files[0];
validationResult = null;
importResult = null;
}
}
function formatSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
let allSelected = $derived(Object.values(selectedCategories).every(v => v));
let noneSelected = $derived(Object.values(selectedCategories).every(v => !v));
function toggleAll() {
const newVal = !allSelected;
for (const key of Object.keys(selectedCategories)) {
selectedCategories[key] = newVal;
}
}
</script>
<PageHeader title={t('backup.title')} description={t('backup.description')} />
{#if !loaded}
<Loading />
{:else}
<ErrorBanner message={error} />
<div class="space-y-6">
<!-- Export Section -->
<Card>
<h3 class="text-sm font-semibold mb-4 flex items-center gap-2">
<MdiIcon name="mdiDatabaseExport" size={18} />
{t('backup.export')}
</h3>
<p class="text-xs mb-4" style="color: var(--color-muted-foreground);">{t('backup.exportDescription')}</p>
<!-- Categories -->
<div class="mb-4">
<div class="flex items-center gap-2 mb-2">
<label class="text-xs font-medium">{t('backup.categories')}</label>
<button class="text-xs underline" style="color: var(--color-primary);" onclick={toggleAll}>
{allSelected ? t('backup.deselectAll') : t('backup.selectAll')}
</button>
</div>
<div class="grid grid-cols-2 sm:grid-cols-3 gap-1.5">
{#each categories as cat}
<label class="flex items-center gap-1.5 text-xs">
<input type="checkbox" bind:checked={selectedCategories[cat.key]} />
{t(cat.label)}
</label>
{/each}
</div>
</div>
<!-- Secrets mode -->
<div class="mb-4">
<label class="block text-xs font-medium mb-2">{t('backup.secretsMode')}</label>
<div class="flex flex-col gap-1.5">
<label class="flex items-center gap-1.5 text-xs">
<input type="radio" bind:group={exportSecrets} value="exclude" />
{t('backup.secretsExclude')}
</label>
<label class="flex items-center gap-1.5 text-xs">
<input type="radio" bind:group={exportSecrets} value="masked" />
{t('backup.secretsMasked')}
</label>
<label class="flex items-center gap-1.5 text-xs">
<input type="radio" bind:group={exportSecrets} value="include" />
{t('backup.secretsInclude')}
</label>
</div>
{#if exportSecrets === 'include'}
<div class="mt-2 p-2 rounded-md text-xs flex items-center gap-2"
style="background: var(--color-error-bg); color: var(--color-error-fg);">
<MdiIcon name="mdiAlert" size={14} />
{t('backup.secretsWarningExport')}
</div>
{/if}
</div>
<Button onclick={doExport} disabled={exporting || noneSelected}>
{#if exporting}
<MdiIcon name="mdiLoading" size={14} />
{:else}
<MdiIcon name="mdiDownload" size={14} />
{/if}
{exporting ? t('common.loading') : t('backup.exportBtn')}
</Button>
</Card>
<!-- Import Section -->
<Card>
<h3 class="text-sm font-semibold mb-4 flex items-center gap-2">
<MdiIcon name="mdiDatabaseImport" size={18} />
{t('backup.import')}
</h3>
<p class="text-xs mb-4" style="color: var(--color-muted-foreground);">{t('backup.importDescription')}</p>
<!-- File picker -->
<div class="mb-4">
<input type="file" accept=".json" onchange={handleFileSelect}
class="text-xs file:mr-2 file:py-1.5 file:px-3 file:rounded-md file:border-0 file:text-xs file:font-medium file:cursor-pointer"
style="file:background: var(--color-muted); file:color: var(--color-foreground);" />
</div>
{#if importFile}
<!-- Validate -->
<div class="mb-4 flex items-center gap-2">
<Button variant="secondary" onclick={validateFile} disabled={validating}>
{#if validating}
<MdiIcon name="mdiLoading" size={14} />
{:else}
<MdiIcon name="mdiCheckCircleOutline" size={14} />
{/if}
{validating ? t('backup.validating') : t('backup.validateBtn')}
</Button>
</div>
{#if validationResult}
<div class="mb-4 p-3 rounded-md text-xs border" style="border-color: var(--color-border);">
<div class="flex items-center gap-2 mb-2 font-medium">
{#if validationResult.valid}
<MdiIcon name="mdiCheckCircle" size={14} class="text-green-600" />
<span style="color: var(--color-success-fg, green);">{t('backup.validationPassed')}</span>
{:else}
<MdiIcon name="mdiCloseCircle" size={14} />
<span style="color: var(--color-error-fg);">{t('backup.validationFailed')}</span>
{/if}
</div>
{#if Object.keys(validationResult.entity_counts || {}).length}
<div class="mb-2">
<span class="font-medium">{t('backup.entities')}:</span>
{#each Object.entries(validationResult.entity_counts) as [cat, count]}
<span class="inline-block mr-2">{cat}: {count}</span>
{/each}
</div>
{/if}
{#each validationResult.warnings || [] as w}
<div class="flex items-start gap-1 mt-1" style="color: var(--color-warning-fg, orange);">
<MdiIcon name="mdiAlert" size={12} />
<span>{w}</span>
</div>
{/each}
{#each validationResult.errors || [] as e}
<div class="flex items-start gap-1 mt-1" style="color: var(--color-error-fg);">
<MdiIcon name="mdiAlertCircle" size={12} />
<span>{e}</span>
</div>
{/each}
</div>
{/if}
<!-- Conflict mode -->
<div class="mb-4">
<label class="block text-xs font-medium mb-2">{t('backup.conflictMode')}</label>
<div class="flex flex-col gap-1.5">
<label class="flex items-center gap-1.5 text-xs">
<input type="radio" bind:group={importConflict} value="skip" />
{t('backup.conflictSkip')}
</label>
<label class="flex items-center gap-1.5 text-xs">
<input type="radio" bind:group={importConflict} value="rename" />
{t('backup.conflictRename')}
</label>
<label class="flex items-center gap-1.5 text-xs">
<input type="radio" bind:group={importConflict} value="overwrite" />
{t('backup.conflictOverwrite')}
</label>
</div>
</div>
<Button onclick={doImport}
disabled={importing || !validationResult?.valid}>
{#if importing}
<MdiIcon name="mdiLoading" size={14} />
{:else}
<MdiIcon name="mdiUpload" size={14} />
{/if}
{importing ? t('backup.importing') : t('backup.importBtn')}
</Button>
{#if importResult}
<div class="mt-4 p-3 rounded-md text-xs border" style="border-color: var(--color-border);">
<div class="font-medium mb-1">{t('backup.importResults')}</div>
<div class="space-y-0.5">
<div>{t('backup.resultCreated')}: {importResult.created}</div>
<div>{t('backup.resultSkipped')}: {importResult.skipped}</div>
<div>{t('backup.resultOverwritten')}: {importResult.overwritten}</div>
{#if importResult.errors?.length}
<div style="color: var(--color-error-fg);">{t('backup.resultErrors')}: {importResult.errors.length}</div>
{#each importResult.errors as e}
<div class="ml-2" style="color: var(--color-error-fg);">{e}</div>
{/each}
{/if}
{#if importResult.warnings?.length}
{#each importResult.warnings as w}
<div class="ml-2" style="color: var(--color-warning-fg, orange);">{w}</div>
{/each}
{/if}
</div>
</div>
{/if}
{/if}
</Card>
<!-- Scheduled Backups Section -->
<Card>
<h3 class="text-sm font-semibold mb-4 flex items-center gap-2">
<MdiIcon name="mdiClockOutline" size={18} />
{t('backup.scheduled')}
</h3>
<div class="space-y-3">
<label class="flex items-center gap-2 text-xs">
<input type="checkbox"
checked={scheduledSettings.backup_scheduled_enabled === 'true'}
onchange={() => scheduledSettings.backup_scheduled_enabled =
scheduledSettings.backup_scheduled_enabled === 'true' ? 'false' : 'true'} />
<span class="font-medium">{t('backup.enableScheduled')}</span>
</label>
{#if scheduledSettings.backup_scheduled_enabled === 'true'}
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
<div>
<label class="block text-xs font-medium mb-1">{t('backup.interval')}</label>
<select bind:value={scheduledSettings.backup_scheduled_interval_hours}
class="w-full px-3 py-1.5 text-sm border border-[var(--color-border)] rounded-md bg-[var(--color-background)]">
<option value="6">6 {t('backup.hours')}</option>
<option value="12">12 {t('backup.hours')}</option>
<option value="24">24 {t('backup.hours')}</option>
<option value="48">48 {t('backup.hours')}</option>
<option value="72">72 {t('backup.hours')}</option>
<option value="168">168 {t('backup.hours')} (7d)</option>
</select>
</div>
<div>
<label class="block text-xs font-medium mb-1">{t('backup.secretsMode')}</label>
<select bind:value={scheduledSettings.backup_secrets_mode}
class="w-full px-3 py-1.5 text-sm border border-[var(--color-border)] rounded-md bg-[var(--color-background)]">
<option value="exclude">{t('backup.secretsExclude')}</option>
<option value="masked">{t('backup.secretsMasked')}</option>
<option value="include">{t('backup.secretsInclude')}</option>
</select>
</div>
<div>
<label class="block text-xs font-medium mb-1">{t('backup.retention')}</label>
<select bind:value={scheduledSettings.backup_retention_count}
class="w-full px-3 py-1.5 text-sm border border-[var(--color-border)] rounded-md bg-[var(--color-background)]">
<option value="3">3</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
</select>
</div>
</div>
{/if}
</div>
<div class="mt-4">
<Button onclick={saveSchedule} disabled={savingSchedule}>
{savingSchedule ? t('common.loading') : t('common.save')}
</Button>
</div>
</Card>
<!-- Saved Backup Files -->
<Card>
<div class="flex items-center justify-between mb-4">
<h3 class="text-sm font-semibold flex items-center gap-2">
<MdiIcon name="mdiFolder" size={18} />
{t('backup.savedFiles')}
</h3>
<button onclick={refreshFiles} class="text-xs" style="color: var(--color-primary);" disabled={loadingFiles}>
<MdiIcon name="mdiRefresh" size={14} />
</button>
</div>
{#if backupFiles.length === 0}
<p class="text-xs" style="color: var(--color-muted-foreground);">{t('backup.noFiles')}</p>
{:else}
<div class="space-y-2">
{#each backupFiles as file}
<div class="flex items-center justify-between p-2 rounded-md border text-xs"
style="border-color: var(--color-border);">
<div class="flex items-center gap-2">
<MdiIcon name="mdiFileDocument" size={14} />
<span class="font-mono">{file.filename}</span>
<span style="color: var(--color-muted-foreground);">({formatSize(file.size)})</span>
</div>
<div class="flex items-center gap-1">
<button onclick={() => downloadFile(file.filename)}
class="p-1 rounded hover:bg-[var(--color-muted)]" title={t('backup.download')}>
<MdiIcon name="mdiDownload" size={14} />
</button>
<button onclick={() => confirmDeleteFile = file.filename}
class="p-1 rounded hover:bg-[var(--color-muted)]" title={t('common.delete')}
style="color: var(--color-error-fg);">
<MdiIcon name="mdiDelete" size={14} />
</button>
</div>
</div>
{/each}
</div>
{/if}
</Card>
</div>
{/if}
<!-- Confirm plaintext export -->
<ConfirmModal
open={confirmExportOpen}
title={t('backup.confirmExportTitle')}
message={t('backup.confirmExportMessage')}
confirmLabel={t('backup.exportBtn')}
confirmIcon="mdiDownload"
onconfirm={performExport}
oncancel={() => confirmExportOpen = false}
/>
<!-- Confirm import -->
<ConfirmModal
open={confirmImportOpen}
title={t('backup.confirmImportTitle')}
message={t('backup.confirmImportMessage')}
confirmLabel={t('backup.importBtn')}
confirmIcon="mdiUpload"
onconfirm={performImport}
oncancel={() => confirmImportOpen = false}
/>
<!-- Confirm delete file -->
<ConfirmModal
open={!!confirmDeleteFile}
title={t('common.delete')}
message={confirmDeleteFile}
onconfirm={() => deleteFile(confirmDeleteFile)}
oncancel={() => confirmDeleteFile = ''}
/>