feat(immich): per-album scheduled/memory dispatch + template tooling

Dispatch: honor {kind}_collection_mode on TrackingConfig — "per_collection"
fans out one event per album; "combined" pools assets as before. Extract
build_immich_dispatch_events shared by cron and test paths.

Assets: collect_scheduled_assets attaches album_name/album_url/album_public_url
to each asset so combined-mode templates can attribute rows to their source
album. Default scheduled_assets templates render a multi-album header with
inline album list and per-row album link; memory_mode follows the same pattern.

UI: "Reset to default" buttons on notification and command template slots
(per-slot and whole-template), backed by new GET /*-template-configs/defaults
endpoints. tracking-configs "Preview template" now opens an inline preview
modal with locale tabs instead of navigating away; Edit button deep-links
with ?edit_slot=<name> so the destination auto-opens the config and scrolls
to the slot. Reset confirmations use ConfirmModal instead of window.confirm.

Fixes:
* NotificationDispatcher._session_ctx infinite recursion when no shared
  aiohttp.ClientSession was passed — broke test dispatch for periodic/
  scheduled/memory (cron path was unaffected).
* telegram-bots /chats/{id}/test now resolves chat.language_override /
  language_code instead of using the raw ?locale query param, matching
  the resolution the tracker-target test endpoint already used.
* scheduled_assets default template no longer emits a blank line between
  header and the first asset when the multi-album branch is taken.
This commit is contained in:
2026-04-24 19:15:54 +03:00
parent be15463fd2
commit b61394f057
40 changed files with 1235 additions and 224 deletions
+27 -3
View File
@@ -262,7 +262,14 @@
"testPeriodic": "Test periodic summary", "testPeriodic": "Test periodic summary",
"testScheduled": "Test scheduled assets", "testScheduled": "Test scheduled assets",
"testMemory": "Test memory / On This Day", "testMemory": "Test memory / On This Day",
"testDisabledHint": "Enable this feature in the tracker's default Tracking Config first.",
"checkingLinks": "Checking links...", "checkingLinks": "Checking links...",
"featureDiscovery": "Configure periodic summaries, scheduled photo picks, memories, and quiet hours in the default Tracking Config.",
"openTrackingConfig": "Open Tracking Config",
"linkReplace": "Replace",
"linkReplacing": "Replacing...",
"linkReplaceFailed": "Failed to replace link for \"{name}\"",
"linkPasswordProtectedNote": "Telegram users can't open password-protected links without the password. Remove the password in Immich or replace the link.",
"missingLinksTitle": "Albums Missing Public Links", "missingLinksTitle": "Albums Missing Public Links",
"missingLinksDesc": "The following albums don't have public shared links. Without links, notification recipients won't be able to view photos.", "missingLinksDesc": "The following albums don't have public shared links. Without links, notification recipients won't be able to view photos.",
"expired": "Expired", "expired": "Expired",
@@ -552,7 +559,14 @@
"renamed": "renamed", "renamed": "renamed",
"deleted": "deleted", "deleted": "deleted",
"providerType": "Provider Type", "providerType": "Provider Type",
"sortRandom": "Random" "sortRandom": "Random",
"timesInlineHelp": "HH:MM, comma-separated",
"invalidTimeList": "Use HH:MM format, e.g. 09:00 or 09:00, 18:30",
"previewTemplate": "Preview template",
"previewSampleNote": "Rendered with sample data — not your real assets. Shows the shipped default template.",
"editTemplate": "Edit template",
"quietHoursZero": "Quiet period is 0 minutes — adjust times",
"nextDay": "next day"
}, },
"templateConfig": { "templateConfig": {
"title": "Template Configs", "title": "Template Configs",
@@ -598,7 +612,14 @@
"confirmDelete": "Delete this template config?", "confirmDelete": "Delete this template config?",
"invalidFormat": "Invalid format string", "invalidFormat": "Invalid format string",
"filterSlots": "Filter slots...", "filterSlots": "Filter slots...",
"slots": "slots" "slots": "slots",
"resetToDefault": "Reset to default",
"resetAllToDefaults": "Reset all to defaults",
"resetSlotConfirm": "Replace this slot's {locale} template with the shipped default? Your current edits will be lost.",
"resetAllConfirm": "Replace every slot's {locale} template with the shipped defaults? All your {locale} edits will be lost.",
"resetNoDefault": "No shipped default for this slot.",
"resetApplied": "Reset to default (not saved yet — click Save to persist)",
"deepLinkNoConfig": "No template config found for this provider. Create one first."
}, },
"templateVars": { "templateVars": {
"message_assets_added": { "message_assets_added": {
@@ -715,9 +736,12 @@
"quietHours": "Suppress all notifications during this HH:MM window (interpreted in the app timezone). Overnight windows like 22:0007:00 are supported.", "quietHours": "Suppress all notifications during this HH:MM window (interpreted in the app timezone). Overnight windows like 22:0007:00 are supported.",
"favoritesOnly": "Only include assets marked as favorites.", "favoritesOnly": "Only include assets marked as favorites.",
"maxAssets": "Maximum number of asset details to include in a single notification message.", "maxAssets": "Maximum number of asset details to include in a single notification message.",
"periodicStartDate": "The reference date for calculating periodic intervals. Summaries are sent every N days from this date.", "periodicStartDate": "Reference date in the app timezone. The first summary fires at the next configured HH:MM on/after this date, then every N days.",
"intervalDays": "Days between successive summaries. 1 = daily, 7 = weekly.",
"times": "Time(s) of day to send notifications, in HH:MM format. Use commas for multiple times: 09:00,18:00", "times": "Time(s) of day to send notifications, in HH:MM format. Use commas for multiple times: 09:00,18:00",
"albumMode": "Per album: separate notification per album. Combined: one notification with all albums. Random: pick one album randomly.", "albumMode": "Per album: separate notification per album. Combined: one notification with all albums. Random: pick one album randomly.",
"scheduledAlbumMode": "How albums are grouped in scheduled deliveries. Default: Per album (one notification per tracked album).",
"memoryAlbumMode": "How albums are grouped in memory deliveries. Default: Combined (a single notification aggregating matches from all tracked albums).",
"minRating": "Only include assets with at least this star rating (0 = no filter).", "minRating": "Only include assets with at least this star rating (0 = no filter).",
"eventMessages": "Templates for real-time event notifications. Use {variables} for dynamic content.", "eventMessages": "Templates for real-time event notifications. Use {variables} for dynamic content.",
"assetFormatting": "How individual assets are formatted within notification messages.", "assetFormatting": "How individual assets are formatted within notification messages.",
+27 -3
View File
@@ -262,7 +262,14 @@
"testPeriodic": "Тест периодической сводки", "testPeriodic": "Тест периодической сводки",
"testScheduled": "Тест запланированных фото", "testScheduled": "Тест запланированных фото",
"testMemory": "Тест воспоминаний", "testMemory": "Тест воспоминаний",
"testDisabledHint": "Сначала включите эту функцию в привязанной конфигурации отслеживания.",
"checkingLinks": "Проверка ссылок...", "checkingLinks": "Проверка ссылок...",
"featureDiscovery": "Периодические сводки, запланированные подборки, воспоминания и тихие часы настраиваются в привязанной конфигурации отслеживания.",
"openTrackingConfig": "Открыть конфигурацию отслеживания",
"linkReplace": "Пересоздать",
"linkReplacing": "Пересоздание...",
"linkReplaceFailed": "Не удалось пересоздать ссылку для «{name}»",
"linkPasswordProtectedNote": "Получатели в Telegram не смогут открыть защищённую паролем ссылку без пароля. Снимите пароль в Immich или пересоздайте ссылку.",
"missingLinksTitle": "Альбомы без публичных ссылок", "missingLinksTitle": "Альбомы без публичных ссылок",
"missingLinksDesc": "У следующих альбомов нет публичных ссылок. Без ссылок получатели уведомлений не смогут просматривать фото.", "missingLinksDesc": "У следующих альбомов нет публичных ссылок. Без ссылок получатели уведомлений не смогут просматривать фото.",
"expired": "Истёк", "expired": "Истёк",
@@ -552,7 +559,14 @@
"renamed": "переименование", "renamed": "переименование",
"deleted": "удалён", "deleted": "удалён",
"providerType": "Тип провайдера", "providerType": "Тип провайдера",
"sortRandom": "Случайный" "sortRandom": "Случайный",
"timesInlineHelp": "ЧЧ:ММ, через запятую",
"invalidTimeList": "Используйте формат ЧЧ:ММ, например 09:00 или 09:00, 18:30",
"previewTemplate": "Предпросмотр шаблона",
"previewSampleNote": "Отрисовано на демо-данных, не на ваших реальных фото. Показан шаблон по умолчанию.",
"editTemplate": "Редактировать шаблон",
"quietHoursZero": "Тихий период 0 минут — скорректируйте время",
"nextDay": "след. день"
}, },
"templateConfig": { "templateConfig": {
"title": "Конфигурации шаблонов", "title": "Конфигурации шаблонов",
@@ -598,7 +612,14 @@
"confirmDelete": "Удалить эту конфигурацию шаблона?", "confirmDelete": "Удалить эту конфигурацию шаблона?",
"invalidFormat": "Некорректная строка формата", "invalidFormat": "Некорректная строка формата",
"filterSlots": "Фильтр слотов...", "filterSlots": "Фильтр слотов...",
"slots": "слотов" "slots": "слотов",
"resetToDefault": "Сбросить к умолчанию",
"resetAllToDefaults": "Сбросить все к умолчаниям",
"resetSlotConfirm": "Заменить шаблон этого слота ({locale}) на исходный по умолчанию? Ваши правки будут потеряны.",
"resetAllConfirm": "Заменить шаблоны всех слотов ({locale}) на исходные по умолчанию? Все ваши правки для {locale} будут потеряны.",
"resetNoDefault": "Для этого слота нет шаблона по умолчанию.",
"resetApplied": "Сброшено к умолчанию (ещё не сохранено — нажмите «Сохранить»)",
"deepLinkNoConfig": "Не найдено конфигурации шаблонов для этого провайдера. Сначала создайте её."
}, },
"templateVars": { "templateVars": {
"message_assets_added": { "message_assets_added": {
@@ -715,9 +736,12 @@
"quietHours": "Подавляет все уведомления в указанном HH:MM окне (по часовому поясу приложения). Поддерживаются окна через полночь, например 22:0007:00.", "quietHours": "Подавляет все уведомления в указанном HH:MM окне (по часовому поясу приложения). Поддерживаются окна через полночь, например 22:0007:00.",
"favoritesOnly": "Включать только ассеты, отмеченные как избранные.", "favoritesOnly": "Включать только ассеты, отмеченные как избранные.",
"maxAssets": "Максимальное количество ассетов в одном уведомлении.", "maxAssets": "Максимальное количество ассетов в одном уведомлении.",
"periodicStartDate": "Опорная дата для расчёта интервалов. Сводки отправляются каждые N дней от этой даты.", "periodicStartDate": "Опорная дата в часовом поясе приложения. Первая сводка отправится в ближайшее заданное время ЧЧ:ММ, начиная с этой даты, затем каждые N дней.",
"intervalDays": "Период между сводками в днях. 1 = ежедневно, 7 = еженедельно.",
"times": "Время отправки уведомлений в формате ЧЧ:ММ. Для нескольких значений через запятую: 09:00,18:00", "times": "Время отправки уведомлений в формате ЧЧ:ММ. Для нескольких значений через запятую: 09:00,18:00",
"albumMode": "По альбому: отдельное уведомление для каждого. Объединённый: одно уведомление со всеми. Случайный: выбирается один альбом.", "albumMode": "По альбому: отдельное уведомление для каждого. Объединённый: одно уведомление со всеми. Случайный: выбирается один альбом.",
"scheduledAlbumMode": "Как альбомы группируются в запланированных отправках. По умолчанию: По альбому (одно уведомление на каждый отслеживаемый альбом).",
"memoryAlbumMode": "Как альбомы группируются в воспоминаниях. По умолчанию: Объединённый (одно уведомление со всеми совпадениями из всех альбомов).",
"minRating": "Включать только ассеты с рейтингом не ниже указанного (0 = без фильтра).", "minRating": "Включать только ассеты с рейтингом не ниже указанного (0 = без фильтра).",
"eventMessages": "Шаблоны уведомлений о событиях в реальном времени. Используйте {переменные} для динамического контента.", "eventMessages": "Шаблоны уведомлений о событиях в реальном времени. Используйте {переменные} для динамического контента.",
"assetFormatting": "Форматирование отдельных ассетов в сообщениях уведомлений.", "assetFormatting": "Форматирование отдельных ассетов в сообщениях уведомлений.",
+22 -13
View File
@@ -1,5 +1,12 @@
import type { ProviderDescriptor } from './types'; import type { ProviderDescriptor } from './types';
/**
* Today's date in ISO (YYYY-MM-DD) — used as the default for
* `periodic_start_date` so new configs anchor to "today" rather than a
* hardcoded date that gets further into the past on every release.
*/
const todayIso = (): string => new Date().toISOString().slice(0, 10);
export const immichDescriptor: ProviderDescriptor = { export const immichDescriptor: ProviderDescriptor = {
type: 'immich', type: 'immich',
defaultName: 'Immich', defaultName: 'Immich',
@@ -58,17 +65,17 @@ export const immichDescriptor: ProviderDescriptor = {
key: 'periodic', legend: 'trackingConfig.periodicSummary', legendHint: 'hints.periodicSummary', key: 'periodic', legend: 'trackingConfig.periodicSummary', legendHint: 'hints.periodicSummary',
enabledField: 'periodic_enabled', enabledDefault: false, enabledField: 'periodic_enabled', enabledDefault: false,
fields: [ fields: [
{ key: 'periodic_interval_days', label: 'trackingConfig.intervalDays', type: 'number', min: 1, defaultValue: 1 }, { key: 'periodic_interval_days', label: 'trackingConfig.intervalDays', type: 'number', min: 1, defaultValue: 1, hint: 'hints.intervalDays' },
{ key: 'periodic_start_date', label: 'trackingConfig.startDate', type: 'number', defaultValue: '2025-01-01' }, // rendered as date input { key: 'periodic_start_date', label: 'trackingConfig.startDate', type: 'date', defaultValue: todayIso, hint: 'hints.periodicStartDate' },
{ key: 'periodic_times', label: 'trackingConfig.times', type: 'number', defaultValue: '12:00' }, // rendered as text input { key: 'periodic_times', label: 'trackingConfig.times', type: 'time-list', defaultValue: '12:00', hint: 'hints.times', inlineHelp: 'trackingConfig.timesInlineHelp', validateFormat: true },
], ],
}, },
{ {
key: 'scheduled', legend: 'trackingConfig.scheduledAssets', legendHint: 'hints.scheduledAssets', key: 'scheduled', legend: 'trackingConfig.scheduledAssets', legendHint: 'hints.scheduledAssets',
enabledField: 'scheduled_enabled', enabledDefault: false, enabledField: 'scheduled_enabled', enabledDefault: false,
fields: [ fields: [
{ key: 'scheduled_times', label: 'trackingConfig.times', type: 'number', defaultValue: '09:00' }, { key: 'scheduled_times', label: 'trackingConfig.times', type: 'time-list', defaultValue: '09:00', hint: 'hints.times', inlineHelp: 'trackingConfig.timesInlineHelp', validateFormat: true },
{ key: 'scheduled_collection_mode', label: 'trackingConfig.albumMode', type: 'grid-select', gridItems: 'albumModeItems', gridColumns: 3, defaultValue: 'per_collection' }, { key: 'scheduled_collection_mode', label: 'trackingConfig.albumMode', type: 'grid-select', gridItems: 'albumModeItems', gridColumns: 3, defaultValue: 'per_collection', hint: 'hints.scheduledAlbumMode' },
{ key: 'scheduled_limit', label: 'trackingConfig.maxAssets', type: 'number', min: 1, max: 100, defaultValue: 10, hint: 'hints.maxAssets' }, { key: 'scheduled_limit', label: 'trackingConfig.maxAssets', type: 'number', min: 1, max: 100, defaultValue: 10, hint: 'hints.maxAssets' },
{ key: 'scheduled_asset_type', label: 'trackingConfig.assetType', type: 'grid-select', gridItems: 'assetTypeItems', gridColumns: 3, defaultValue: 'all' }, { key: 'scheduled_asset_type', label: 'trackingConfig.assetType', type: 'grid-select', gridItems: 'assetTypeItems', gridColumns: 3, defaultValue: 'all' },
{ key: 'scheduled_min_rating', label: 'trackingConfig.minRating', type: 'number', min: 0, max: 5, defaultValue: 0, hint: 'hints.minRating' }, { key: 'scheduled_min_rating', label: 'trackingConfig.minRating', type: 'number', min: 0, max: 5, defaultValue: 0, hint: 'hints.minRating' },
@@ -79,21 +86,21 @@ export const immichDescriptor: ProviderDescriptor = {
key: 'memory', legend: 'trackingConfig.memoryMode', legendHint: 'hints.memoryMode', key: 'memory', legend: 'trackingConfig.memoryMode', legendHint: 'hints.memoryMode',
enabledField: 'memory_enabled', enabledDefault: false, enabledField: 'memory_enabled', enabledDefault: false,
fields: [ fields: [
{ key: 'memory_times', label: 'trackingConfig.times', type: 'number', defaultValue: '09:00' }, { key: 'memory_times', label: 'trackingConfig.times', type: 'time-list', defaultValue: '09:00', hint: 'hints.times', inlineHelp: 'trackingConfig.timesInlineHelp', validateFormat: true },
{ key: 'memory_collection_mode', label: 'trackingConfig.albumMode', type: 'grid-select', gridItems: 'albumModeItems', gridColumns: 3, defaultValue: 'combined' }, { key: 'memory_collection_mode', label: 'trackingConfig.albumMode', type: 'grid-select', gridItems: 'albumModeItems', gridColumns: 3, defaultValue: 'combined', hint: 'hints.memoryAlbumMode' },
{ key: 'memory_limit', label: 'trackingConfig.maxAssets', type: 'number', min: 1, max: 100, defaultValue: 10 }, { key: 'memory_limit', label: 'trackingConfig.maxAssets', type: 'number', min: 1, max: 100, defaultValue: 10, hint: 'hints.maxAssets' },
{ key: 'memory_asset_type', label: 'trackingConfig.assetType', type: 'grid-select', gridItems: 'assetTypeItems', gridColumns: 3, defaultValue: 'all' }, { key: 'memory_asset_type', label: 'trackingConfig.assetType', type: 'grid-select', gridItems: 'assetTypeItems', gridColumns: 3, defaultValue: 'all' },
{ key: 'memory_min_rating', label: 'trackingConfig.minRating', type: 'number', min: 0, max: 5, defaultValue: 0 }, { key: 'memory_min_rating', label: 'trackingConfig.minRating', type: 'number', min: 0, max: 5, defaultValue: 0, hint: 'hints.minRating' },
{ key: 'memory_favorite_only', label: 'trackingConfig.favoritesOnly', type: 'toggle', defaultValue: false, hint: 'hints.favoritesOnly' }, { key: 'memory_favorite_only', label: 'trackingConfig.favoritesOnly', type: 'toggle', defaultValue: false, hint: 'hints.favoritesOnly' },
{ key: 'memory_source', label: 'trackingConfig.memorySource', type: 'grid-select', gridItems: 'memorySourceItems', gridColumns: 2, defaultValue: 'albums' }, { key: 'memory_source', label: 'trackingConfig.memorySource', type: 'grid-select', gridItems: 'memorySourceItems', gridColumns: 2, defaultValue: 'albums', hint: 'hints.memorySource' },
], ],
}, },
{ {
key: 'quietHours', legend: 'trackingConfig.quietHours', legendHint: 'hints.quietHours', key: 'quietHours', legend: 'trackingConfig.quietHours', legendHint: 'hints.quietHours',
enabledField: 'quiet_hours_enabled', enabledDefault: false, enabledField: 'quiet_hours_enabled', enabledDefault: false,
fields: [ fields: [
{ key: 'quiet_hours_start', label: 'trackingConfig.quietHoursStart', type: 'number', defaultValue: '22:00' }, { key: 'quiet_hours_start', label: 'trackingConfig.quietHoursStart', type: 'time', defaultValue: '22:00' },
{ key: 'quiet_hours_end', label: 'trackingConfig.quietHoursEnd', type: 'number', defaultValue: '07:00' }, { key: 'quiet_hours_end', label: 'trackingConfig.quietHoursEnd', type: 'time', defaultValue: '07:00' },
], ],
}, },
], ],
@@ -114,7 +121,9 @@ export const immichDescriptor: ProviderDescriptor = {
const warnings: { id: string; name: string; issue: string }[] = []; const warnings: { id: string; name: string; issue: string }[] = [];
// Run shared-link checks in parallel with a concurrency cap so a large // Run shared-link checks in parallel with a concurrency cap so a large
// album set doesn't stall the save button for seconds. // album set doesn't stall the save button for seconds. Cap of 6 keeps
// the save dialog responsive for users with 50+ albums while staying
// well under typical Immich per-IP rate limits.
const CONCURRENCY = 6; const CONCURRENCY = 6;
async function checkOne(albumId: string): Promise<void> { async function checkOne(albumId: string): Promise<void> {
try { try {
+5 -2
View File
@@ -47,17 +47,20 @@ export function allProviderTypes(): string[] {
*/ */
export function buildTrackingFormDefaults(): Record<string, any> { export function buildTrackingFormDefaults(): Record<string, any> {
const defaults: Record<string, any> = {}; const defaults: Record<string, any> = {};
// `defaultValue` may be a function (for time-sensitive defaults like
// today's date) so the computed value is fresh each time the form resets.
const resolve = (v: unknown): unknown => (typeof v === 'function' ? (v as () => unknown)() : v);
for (const desc of REGISTRY.values()) { for (const desc of REGISTRY.values()) {
for (const field of desc.eventFields) { for (const field of desc.eventFields) {
defaults[field.key] = field.default; defaults[field.key] = field.default;
} }
for (const extra of desc.extraTrackingFields ?? []) { for (const extra of desc.extraTrackingFields ?? []) {
defaults[extra.key] = extra.defaultValue ?? ''; defaults[extra.key] = resolve(extra.defaultValue) ?? '';
} }
for (const section of desc.featureSections ?? []) { for (const section of desc.featureSections ?? []) {
defaults[section.enabledField] = section.enabledDefault; defaults[section.enabledField] = section.enabledDefault;
for (const f of section.fields) { for (const f of section.fields) {
defaults[f.key] = f.defaultValue ?? ''; defaults[f.key] = resolve(f.defaultValue) ?? '';
} }
for (const cb of section.checkboxes ?? []) { for (const cb of section.checkboxes ?? []) {
defaults[cb.key] = cb.default; defaults[cb.key] = cb.default;
+19 -2
View File
@@ -60,14 +60,31 @@ export interface EventTrackingField {
export interface ExtraTrackingField { export interface ExtraTrackingField {
key: string; key: string;
label: string; label: string;
type: 'number' | 'grid-select' | 'toggle'; /**
* Control kind:
* - `number` — numeric spinner
* - `grid-select` — icon-grid chooser (requires `gridItems`)
* - `toggle` — on/off switch
* - `date` — HTML date picker (YYYY-MM-DD)
* - `time` — HTML time picker (HH:MM)
* - `time-list` — comma-separated HH:MM list, validated on blur
*/
type: 'number' | 'grid-select' | 'toggle' | 'date' | 'time' | 'time-list';
/** Grid-select item source function name from grid-items.ts. */ /** Grid-select item source function name from grid-items.ts. */
gridItems?: string; gridItems?: string;
gridColumns?: number; gridColumns?: number;
hint?: string; hint?: string;
/** Inline helper text rendered under the input (not a tooltip). */
inlineHelp?: string;
min?: number; min?: number;
max?: number; max?: number;
defaultValue?: string | number | boolean; /** For time-list: show live validation + auto-normalize on blur. */
validateFormat?: boolean;
/**
* Default value. Can be a function for dynamic values (e.g. today's date)
* evaluated each time the form is reset.
*/
defaultValue?: string | number | boolean | (() => string | number | boolean);
} }
/** A feature section like periodic summary, scheduled assets, memory mode. */ /** A feature section like periodic summary, scheduled assets, memory mode. */
@@ -54,6 +54,11 @@
let editing = $state<number | null>(null); let editing = $state<number | null>(null);
let error = $state(''); let error = $state('');
let confirmDelete = $state<{ id: number; onconfirm: () => Promise<void> } | null>(null); let confirmDelete = $state<{ id: number; onconfirm: () => Promise<void> } | null>(null);
let confirmReset = $state<{
kind: 'slot' | 'all';
slotKey?: string;
message: string;
} | null>(null);
let slotPreview = $state<Record<string, string>>({}); let slotPreview = $state<Record<string, string>>({});
let slotErrors = $state<Record<string, string>>({}); let slotErrors = $state<Record<string, string>>({});
let slotErrorLines = $state<Record<string, number | null>>({}); let slotErrorLines = $state<Record<string, number | null>>({});
@@ -253,6 +258,58 @@
} }
} }
function resetSlotToDefault(slotKey: string) {
if (!form.provider_type) return;
confirmReset = {
kind: 'slot',
slotKey,
message: t('templateConfig.resetSlotConfirm').replace('{locale}', activeLocale.toUpperCase()),
};
}
function resetAllToDefaults() {
if (!form.provider_type) return;
confirmReset = {
kind: 'all',
message: t('templateConfig.resetAllConfirm').replace(/\{locale\}/g, activeLocale.toUpperCase()),
};
}
async function performReset() {
if (!confirmReset || !form.provider_type) return;
const { kind, slotKey } = confirmReset;
confirmReset = null;
try {
if (kind === 'slot' && slotKey) {
const res = await api<Record<string, Record<string, string>>>(
`/command-template-configs/defaults?provider_type=${encodeURIComponent(form.provider_type)}&slot_name=${encodeURIComponent(slotKey)}&locale=${encodeURIComponent(activeLocale)}`,
);
const text = res?.[slotKey]?.[activeLocale];
if (!text) {
snackError(t('templateConfig.resetNoDefault'));
return;
}
setSlotValue(slotKey, text);
validateSlot(slotKey, text, true);
} else {
const res = await api<Record<string, Record<string, string>>>(
`/command-template-configs/defaults?provider_type=${encodeURIComponent(form.provider_type)}&locale=${encodeURIComponent(activeLocale)}`,
);
const nextSlots = { ...form.slots };
for (const [key, localeMap] of Object.entries(res || {})) {
const text = localeMap?.[activeLocale];
if (text === undefined) continue;
nextSlots[key] = { ...(nextSlots[key] || {}), [activeLocale]: text };
}
form.slots = nextSlots;
refreshAllPreviews();
}
snackSuccess(t('templateConfig.resetApplied'));
} catch (err: any) {
snackError(err.message);
}
}
function clone(c: CmdTemplateConfig) { function clone(c: CmdTemplateConfig) {
const slotsCopy: Record<string, Record<string, string>> = {}; const slotsCopy: Record<string, Record<string, string>> = {};
for (const [k, v] of Object.entries(c.slots)) { for (const [k, v] of Object.entries(c.slots)) {
@@ -343,7 +400,7 @@
<p class="text-xs text-[var(--color-muted-foreground)] mb-2">{t('cmdTemplateConfig.commandResponsesHint')}</p> <p class="text-xs text-[var(--color-muted-foreground)] mb-2">{t('cmdTemplateConfig.commandResponsesHint')}</p>
<!-- Locale tabs --> <!-- Locale tabs -->
<div class="flex gap-1 mb-3 border-b border-[var(--color-border)]"> <div class="flex items-center gap-1 mb-3 border-b border-[var(--color-border)]">
{#each LOCALES as loc} {#each LOCALES as loc}
<button type="button" <button type="button"
class="px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors {activeLocale === loc ? 'bg-[var(--color-primary)] text-[var(--color-primary-foreground)]' : 'text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]'}" class="px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors {activeLocale === loc ? 'bg-[var(--color-primary)] text-[var(--color-primary-foreground)]' : 'text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]'}"
@@ -351,6 +408,14 @@
{loc.toUpperCase()} {loc.toUpperCase()}
</button> </button>
{/each} {/each}
{#if form.provider_type}
<button type="button" onclick={resetAllToDefaults}
title={t('templateConfig.resetAllToDefaults')}
class="ml-auto flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-[var(--color-border)] text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]">
<MdiIcon name="mdiRefresh" size={12} />
{t('templateConfig.resetAllToDefaults')}
</button>
{/if}
</div> </div>
<!-- Slot filter --> <!-- Slot filter -->
@@ -381,6 +446,11 @@
<button type="button" onclick={() => showVarsFor = slot.name} <button type="button" onclick={() => showVarsFor = slot.name}
class="text-xs text-[var(--color-muted-foreground)] hover:underline">{t('templateConfig.variables')}</button> class="text-xs text-[var(--color-muted-foreground)] hover:underline">{t('templateConfig.variables')}</button>
{/if} {/if}
<button type="button" onclick={() => resetSlotToDefault(slot.name)}
title={t('templateConfig.resetToDefault')}
class="text-xs text-[var(--color-muted-foreground)] hover:underline">
{t('templateConfig.resetToDefault')}
</button>
</div> </div>
{#if showPreviewFor.has(slot.name) && slotPreview[slot.name] && !slotErrors[slot.name]} {#if showPreviewFor.has(slot.name) && slotPreview[slot.name] && !slotErrors[slot.name]}
@@ -472,6 +542,14 @@
<ConfirmModal open={confirmDelete !== null} message={t('cmdTemplateConfig.confirmDelete')} <ConfirmModal open={confirmDelete !== null} message={t('cmdTemplateConfig.confirmDelete')}
onconfirm={() => confirmDelete?.onconfirm()} oncancel={() => confirmDelete = null} /> onconfirm={() => confirmDelete?.onconfirm()} oncancel={() => confirmDelete = null} />
<ConfirmModal open={confirmReset !== null}
title={t('templateConfig.resetToDefault')}
message={confirmReset?.message || ''}
confirmLabel={confirmReset?.kind === 'all' ? t('templateConfig.resetAllToDefaults') : t('templateConfig.resetToDefault')}
confirmIcon="mdiRefresh"
onconfirm={performReset}
oncancel={() => confirmReset = null} />
<BlockedByModal open={!!blockedBy} detail={blockedBy} onclose={() => blockedBy = null} /> <BlockedByModal open={!!blockedBy} detail={blockedBy} onclose={() => blockedBy = null} />
<!-- Variables reference modal --> <!-- Variables reference modal -->
@@ -84,17 +84,23 @@
let testMenuStyle = $state(''); let testMenuStyle = $state('');
// Test types: basic is always available; periodic/scheduled/memory only for providers // Test types: basic is always available; periodic/scheduled/memory only for providers
// that have those notification slots in their capabilities // that have those notification slots in their capabilities AND have the feature
const allTestTypes: Record<string, { key: string; icon: string; labelKey: string; requiredSlot?: string }> = { // enabled on the tracker's default TrackingConfig. A disabled feature on the
// default config means cron dispatch won't fire it in production either — so
// the test button would just surface a silent skip.
const allTestTypes: Record<string, {
key: string; icon: string; labelKey: string;
requiredSlot?: string; enabledField?: string;
}> = {
basic: { key: 'basic', icon: 'mdiSend', labelKey: 'notificationTracker.testBasic' }, basic: { key: 'basic', icon: 'mdiSend', labelKey: 'notificationTracker.testBasic' },
periodic: { key: 'periodic', icon: 'mdiCalendarClock', labelKey: 'notificationTracker.testPeriodic', requiredSlot: 'periodic_summary_message' }, periodic: { key: 'periodic', icon: 'mdiCalendarClock', labelKey: 'notificationTracker.testPeriodic', requiredSlot: 'periodic_summary_message', enabledField: 'periodic_enabled' },
scheduled: { key: 'scheduled', icon: 'mdiCalendarCheck', labelKey: 'notificationTracker.testScheduled', requiredSlot: 'scheduled_assets_message' }, scheduled: { key: 'scheduled', icon: 'mdiCalendarCheck', labelKey: 'notificationTracker.testScheduled', requiredSlot: 'scheduled_assets_message', enabledField: 'scheduled_enabled' },
memory: { key: 'memory', icon: 'mdiHistory', labelKey: 'notificationTracker.testMemory', requiredSlot: 'memory_mode_message' }, memory: { key: 'memory', icon: 'mdiHistory', labelKey: 'notificationTracker.testMemory', requiredSlot: 'memory_mode_message', enabledField: 'memory_enabled' },
}; };
let testMenuTrackerId = $state<number | null>(null); let testMenuTrackerId = $state<number | null>(null);
let testTypes = $derived.by(() => { let testTypes = $derived.by(() => {
const base = [allTestTypes.basic]; const base: { key: string; icon: string; labelKey: string; disabledReason?: string }[] = [allTestTypes.basic];
if (!testMenuTrackerId) return base; if (!testMenuTrackerId) return base;
const tracker = notificationTrackers.find(t => t.id === testMenuTrackerId); const tracker = notificationTrackers.find(t => t.id === testMenuTrackerId);
if (!tracker) return base; if (!tracker) return base;
@@ -103,8 +109,18 @@
const caps = allCapabilities[provider.type]; const caps = allCapabilities[provider.type];
if (!caps) return base; if (!caps) return base;
const slotNames = new Set((caps.notification_slots || []).map((s: any) => s.name)); const slotNames = new Set((caps.notification_slots || []).map((s: any) => s.name));
const defaultTc = trackingConfigs.find(c => c.id === tracker.default_tracking_config_id);
for (const tt of [allTestTypes.periodic, allTestTypes.scheduled, allTestTypes.memory]) { for (const tt of [allTestTypes.periodic, allTestTypes.scheduled, allTestTypes.memory]) {
if (tt.requiredSlot && slotNames.has(tt.requiredSlot)) base.push(tt); if (!tt.requiredSlot || !slotNames.has(tt.requiredSlot)) continue;
const enabled = !!defaultTc && !!tt.enabledField && !!(defaultTc as any)[tt.enabledField];
base.push({
key: tt.key, icon: tt.icon, labelKey: tt.labelKey,
// When surfaced, the button still renders but is disabled and
// shows *why* — users who land here via the test menu without
// having toggled the feature on Tracking Config see a clear
// pointer to the missing setting instead of a silent failure.
disabledReason: enabled ? undefined : 'notificationTracker.testDisabledHint',
});
} }
return base; return base;
}); });
@@ -516,6 +532,15 @@
onclose={() => { linkWarning = null; }} onclose={() => { linkWarning = null; }}
onautoCreate={autoCreateLinks} onautoCreate={autoCreateLinks}
ondismiss={dismissLinkWarning} ondismiss={dismissLinkWarning}
onupdate={(remaining) => {
if (!linkWarning) return;
if (remaining.length === 0) {
linkWarning = null;
doSave();
} else {
linkWarning = { ...linkWarning, albums: remaining };
}
}}
/> />
<ConfirmModal <ConfirmModal
@@ -1,17 +1,50 @@
<script lang="ts"> <script lang="ts">
import { t } from '$lib/i18n'; import { t } from '$lib/i18n';
import { api } from '$lib/api';
import { snackError, snackSuccess } from '$lib/stores/snackbar.svelte';
import Modal from '$lib/components/Modal.svelte'; import Modal from '$lib/components/Modal.svelte';
import MdiIcon from '$lib/components/MdiIcon.svelte'; import MdiIcon from '$lib/components/MdiIcon.svelte';
interface AlbumIssue { id: string; name: string; issue: string }
interface Props { interface Props {
linkWarning: { albums: any[]; providerId: number } | null; linkWarning: { albums: AlbumIssue[]; providerId: number } | null;
linkCreating: boolean; linkCreating: boolean;
onclose: () => void; onclose: () => void;
onautoCreate: () => void; onautoCreate: () => void;
ondismiss: () => void; ondismiss: () => void;
/** Called with the updated warning list after a per-row replace. */
onupdate?: (albums: AlbumIssue[]) => void;
} }
let { linkWarning, linkCreating, onclose, onautoCreate, ondismiss }: Props = $props(); let { linkWarning, linkCreating, onclose, onautoCreate, ondismiss, onupdate }: Props = $props();
/** Per-row loading state for the "Replace" button. */
let replacing = $state<Record<string, boolean>>({});
/**
* Expired and password-protected links can't be repaired in place — the
* Immich API has no "reset" endpoint. The only remedy is to recreate the
* link (which the backend does by POSTing a new one and returning it).
* We surface the action per-row so users don't have to leave the form.
*/
async function replaceOne(album: AlbumIssue) {
if (!linkWarning) return;
replacing = { ...replacing, [album.id]: true };
try {
await api(`/providers/${linkWarning.providerId}/albums/${album.id}/shared-links`, {
method: 'POST',
body: JSON.stringify({ replace: true }),
});
snackSuccess(t('notificationTracker.createdLinks').replace('{count}', '1'));
const remaining = linkWarning.albums.filter(a => a.id !== album.id);
if (onupdate) onupdate(remaining);
} catch (err: any) {
snackError(t('notificationTracker.linkReplaceFailed').replace('{name}', album.name) + ': ' + err.message);
} finally {
replacing = { ...replacing, [album.id]: false };
}
}
</script> </script>
<Modal open={linkWarning !== null} title={t('notificationTracker.missingLinksTitle')} onclose={onclose}> <Modal open={linkWarning !== null} title={t('notificationTracker.missingLinksTitle')} onclose={onclose}>
@@ -19,13 +52,26 @@
<p class="text-sm mb-3" style="color: var(--color-muted-foreground);"> <p class="text-sm mb-3" style="color: var(--color-muted-foreground);">
{t('notificationTracker.missingLinksDesc')} {t('notificationTracker.missingLinksDesc')}
</p> </p>
<div class="space-y-1.5 mb-4 max-h-40 overflow-y-auto"> <div class="space-y-1.5 mb-4 max-h-60 overflow-y-auto">
{#each linkWarning.albums as album} {#each linkWarning.albums as album}
<div class="flex items-center justify-between text-sm px-2 py-1.5 rounded bg-[var(--color-muted)]/30"> <div class="flex items-center justify-between gap-2 text-sm px-2 py-1.5 rounded bg-[var(--color-muted)]/30">
<span class="font-medium">{album.name}</span> <div class="flex-1 min-w-0">
<span class="text-xs px-1.5 py-0.5 rounded {album.issue === 'expired' ? 'bg-[var(--color-error-bg)] text-[var(--color-error-fg)]' : album.issue === 'password-protected' ? 'bg-[var(--color-warning-bg)] text-[var(--color-warning-fg)]' : 'bg-[var(--color-muted)] text-[var(--color-muted-foreground)]'}"> <span class="font-medium truncate block">{album.name}</span>
{#if album.issue === 'password-protected'}
<span class="text-[10px] block" style="color: var(--color-muted-foreground);">
{t('notificationTracker.linkPasswordProtectedNote')}
</span>
{/if}
</div>
<span class="text-xs px-1.5 py-0.5 rounded shrink-0 {album.issue === 'expired' ? 'bg-[var(--color-error-bg)] text-[var(--color-error-fg)]' : album.issue === 'password-protected' ? 'bg-[var(--color-warning-bg)] text-[var(--color-warning-fg)]' : 'bg-[var(--color-muted)] text-[var(--color-muted-foreground)]'}">
{album.issue === 'expired' ? t('notificationTracker.expired') : album.issue === 'password-protected' ? t('notificationTracker.passwordProtected') : t('notificationTracker.noLink')} {album.issue === 'expired' ? t('notificationTracker.expired') : album.issue === 'password-protected' ? t('notificationTracker.passwordProtected') : t('notificationTracker.noLink')}
</span> </span>
{#if album.issue === 'expired' || album.issue === 'password-protected'}
<button type="button" onclick={() => replaceOne(album)} disabled={replacing[album.id]}
class="text-xs px-2 py-1 rounded border border-[var(--color-border)] hover:bg-[var(--color-muted)] disabled:opacity-50 shrink-0">
{replacing[album.id] ? t('notificationTracker.linkReplacing') : t('notificationTracker.linkReplace')}
</button>
{/if}
</div> </div>
{/each} {/each}
</div> </div>
@@ -6,7 +6,13 @@
testMenuOpen: string | null; testMenuOpen: string | null;
testMenuStyle: string; testMenuStyle: string;
ttTesting: Record<string, string>; ttTesting: Record<string, string>;
testTypes: { key: string; icon: string; labelKey: string }[]; /**
* When `disabledReason` is set, the button is rendered greyed out with a
* tooltip pointing the user at the missing setting (e.g. "Enable Periodic
* Summary in Tracking Config first"). Clicking is blocked — clicking an
* unconfigured test would have surfaced as a silent server-side skip.
*/
testTypes: { key: string; icon: string; labelKey: string; disabledReason?: string }[];
ontest: (ttId: number, testType: string) => void; ontest: (ttId: number, testType: string) => void;
onclose: () => void; onclose: () => void;
} }
@@ -20,18 +26,27 @@
onclick={onclose} onclick={onclose}
onkeydown={(e) => { if (e.key === 'Escape') onclose(); }}> onkeydown={(e) => { if (e.key === 'Escape') onclose(); }}>
</div> </div>
<div style="{testMenuStyle} background:var(--color-card); border:1px solid var(--color-border); border-radius:0.5rem; box-shadow:0 10px 25px rgba(0,0,0,0.3); padding:0.25rem; min-width:10rem;"> <div style="{testMenuStyle} background:var(--color-card); border:1px solid var(--color-border); border-radius:0.5rem; box-shadow:0 10px 25px rgba(0,0,0,0.3); padding:0.25rem; min-width:12rem;">
{#each testTypes as tt} {#each testTypes as tt}
{@const busy = !!ttTesting[`${testMenuOpen}_${tt.key}`]}
{@const blocked = !!tt.disabledReason}
<button <button
onclick={() => ontest(Number(testMenuOpen), tt.key)} onclick={() => { if (!blocked) ontest(Number(testMenuOpen), tt.key); }}
disabled={!!ttTesting[`${testMenuOpen}_${tt.key}`]} disabled={busy || blocked}
title={blocked ? t(tt.disabledReason!) : ''}
class="flex items-center gap-2 w-full px-3 py-1.5 text-sm rounded hover:bg-[var(--color-muted)] transition-colors disabled:opacity-50 text-left"> class="flex items-center gap-2 w-full px-3 py-1.5 text-sm rounded hover:bg-[var(--color-muted)] transition-colors disabled:opacity-50 text-left">
<MdiIcon name={tt.icon} size={14} /> <MdiIcon name={tt.icon} size={14} />
{t(tt.labelKey)} {t(tt.labelKey)}
{#if ttTesting[`${testMenuOpen}_${tt.key}`]} {#if blocked}
<MdiIcon name="mdiLock" size={12} />
{/if}
{#if busy}
<span class="ml-auto text-xs text-[var(--color-muted-foreground)]">...</span> <span class="ml-auto text-xs text-[var(--color-muted-foreground)]">...</span>
{/if} {/if}
</button> </button>
{#if blocked}
<p class="px-3 pb-1 text-[10px]" style="color: var(--color-muted-foreground);">{t(tt.disabledReason!)}</p>
{/if}
{/each} {/each}
</div> </div>
{/if} {/if}
@@ -4,6 +4,7 @@
import Card from '$lib/components/Card.svelte'; import Card from '$lib/components/Card.svelte';
import IconPicker from '$lib/components/IconPicker.svelte'; import IconPicker from '$lib/components/IconPicker.svelte';
import Hint from '$lib/components/Hint.svelte'; import Hint from '$lib/components/Hint.svelte';
import MdiIcon from '$lib/components/MdiIcon.svelte';
import EntitySelect from '$lib/components/EntitySelect.svelte'; import EntitySelect from '$lib/components/EntitySelect.svelte';
import MultiEntitySelect from '$lib/components/MultiEntitySelect.svelte'; import MultiEntitySelect from '$lib/components/MultiEntitySelect.svelte';
import { getDescriptor } from '$lib/providers'; import { getDescriptor } from '$lib/providers';
@@ -199,6 +200,22 @@
</div> </div>
{/if} {/if}
<!-- Feature discovery: the periodic/scheduled/memory/quiet-hours controls
live on the tracking config, not on the tracker itself. Surface this
here so users don't have to stumble onto the feature by reading docs. -->
{#if providerType === 'immich'}
<div class="flex items-start gap-2 rounded-md border border-[var(--color-border)] bg-[var(--color-muted)]/30 px-3 py-2">
<span style="color: var(--color-primary);"><MdiIcon name="mdiInformationOutline" size={16} /></span>
<div class="flex-1 text-xs">
<p style="color: var(--color-muted-foreground);">{t('notificationTracker.featureDiscovery')}</p>
<a href="/tracking-configs" class="inline-flex items-center gap-1 text-[var(--color-primary)] hover:underline mt-1">
<MdiIcon name="mdiArrowRight" size={12} />
{t('notificationTracker.openTrackingConfig')}
</a>
</div>
</div>
{/if}
<button type="submit" disabled={submitting || linkCheckLoading} class="px-4 py-2 bg-[var(--color-primary)] text-[var(--color-primary-foreground)] rounded-md text-sm font-medium hover:opacity-90 disabled:opacity-50"> <button type="submit" disabled={submitting || linkCheckLoading} class="px-4 py-2 bg-[var(--color-primary)] text-[var(--color-primary-foreground)] rounded-md text-sm font-medium hover:opacity-90 disabled:opacity-50">
{#if linkCheckLoading}{t('notificationTracker.checkingLinks')}{:else}{editing ? t('common.save') : t('notificationTracker.createTracker')}{/if} {#if linkCheckLoading}{t('notificationTracker.checkingLinks')}{:else}{editing ? t('common.save') : t('notificationTracker.createTracker')}{/if}
</button> </button>
@@ -42,6 +42,17 @@
let editing = $state<number | null>(null); let editing = $state<number | null>(null);
let error = $state(''); let error = $state('');
let confirmDelete = $state<{ id: number; onconfirm: () => Promise<void> } | null>(null); let confirmDelete = $state<{ id: number; onconfirm: () => Promise<void> } | null>(null);
/**
* Reset-to-default confirmation prompt. ``kind: 'slot'`` confirms a
* single-slot reset (slotKey populated); ``'all'`` confirms a full
* locale-scoped wipe. Split from confirmDelete so the two flows can
* coexist without stomping each other's state mid-dialog.
*/
let confirmReset = $state<{
kind: 'slot' | 'all';
slotKey?: string;
message: string;
} | null>(null);
let slotPreview = $state<Record<string, string>>({}); let slotPreview = $state<Record<string, string>>({});
let slotErrors = $state<Record<string, string>>({}); let slotErrors = $state<Record<string, string>>({});
let slotErrorLines = $state<Record<string, number | null>>({}); let slotErrorLines = $state<Record<string, number | null>>({});
@@ -206,7 +217,40 @@
supportedLocalesCache.fetch(), supportedLocalesCache.fetch(),
]); ]);
} catch (err: any) { error = err.message || t('common.loadError'); snackError(error); } } catch (err: any) { error = err.message || t('common.loadError'); snackError(error); }
finally { loaded = true; highlightFromUrl(); } finally { loaded = true; highlightFromUrl(); handleDeepLink(); }
}
/**
* Respond to ``?edit_slot=<slot_name>&provider=<type>`` deep-links from
* other pages (currently the tracking-configs Preview-template modal).
* Picks the first visible config matching ``provider``, opens it in edit
* mode, and pre-expands the target slot. Strips the param from the URL so
* a subsequent reload doesn't reopen the form unexpectedly.
*/
function handleDeepLink() {
if (typeof window === 'undefined') return;
const params = new URLSearchParams(window.location.search);
const slot = params.get('edit_slot');
if (!slot) return;
const provider = params.get('provider') || '';
const target = allTemplateConfigs.find(
c => !provider || c.provider_type === provider,
);
// Strip the deep-link param so reload/back doesn't replay it.
params.delete('edit_slot');
const qs = params.toString();
window.history.replaceState(null, '', window.location.pathname + (qs ? '?' + qs : ''));
if (!target) {
snackError(t('templateConfig.deepLinkNoConfig'));
return;
}
edit(target);
expandedSlots = new Set([slot]);
// Scroll the slot into view once the form has rendered.
setTimeout(() => {
const el = document.getElementById(`slot-${slot}`);
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
}, 200);
} }
function openNew() { function openNew() {
@@ -241,6 +285,65 @@
} catch (err: any) { error = err.message; snackError(err.message); } } catch (err: any) { error = err.message; snackError(err.message); }
} }
/**
* Ask the user to confirm a reset. The actual fetch+replace runs in
* ``performReset`` after the ConfirmModal's onconfirm fires. Split into
* two steps so we can use the app-wide ConfirmModal (consistent look,
* keyboard handling) instead of ``window.confirm`` (blocks the page).
*/
function resetSlotToDefault(slotKey: string) {
if (!form.provider_type) return;
confirmReset = {
kind: 'slot',
slotKey,
message: t('templateConfig.resetSlotConfirm').replace('{locale}', activeLocale.toUpperCase()),
};
}
function resetAllToDefaults() {
if (!form.provider_type) return;
confirmReset = {
kind: 'all',
message: t('templateConfig.resetAllConfirm').replace(/\{locale\}/g, activeLocale.toUpperCase()),
};
}
async function performReset() {
if (!confirmReset || !form.provider_type) return;
const { kind, slotKey } = confirmReset;
confirmReset = null;
try {
if (kind === 'slot' && slotKey) {
const res = await api<Record<string, Record<string, string>>>(
`/template-configs/defaults?provider_type=${encodeURIComponent(form.provider_type)}&slot_name=${encodeURIComponent(slotKey)}&locale=${encodeURIComponent(activeLocale)}`,
);
const text = res?.[slotKey]?.[activeLocale];
if (!text) {
snackError(t('templateConfig.resetNoDefault'));
return;
}
setSlotValue(slotKey, text);
validateSlot(slotKey, text, true);
} else {
const res = await api<Record<string, Record<string, string>>>(
`/template-configs/defaults?provider_type=${encodeURIComponent(form.provider_type)}&locale=${encodeURIComponent(activeLocale)}`,
);
// Replace current-locale slots; leave other locales' values untouched.
const nextSlots = { ...form.slots };
for (const [key, localeMap] of Object.entries(res || {})) {
const text = localeMap?.[activeLocale];
if (text === undefined) continue;
nextSlots[key] = { ...(nextSlots[key] || {}), [activeLocale]: text };
}
form.slots = nextSlots;
refreshAllPreviews();
}
snackSuccess(t('templateConfig.resetApplied'));
} catch (err: any) {
snackError(err.message);
}
}
function clone(c: TemplateConfig) { function clone(c: TemplateConfig) {
form = { form = {
provider_type: c.provider_type, provider_type: c.provider_type,
@@ -321,7 +424,7 @@
</div> </div>
<!-- Locale tabs --> <!-- Locale tabs -->
<div class="flex gap-1 mb-3 border-b border-[var(--color-border)]"> <div class="flex items-center gap-1 mb-3 border-b border-[var(--color-border)]">
{#each LOCALES as loc} {#each LOCALES as loc}
<button type="button" <button type="button"
class="px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors {activeLocale === loc ? 'bg-[var(--color-primary)] text-[var(--color-primary-foreground)]' : 'text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]'}" class="px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors {activeLocale === loc ? 'bg-[var(--color-primary)] text-[var(--color-primary-foreground)]' : 'text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]'}"
@@ -329,6 +432,14 @@
{loc.toUpperCase()} {loc.toUpperCase()}
</button> </button>
{/each} {/each}
{#if form.provider_type}
<button type="button" onclick={resetAllToDefaults}
title={t('templateConfig.resetAllToDefaults')}
class="ml-auto flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-[var(--color-border)] text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]">
<MdiIcon name="mdiRefresh" size={12} />
{t('templateConfig.resetAllToDefaults')}
</button>
{/if}
</div> </div>
<!-- Slot filter --> <!-- Slot filter -->
@@ -361,6 +472,7 @@
{/if} {/if}
</div> </div>
{:else} {:else}
<div id="slot-{slot.key}">
<CollapsibleSlot <CollapsibleSlot
label={slot.key} label={slot.key}
description={slot.description || t(`templateConfig.${slot.label}`, slot.label)} description={slot.description || t(`templateConfig.${slot.label}`, slot.label)}
@@ -379,6 +491,11 @@
<button type="button" onclick={() => showVarsFor = slot.key} <button type="button" onclick={() => showVarsFor = slot.key}
class="text-xs text-[var(--color-muted-foreground)] hover:underline">{t('templateConfig.variables')}</button> class="text-xs text-[var(--color-muted-foreground)] hover:underline">{t('templateConfig.variables')}</button>
{/if} {/if}
<button type="button" onclick={() => resetSlotToDefault(slot.key)}
title={t('templateConfig.resetToDefault')}
class="text-xs text-[var(--color-muted-foreground)] hover:underline">
{t('templateConfig.resetToDefault')}
</button>
</div> </div>
{#if showPreviewFor.has(slot.key) && slotPreview[slot.key] && !slotErrors[slot.key]} {#if showPreviewFor.has(slot.key) && slotPreview[slot.key] && !slotErrors[slot.key]}
@@ -397,6 +514,7 @@
{/if} {/if}
{/if} {/if}
</CollapsibleSlot> </CollapsibleSlot>
</div>
{/if} {/if}
{/each} {/each}
</div> </div>
@@ -466,6 +584,14 @@
<ConfirmModal open={confirmDelete !== null} message={t('templateConfig.confirmDelete')} <ConfirmModal open={confirmDelete !== null} message={t('templateConfig.confirmDelete')}
onconfirm={() => confirmDelete?.onconfirm()} oncancel={() => confirmDelete = null} /> onconfirm={() => confirmDelete?.onconfirm()} oncancel={() => confirmDelete = null} />
<ConfirmModal open={confirmReset !== null}
title={t('templateConfig.resetToDefault')}
message={confirmReset?.message || ''}
confirmLabel={confirmReset?.kind === 'all' ? t('templateConfig.resetAllToDefaults') : t('templateConfig.resetToDefault')}
confirmIcon="mdiRefresh"
onconfirm={performReset}
oncancel={() => confirmReset = null} />
<BlockedByModal open={!!blockedBy} detail={blockedBy} onclose={() => blockedBy = null} /> <BlockedByModal open={!!blockedBy} detail={blockedBy} onclose={() => blockedBy = null} />
<!-- Variables reference modal --> <!-- Variables reference modal -->
+232 -11
View File
@@ -12,6 +12,9 @@
import MdiIcon from '$lib/components/MdiIcon.svelte'; import MdiIcon from '$lib/components/MdiIcon.svelte';
import EmptyState from '$lib/components/EmptyState.svelte'; import EmptyState from '$lib/components/EmptyState.svelte';
import ConfirmModal from '$lib/components/ConfirmModal.svelte'; import ConfirmModal from '$lib/components/ConfirmModal.svelte';
import Modal from '$lib/components/Modal.svelte';
import { sanitizePreview } from '$lib/sanitize';
import { supportedLocalesCache } from '$lib/stores/caches.svelte';
import Hint from '$lib/components/Hint.svelte'; import Hint from '$lib/components/Hint.svelte';
import IconButton from '$lib/components/IconButton.svelte'; import IconButton from '$lib/components/IconButton.svelte';
import IconGridSelect from '$lib/components/IconGridSelect.svelte'; import IconGridSelect from '$lib/components/IconGridSelect.svelte';
@@ -22,13 +25,150 @@
import { getDescriptor, buildTrackingFormDefaults } from '$lib/providers'; import { getDescriptor, buildTrackingFormDefaults } from '$lib/providers';
import ErrorBanner from '$lib/components/ErrorBanner.svelte'; import ErrorBanner from '$lib/components/ErrorBanner.svelte';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
import type { TrackingConfig } from '$lib/types';
/** Grid-select item source lookup — maps descriptor string name to actual function. */ /** Grid-select item source lookup — maps descriptor string name to actual function. */
const gridItemSources: Record<string, () => any[]> = { const gridItemSources: Record<string, () => any[]> = {
sortByItems, sortOrderItems, albumModeItems, assetTypeItems, memorySourceItems, sortByItems, sortOrderItems, albumModeItems, assetTypeItems, memorySourceItems,
}; };
/**
* HH:MM, comma-separated: "09:00" or "09:00, 18:30" — the only format cron
* dispatch accepts. Matched on blur for time-list fields; invalid values
* are surfaced inline next to the input.
*/
const TIME_LIST_RE = /^\s*(?:[01]\d|2[0-3]):[0-5]\d(?:\s*,\s*(?:[01]\d|2[0-3]):[0-5]\d)*\s*$/;
/** Per-field error messages surfaced inline under time-list inputs. */
let timeListErrors = $state<Record<string, string>>({});
/** Normalize "9:0 , 18:30" → "09:00,18:30" on blur, clear error when valid. */
function normalizeTimeList(key: string) {
const raw = String(form[key] ?? '').trim();
if (!raw) { timeListErrors = { ...timeListErrors, [key]: '' }; return; }
if (!TIME_LIST_RE.test(raw)) {
// Try a lenient normalization: split on commas, zero-pad each part.
const parts = raw.split(',').map(p => p.trim()).filter(Boolean);
const fixed: string[] = [];
let ok = true;
for (const p of parts) {
const m = /^(\d{1,2}):(\d{1,2})$/.exec(p);
if (!m) { ok = false; break; }
const hh = Number(m[1]);
const mm = Number(m[2]);
if (!Number.isFinite(hh) || !Number.isFinite(mm) || hh < 0 || hh > 23 || mm < 0 || mm > 59) { ok = false; break; }
fixed.push(`${String(hh).padStart(2, '0')}:${String(mm).padStart(2, '0')}`);
}
if (ok) {
form[key] = fixed.join(',');
timeListErrors = { ...timeListErrors, [key]: '' };
return;
}
timeListErrors = { ...timeListErrors, [key]: t('trackingConfig.invalidTimeList') };
return;
}
// Canonicalise spacing.
form[key] = raw.split(',').map(s => s.trim()).join(',');
timeListErrors = { ...timeListErrors, [key]: '' };
}
/**
* Quiet-hours preview: "22:00 → 07:00 next day (9h)" or "Quiet period is 0
* minutes — adjust times" when start equals end. Handles overnight ranges
* (start > end) correctly.
*/
function quietHoursPreview(start: string, end: string): string {
if (!start || !end) return '';
const [sh, sm] = start.split(':').map(Number);
const [eh, em] = end.split(':').map(Number);
if (![sh, sm, eh, em].every(Number.isFinite)) return '';
const sMin = sh * 60 + sm;
const eMin = eh * 60 + em;
if (sMin === eMin) return t('trackingConfig.quietHoursZero');
const overnight = sMin > eMin;
const span = overnight ? (24 * 60 - sMin) + eMin : eMin - sMin;
const h = Math.floor(span / 60);
const m = span % 60;
const dur = m === 0 ? `${h}h` : `${h}h ${m}m`;
const arrow = overnight
? `${start}${end} ${t('trackingConfig.nextDay')}`
: `${start}${end}`;
return `${arrow} (${dur})`;
}
function gotoTemplateConfig(slotName: string) {
// Deep-link to the template configs page: pass the slot as a query
// param (``edit_slot``) so the destination can auto-open the first
// matching config in edit mode and expand that slot. Plain hashes
// like ``#slot-X`` were a no-op because slots don't exist in the DOM
// until a config is being edited.
const u = new URL('/template-configs', window.location.origin);
u.searchParams.set('provider', 'immich');
u.searchParams.set('edit_slot', slotName);
window.location.href = u.toString();
}
/**
* Inline preview of the shipped default template for a scheduled/periodic/
* memory slot. Using the shipped default (not a tracker's current template)
* keeps this scoped to the tracking-config page — which has no concept of
* which TemplateConfig a given tracker uses. Users who want to edit the
* actual config can click "Edit template" in the modal footer.
*
* ``previewLocale`` is modal-scoped so switching tabs only refetches for
* this preview — the user's UI locale (and other previews) are untouched.
*/
let previewModal = $state<{ slotName: string; rendered: string; error: string; locale: string } | null>(null);
let previewLoading = $state(false);
let previewLocales = $derived(supportedLocalesCache.items);
async function openTemplatePreview(slotName: string) {
await supportedLocalesCache.fetch();
const initialLocale = previewLocales.includes('en') ? 'en' : (previewLocales[0] || 'en');
await renderPreviewFor(slotName, initialLocale);
}
async function renderPreviewFor(slotName: string, locale: string) {
previewLoading = true;
try {
const defaults = await api<Record<string, Record<string, string>>>(
`/template-configs/defaults?provider_type=immich&slot_name=${encodeURIComponent(slotName)}&locale=${encodeURIComponent(locale)}`,
);
const template = defaults?.[slotName]?.[locale];
if (!template) {
previewModal = { slotName, rendered: '', error: t('templateConfig.resetNoDefault'), locale };
return;
}
const res = await api<{ rendered?: string; error?: string }>(
'/template-configs/preview-raw',
{
method: 'POST',
body: JSON.stringify({
template,
target_type: 'telegram',
date_format: '%d.%m.%Y, %H:%M UTC',
date_only_format: '%d.%m.%Y',
}),
},
);
previewModal = {
slotName,
rendered: res?.rendered || '',
error: res?.error || '',
locale,
};
} catch (err: any) {
previewModal = { slotName, rendered: '', error: err.message, locale };
} finally {
previewLoading = false;
}
}
const SLOT_FOR_SECTION: Record<string, string> = {
periodic: 'periodic_summary_message',
scheduled: 'scheduled_assets_message',
memory: 'memory_mode_message',
};
let allConfigs = $derived(trackingConfigsCache.items); let allConfigs = $derived(trackingConfigsCache.items);
let filterText = $state(''); let filterText = $state('');
let filterType = $state(''); let filterType = $state('');
@@ -161,10 +301,20 @@
{t(section.legend)} {t(section.legend)}
{#if section.legendHint}<Hint text={t(section.legendHint)} />{/if} {#if section.legendHint}<Hint text={t(section.legendHint)} />{/if}
</legend> </legend>
<label class="flex items-center gap-2 text-sm mt-1"> <div class="flex items-center justify-between mt-1">
<input type="checkbox" bind:checked={form[section.enabledField]} /> <label class="flex items-center gap-2 text-sm">
{t('trackingConfig.enabled')} <input type="checkbox" bind:checked={form[section.enabledField]} />
</label> {t('trackingConfig.enabled')}
</label>
{#if SLOT_FOR_SECTION[section.key]}
<button type="button" onclick={() => openTemplatePreview(SLOT_FOR_SECTION[section.key])}
class="text-xs text-[var(--color-primary)] hover:underline inline-flex items-center gap-1"
disabled={previewLoading}>
<MdiIcon name="mdiEyeOutline" size={14} />
{t('trackingConfig.previewTemplate')}
</button>
{/if}
</div>
{#if form[section.enabledField]} {#if form[section.enabledField]}
<div class="grid grid-cols-3 gap-3 mt-3"> <div class="grid grid-cols-3 gap-3 mt-3">
{#each section.fields as field (field.key)} {#each section.fields as field (field.key)}
@@ -181,17 +331,32 @@
{:else if field.type === 'grid-select' && field.gridItems} {:else if field.type === 'grid-select' && field.gridItems}
<IconGridSelect items={gridItemSources[field.gridItems]()} bind:value={form[field.key]} columns={field.gridColumns ?? 2} compact /> <IconGridSelect items={gridItemSources[field.gridItems]()} bind:value={form[field.key]} columns={field.gridColumns ?? 2} compact />
{:else} {:else}
<input type={field.key.includes('date') ? 'date' {@const inputType = field.type === 'date' ? 'date'
: field.key.startsWith('quiet_hours_') ? 'time' : field.type === 'time' ? 'time'
: field.key.includes('times') ? 'text' : field.type === 'time-list' ? 'text'
: 'number'} : 'number'}
{@const hasError = field.type === 'time-list' && !!timeListErrors[field.key]}
<input type={inputType}
bind:value={form[field.key]} min={field.min} max={field.max} bind:value={form[field.key]} min={field.min} max={field.max}
placeholder={field.key.includes('times') || field.key.startsWith('quiet_hours_') ? String(field.defaultValue ?? '') : ''} onblur={field.type === 'time-list' && field.validateFormat ? () => normalizeTimeList(field.key) : undefined}
class="w-full px-2 py-1 border border-[var(--color-border)] rounded-md text-sm bg-[var(--color-background)]" /> placeholder={field.type === 'time-list' || field.type === 'time' ? String(typeof field.defaultValue === 'function' ? field.defaultValue() : (field.defaultValue ?? '')) : ''}
class="w-full px-2 py-1 border rounded-md text-sm bg-[var(--color-background)] {hasError ? 'border-[var(--color-error-fg)]' : 'border-[var(--color-border)]'}" />
{#if field.inlineHelp}
<p class="text-[10px] mt-0.5" style="color: var(--color-muted-foreground);">{t(field.inlineHelp)}</p>
{/if}
{#if hasError}
<p class="text-[10px] mt-0.5" style="color: var(--color-error-fg);">{timeListErrors[field.key]}</p>
{/if}
{/if} {/if}
</div> </div>
{/each} {/each}
</div> </div>
{#if section.key === 'quietHours' && form.quiet_hours_start && form.quiet_hours_end}
<p class="text-xs mt-2" style="color: var(--color-muted-foreground);">
<MdiIcon name="mdiWeatherNight" size={12} />
{quietHoursPreview(String(form.quiet_hours_start), String(form.quiet_hours_end))}
</p>
{/if}
{/if} {/if}
</fieldset> </fieldset>
{/each} {/each}
@@ -268,7 +433,63 @@
<BlockedByModal open={!!blockedBy} detail={blockedBy} onclose={() => blockedBy = null} /> <BlockedByModal open={!!blockedBy} detail={blockedBy} onclose={() => blockedBy = null} />
<Modal open={previewModal !== null}
title={previewModal ? `${t('trackingConfig.previewTemplate')} ${previewModal.slotName}` : ''}
onclose={() => previewModal = null}>
{#if previewModal}
{#if previewLocales.length > 1}
<div class="flex gap-1 mb-3 border-b border-[var(--color-border)]">
{#each previewLocales as loc}
<button type="button"
onclick={() => renderPreviewFor(previewModal!.slotName, loc)}
disabled={previewLoading}
class="px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors {previewModal.locale === loc ? 'bg-[var(--color-primary)] text-[var(--color-primary-foreground)]' : 'text-[var(--color-muted-foreground)] hover:bg-[var(--color-muted)]'} disabled:opacity-50">
{loc.toUpperCase()}
</button>
{/each}
</div>
{/if}
<p class="text-xs mb-3" style="color: var(--color-muted-foreground);">
{t('trackingConfig.previewSampleNote')}
</p>
<!-- Keep the prior rendered/error box mounted while refetching on locale
switch — just dim it. Unmounting and replacing with a small "…"
placeholder caused a one-frame layout jump as the modal shrank and
then re-expanded. -->
<div class="relative mb-3" style="opacity: {previewLoading ? 0.5 : 1}; transition: opacity 0.15s ease;">
{#if previewModal.error}
<div class="p-3 rounded text-xs" style="background: var(--color-error-bg); color: var(--color-error-fg);">
{previewModal.error}
</div>
{:else if previewModal.rendered}
<div class="p-3 bg-[var(--color-muted)] rounded text-sm preview-html">
<pre class="whitespace-pre-wrap text-xs">{@html sanitizePreview(previewModal.rendered)}</pre>
</div>
{:else}
<div class="p-3 text-xs" style="color: var(--color-muted-foreground);"></div>
{/if}
</div>
<div class="flex gap-2 justify-end mt-3">
<button type="button" onclick={() => { const s = previewModal!.slotName; previewModal = null; gotoTemplateConfig(s); }}
class="text-xs px-3 py-1.5 rounded-md border border-[var(--color-border)] hover:bg-[var(--color-muted)]">
{t('trackingConfig.editTemplate')}
</button>
<button type="button" onclick={() => previewModal = null}
class="text-xs px-3 py-1.5 rounded-md bg-[var(--color-primary)] text-[var(--color-primary-foreground)]">
{t('common.close')}
</button>
</div>
{/if}
</Modal>
<style> <style>
:global(.preview-html a) {
color: var(--color-primary);
text-decoration: underline;
}
:global(.preview-html a:hover) {
opacity: 0.8;
}
.toggle-switch { .toggle-switch {
position: relative; position: relative;
display: inline-flex; display: inline-flex;
@@ -105,7 +105,7 @@ class NotificationDispatcher:
if self._shared_session is not None and not self._shared_session.closed: if self._shared_session is not None and not self._shared_session.closed:
yield self._shared_session yield self._shared_session
return return
async with self._session_ctx() as session: async with _new_session() as session:
yield session yield session
async def dispatch( async def dispatch(
@@ -333,8 +333,11 @@ def collect_scheduled_assets(
memory_date = now.isoformat() if is_memory else None memory_date = now.isoformat() if is_memory else None
all_eligible: list[ImmichAssetInfo] = [] all_eligible: list[ImmichAssetInfo] = []
# Track which album each asset belongs to for public URL construction # Track which album each asset belongs to. Public URL is used to construct
asset_album_map: dict[str, tuple[str, str]] = {} # asset_id → (album_id, public_url) # a per-asset share link; name/internal-url are surfaced to templates so
# combined-mode sends can attribute each row to its source album.
asset_album_map: dict[str, tuple[str, str, str, str]] = {}
# asset_id → (album_id, album_public_url, album_name, album_internal_url)
collections_extra: list[dict[str, Any]] = [] collections_extra: list[dict[str, Any]] = []
# limit=0 is the periodic-summary test path — the caller only needs # limit=0 is the periodic-summary test path — the caller only needs
@@ -346,10 +349,11 @@ def collect_scheduled_assets(
for album_id, album in albums.items(): for album_id, album in albums.items():
links = shared_links.get(album_id, []) links = shared_links.get(album_id, [])
album_public_url = get_public_url(external_url, links) or "" album_public_url = get_public_url(external_url, links) or ""
album_internal_url = f"{external_url}/albums/{album_id}"
collections_extra.append({ collections_extra.append({
"name": album.name, "name": album.name,
"url": album_public_url or f"{external_url}/albums/{album_id}", "url": album_public_url or album_internal_url,
"public_url": album_public_url, "public_url": album_public_url,
"asset_count": album.asset_count, "asset_count": album.asset_count,
"shared": album.shared, "shared": album.shared,
@@ -370,7 +374,9 @@ def collect_scheduled_assets(
) )
for asset in filtered: for asset in filtered:
if asset.id not in asset_album_map: if asset.id not in asset_album_map:
asset_album_map[asset.id] = (album_id, album_public_url) asset_album_map[asset.id] = (
album_id, album_public_url, album.name, album_internal_url,
)
all_eligible.append(asset) all_eligible.append(asset)
if stats_only: if stats_only:
@@ -383,15 +389,25 @@ def collect_scheduled_assets(
random.shuffle(all_eligible) random.shuffle(all_eligible)
selected = all_eligible selected = all_eligible
# Convert to MediaAsset with public URLs # Convert to MediaAsset with public URLs. Per-asset album_name/album_url
# let combined-mode templates attribute each row to its source album —
# critical when a tracker spans multiple albums, where the event-level
# ``album_name`` (first album only) would be misleading.
result: list[MediaAsset] = [] result: list[MediaAsset] = []
for asset in selected: for asset in selected:
media = asset_to_media(asset, external_url) media = asset_to_media(asset, external_url)
_, album_pub_url = asset_album_map.get(asset.id, ("", "")) mapped = asset_album_map.get(asset.id)
if mapped:
_, album_pub_url, album_name, album_internal_url = mapped
else:
album_pub_url = album_name = album_internal_url = ""
if album_pub_url: if album_pub_url:
media.extra["public_url"] = f"{album_pub_url}/photos/{asset.id}" media.extra["public_url"] = f"{album_pub_url}/photos/{asset.id}"
else: else:
media.extra.setdefault("public_url", "") media.extra.setdefault("public_url", "")
media.extra["album_name"] = album_name
media.extra["album_url"] = album_pub_url or album_internal_url
media.extra["album_public_url"] = album_pub_url
result.append(media) result.append(media)
return result, collections_extra return result, collections_extra
@@ -1,5 +1,5 @@
⭐ Favorites: ⭐ Favorites:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %} ❤️ • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} ❤️
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,6 +1,6 @@
📸 Latest: 📸 Latest:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %} {%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,5 +1,6 @@
📅 On this day: 📅 On this day:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,6 +1,6 @@
🎲 Random: 🎲 Random:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %} {%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -4,7 +4,7 @@
{%- else %}🔍 Results for "{{ query }}": {%- else %}🔍 Results for "{{ query }}":
{%- endif %} {%- endif %}
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %} {%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,6 @@
📋 Album summary ({{ albums | length }}): 📋 Album summary ({{ albums | length }}):
{%- for album in albums %} {%- for album in albums %}
• {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} assets • {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} assets
{%- if album.photo_count is defined or album.video_count is defined %} ({% if album.photo_count %}🖼️ {{ album.photo_count }}{% endif %}{% if album.photo_count and album.video_count %} · {% endif %}{% if album.video_count %}🎬 {{ album.video_count }}{% endif %}){% endif %}
{%- if album.shared %} 🔗{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,5 +1,5 @@
⭐ Избранное: ⭐ Избранное:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %} ❤️ • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} ❤️
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,6 +1,6 @@
📸 Последние: 📸 Последние:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %} {%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,5 +1,6 @@
📅 В этот день: 📅 В этот день:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,6 +1,6 @@
🎲 Случайные: 🎲 Случайные:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %} {%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -4,7 +4,7 @@
{%- else %}🔍 Результаты по "{{ query }}": {%- else %}🔍 Результаты по "{{ query }}":
{%- endif %} {%- endif %}
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" or asset.type == "video" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.originalFileName }}</a>{% else %}{{ asset.originalFileName }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}{% if asset.year %} ({{ asset.year }}){% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %} {%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %} {%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,6 @@
📋 Сводка альбомов ({{ albums | length }}): 📋 Сводка альбомов ({{ albums | length }}):
{%- for album in albums %} {%- for album in albums %}
• {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} файлов • {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} файлов
{%- if album.photo_count is defined or album.video_count is defined %} ({% if album.photo_count %}🖼️ {{ album.photo_count }}{% endif %}{% if album.photo_count and album.video_count %} · {% endif %}{% if album.video_count %}🎬 {{ album.video_count }}{% endif %}){% endif %}
{%- if album.shared %} 🔗{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,7 @@
📅 On this day: 📅 On this day:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} ({{ asset.created_at[:4] }}) • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} ({{ asset.created_at[:4] }})
{%- if albums and albums|length > 1 and asset.album_name %} — {% if asset.album_url %}<a href="{{ asset.album_url }}">{{ asset.album_name }}</a>{% else %}{{ asset.album_name }}{% endif %}{% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,6 @@
📋 Tracked Albums Summary ({{ albums | length }} albums): 📋 Tracked Albums Summary ({{ albums | length }} albums):
{%- for album in albums %} {%- for album in albums %}
• {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} assets • {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} assets
{%- if album.photo_count is defined or album.video_count is defined %} ({% if album.photo_count %}🖼️ {{ album.photo_count }}{% endif %}{% if album.photo_count and album.video_count %} · {% endif %}{% if album.video_count %}🎬 {{ album.video_count }}{% endif %}){% endif %}
{%- if album.shared %} 🔗{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,11 @@
{%- if albums and albums|length > 1 -%}
🗓️ Scheduled delivery — random photos from {% for album in albums %}{% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}:
{%- else -%}
🗓️ Scheduled delivery — random photos from {% if public_url %}<a href="{{ public_url }}">{{ album_name }}</a>{% else %}"{{ album_name }}"{% endif %}: 🗓️ Scheduled delivery — random photos from {% if public_url %}<a href="{{ public_url }}">{{ album_name }}</a>{% else %}"{{ album_name }}"{% endif %}:
{%- endif %}
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}
{%- if albums and albums|length > 1 and asset.album_name %} — {% if asset.album_url %}<a href="{{ asset.album_url }}">{{ asset.album_name }}</a>{% else %}{{ asset.album_name }}{% endif %}{% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,7 @@
📅 В этот день: 📅 В этот день:
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} ({{ asset.created_at[:4] }}) • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} ({{ asset.created_at[:4] }})
{%- if albums and albums|length > 1 and asset.album_name %} — {% if asset.album_url %}<a href="{{ asset.album_url }}">{{ asset.album_name }}</a>{% else %}{{ asset.album_name }}{% endif %}{% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,6 @@
📋 Сводка альбомов ({{ albums | length }}): 📋 Сводка альбомов ({{ albums | length }}):
{%- for album in albums %} {%- for album in albums %}
• {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} файлов • {% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}: {{ album.asset_count }} файлов
{%- if album.photo_count is defined or album.video_count is defined %} ({% if album.photo_count %}🖼️ {{ album.photo_count }}{% endif %}{% if album.photo_count and album.video_count %} · {% endif %}{% if album.video_count %}🎬 {{ album.video_count }}{% endif %}){% endif %}
{%- if album.shared %} 🔗{% endif %}
{%- endfor %} {%- endfor %}
@@ -1,4 +1,11 @@
{%- if albums and albums|length > 1 -%}
🗓️ Доставка по расписанию — случайные фото из {% for album in albums %}{% if album.public_url %}<a href="{{ album.public_url }}">{{ album.name }}</a>{% else %}{{ album.name }}{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}:
{%- else -%}
🗓️ Доставка по расписанию — случайные фото из {% if public_url %}<a href="{{ public_url }}">{{ album_name }}</a>{% else %}"{{ album_name }}"{% endif %}: 🗓️ Доставка по расписанию — случайные фото из {% if public_url %}<a href="{{ public_url }}">{{ album_name }}</a>{% else %}"{{ album_name }}"{% endif %}:
{%- endif %}
{%- for asset in assets %} {%- for asset in assets %}
• {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %} • {%- if asset.type == "VIDEO" %} 🎬{% else %} 🖼️{% endif %} {% if asset.public_url %}<a href="{{ asset.public_url }}">{{ asset.filename }}</a>{% else %}{{ asset.filename }}{% endif %}
{%- if albums and albums|length > 1 and asset.album_name %} — {% if asset.album_url %}<a href="{{ asset.album_url }}">{{ asset.album_name }}</a>{% else %}{{ asset.album_name }}{% endif %}{% endif %}
{%- if asset.city %} 📍 {{ asset.city }}{% if asset.country %}, {{ asset.country }}{% endif %}{% endif %}
{%- if asset.is_favorite %} ❤️{% endif %}
{%- endfor %} {%- endfor %}
@@ -74,6 +74,36 @@ async def _get(session: AsyncSession, config_id: int, user_id: int) -> CommandTe
# Routes # Routes
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@router.get("/defaults")
async def get_default_command_templates(
provider_type: str,
slot_name: str | None = None,
locale: str | None = None,
user: User = Depends(get_current_user),
):
"""Return the shipped Jinja2 default command templates for a provider type.
Used by the UI's "Reset to default" actions. Filtering works the same way
as the notification-template equivalent: omit ``slot_name`` for the whole
set, omit ``locale`` for every locale.
Response shape: ``{slot_name: {locale: template_text}}``
"""
from notify_bridge_core.templates.command_defaults.loader import (
load_default_command_templates,
)
from notify_bridge_core.templates.defaults.loader import get_available_locales
locales = [locale] if locale else get_available_locales()
result: dict[str, dict[str, str]] = {}
for loc in locales:
defaults = load_default_command_templates(loc, provider_type)
for name, text in defaults.items():
if slot_name and name != slot_name:
continue
result.setdefault(name, {})[loc] = text
return result
@router.get("/variables") @router.get("/variables")
async def get_command_variables( async def get_command_variables(
user: User = Depends(get_current_user), user: User = Depends(get_current_user),
@@ -84,15 +114,26 @@ async def get_command_variables(
} }
asset_fields = { asset_fields = {
"id": "Asset ID (UUID)", "id": "Asset ID (UUID)",
"originalFileName": "Original filename", "filename": "Original filename (preferred; same as originalFileName)",
"originalFileName": "Original filename (alias of filename, kept for backward-compat with older templates)",
"type": "IMAGE or VIDEO", "type": "IMAGE or VIDEO",
"createdAt": "Creation date/time (ISO 8601)", "created_at": "Creation date/time (ISO 8601)",
"createdAt": "Creation date/time (alias of created_at)",
"year": "Year of the memory (memory command only)", "year": "Year of the memory (memory command only)",
"public_url": "Per-asset public share URL (empty if no album link)",
"city": "City name (empty if unknown)",
"country": "Country name (empty if unknown)",
"is_favorite": "Whether asset is favorited (boolean)",
} }
album_fields = { album_fields = {
"name": "Album name", "name": "Album name",
"asset_count": "Number of assets in the album",
"id": "Album ID (UUID)", "id": "Album ID (UUID)",
"public_url": "Public share link URL (empty if none)",
"asset_count": "Number of assets in the album",
"photo_count": "Number of photos in the album",
"video_count": "Number of videos in the album",
"shared": "Whether the album is shared (boolean)",
"owner": "Album owner display name",
} }
command_fields = { command_fields = {
"name": "Command name (e.g. status, albums)", "name": "Command name (e.g. status, albums)",
@@ -492,10 +533,11 @@ async def preview_raw(
{"name": "latest", "description": "Show latest photos", "usage": "/latest 10"}, {"name": "latest", "description": "Show latest photos", "usage": "/latest 10"},
{"name": "search", "description": "Smart search (AI)", "usage": "/search sunset at the beach"}, {"name": "search", "description": "Smart search (AI)", "usage": "/search sunset at the beach"},
], ],
# /albums, /summary # /albums, /summary — provide photo/video split, sharing, owner so the
# enriched summary template previews fully.
"albums": [ "albums": [
{"name": "Family Photos", "asset_count": 142, "id": "abc-123", "public_url": "https://immich.example.com/share/abc123"}, {"name": "Family Photos", "asset_count": 142, "photo_count": 120, "video_count": 22, "shared": True, "owner": "Alice", "id": "abc-123", "public_url": "https://immich.example.com/share/abc123"},
{"name": "Vacation 2025", "asset_count": 87, "id": "def-456", "public_url": ""}, {"name": "Vacation 2025", "asset_count": 87, "photo_count": 80, "video_count": 7, "shared": False, "owner": "Bob", "id": "def-456", "public_url": ""},
], ],
# /events # /events
"events": [ "events": [
@@ -505,9 +547,12 @@ async def preview_raw(
# /people # /people
"people": ["Alice", "Bob", "Charlie"], "people": ["Alice", "Bob", "Charlie"],
# /search, /find, /person, /place, /latest, /favorites, /random, /memory # /search, /find, /person, /place, /latest, /favorites, /random, /memory
# ``filename`` is the canonical key (matches notification context and
# build_asset_dict output); ``originalFileName`` is kept as an alias
# so templates still using the old key render in preview.
"assets": [ "assets": [
{"id": "a1", "originalFileName": "IMG_001.jpg", "type": "IMAGE", "createdAt": "2026-03-19T14:30:00", "year": 2024, "public_url": "https://immich.example.com/share/abc123/photos/a1", "city": "Paris", "country": "France", "is_favorite": True}, {"id": "a1", "filename": "IMG_001.jpg", "originalFileName": "IMG_001.jpg", "type": "IMAGE", "created_at": "2026-03-19T14:30:00", "createdAt": "2026-03-19T14:30:00", "year": 2024, "public_url": "https://immich.example.com/share/abc123/photos/a1", "city": "Paris", "country": "France", "is_favorite": True},
{"id": "a2", "originalFileName": "VID_002.mp4", "type": "VIDEO", "createdAt": "2026-03-19T15:00:00", "year": 2023, "public_url": "", "city": "", "country": "", "is_favorite": False}, {"id": "a2", "filename": "VID_002.mp4", "originalFileName": "VID_002.mp4", "type": "VIDEO", "created_at": "2026-03-19T15:00:00", "createdAt": "2026-03-19T15:00:00", "year": 2023, "public_url": "", "city": "", "country": "", "is_favorite": False},
], ],
"query": "sunset", "query": "sunset",
"command": "search", "command": "search",
@@ -426,19 +426,45 @@ async def get_album_shared_links(
return [] return []
class CreateSharedLinkRequest(BaseModel):
"""Options for POST /shared-links.
``replace=True`` deletes every existing link for the album before creating
the new one, which is the only way to repair an expired or password-
protected link in the Immich API (there is no in-place "reset" endpoint).
Default ``False`` preserves the original additive behaviour used by the
"auto-create missing links" flow.
"""
replace: bool = False
@router.post("/{provider_id}/albums/{album_id}/shared-links") @router.post("/{provider_id}/albums/{album_id}/shared-links")
async def create_album_shared_link( async def create_album_shared_link(
provider_id: int, provider_id: int,
album_id: str, album_id: str,
body: CreateSharedLinkRequest | None = None,
user: User = Depends(get_current_user), user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
): ):
"""Auto-create a public shared link for an album.""" """Auto-create a public shared link for an album.
With ``replace=True`` existing links for the album are deleted first, so
expired/password-protected links are effectively recycled into a fresh
public one.
"""
provider = await _get_user_provider(session, provider_id, user.id) provider = await _get_user_provider(session, provider_id, user.id)
if provider.type == "immich": if provider.type == "immich":
http_session = await get_http_session() http_session = await get_http_session()
immich = make_immich_provider(http_session, provider) immich = make_immich_provider(http_session, provider)
if body and body.replace:
# Best-effort delete; if any delete fails we still try to create —
# the user will see the new link co-exist alongside the old one,
# which is better than a hard failure that leaves them stuck.
existing = await immich.client.get_shared_links(album_id)
for link in existing:
await immich.client.delete_shared_link(link.id)
success = await immich.client.create_shared_link(album_id) success = await immich.client.create_shared_link(album_id)
if success: if success:
return {"success": True} return {"success": True}
@@ -298,10 +298,30 @@ async def test_chat(
user: User = Depends(get_current_user), user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
): ):
"""Send a test message to a chat via the bot.""" """Send a test message to a chat via the bot.
Locale resolution: prefer the chat row's ``language_override`` (explicit
user choice in the UI), fall back to Telegram's ``language_code`` sent
with the chat, and only use the ``?locale=`` query param if neither is
set. Otherwise users who set RU on a chat would still see an EN test.
"""
bot = await _get_user_bot(session, bot_id, user.id) bot = await _get_user_bot(session, bot_id, user.id)
chat_row = (await session.exec(
select(TelegramChat).where(
TelegramChat.bot_id == bot_id,
TelegramChat.chat_id == chat_id,
)
)).first()
effective_locale = locale
if chat_row:
chat_locale = (
getattr(chat_row, 'language_override', '') or
getattr(chat_row, 'language_code', '') or ''
)
if chat_locale:
effective_locale = chat_locale[:2].lower()
from ..services.http_session import get_http_session from ..services.http_session import get_http_session
message = _get_test_message(locale, "telegram") message = _get_test_message(effective_locale, "telegram")
http = await get_http_session() http = await get_http_session()
client = TelegramClient(http, bot.token) client = TelegramClient(http, bot.token)
return await client.send_message(chat_id, message) return await client.send_message(chat_id, message)
@@ -102,6 +102,37 @@ async def list_configs(
return [await _response(session, c) for c in result.all()] return [await _response(session, c) for c in result.all()]
@router.get("/defaults")
async def get_default_slot_templates(
provider_type: str,
slot_name: str | None = None,
locale: str | None = None,
user: User = Depends(get_current_user),
):
"""Return the shipped Jinja2 default templates for a provider type.
Used by the UI's "Reset to default" actions. Filtering is optional —
omit ``slot_name`` to get every slot, omit ``locale`` to get every locale.
Registered before ``/{config_id}`` so the literal path wins over the
path-parameter route in FastAPI's matcher.
Response shape: ``{slot_name: {locale: template_text}}``
"""
from notify_bridge_core.templates.defaults.loader import (
get_available_locales,
load_default_templates,
)
locales = [locale] if locale else get_available_locales()
result: dict[str, dict[str, str]] = {}
for loc in locales:
defaults = load_default_templates(loc, provider_type)
for name, text in defaults.items():
if slot_name and name != slot_name:
continue
result.setdefault(name, {})[loc] = text
return result
@router.get("/variables") @router.get("/variables")
async def get_template_variables( async def get_template_variables(
user: User = Depends(get_current_user), user: User = Depends(get_current_user),
@@ -170,13 +201,20 @@ async def get_template_variables(
"download_url": "Direct download URL (if shared)", "download_url": "Direct download URL (if shared)",
"photo_url": "Preview image URL (images only, if shared)", "photo_url": "Preview image URL (images only, if shared)",
"playback_url": "Video playback URL (videos only, if shared)", "playback_url": "Video playback URL (videos only, if shared)",
# Per-asset album attribution (scheduled/memory templates in combined mode).
"album_name": "Source album name (combined-mode scheduled/memory only)",
"album_url": "Source album URL — public share link if available, else internal album URL",
"album_public_url": "Source album public share URL (empty if no public link)",
} }
album_fields = { album_fields = {
"name": "Collection/album name", "name": "Collection/album name",
"url": "Share URL", "url": "Share URL",
"public_url": "Public share link URL", "public_url": "Public share link URL",
"asset_count": "Total assets in collection", "asset_count": "Total assets in collection",
"shared": "Whether collection is shared", "photo_count": "Number of photos in the album",
"video_count": "Number of videos in the album",
"shared": "Whether collection is shared (boolean)",
"owner": "Album owner display name",
} }
scheduled_vars = { scheduled_vars = {
"date": "Current date string", "date": "Current date string",
@@ -217,12 +255,26 @@ async def get_template_variables(
}, },
"scheduled_assets_message": { "scheduled_assets_message": {
"description": "Scheduled asset delivery (daily photo picks)", "description": "Scheduled asset delivery (daily photo picks)",
"variables": {**scheduled_vars, "assets": "List of asset dicts (use {% for asset in assets %})"}, "variables": {
**scheduled_vars,
"assets": "List of asset dicts (use {% for asset in assets %})",
"album_name": "Source album name",
"public_url": "Public share link URL for the source album (empty if none)",
"asset_count": "Total assets in the source album",
"photo_count": "Photos in the source album",
"video_count": "Videos in the source album",
"owner": "Source album owner",
},
"asset_fields": asset_fields, "asset_fields": asset_fields,
}, },
"memory_mode_message": { "memory_mode_message": {
"description": "\"On This Day\" memories from previous years", "description": "\"On This Day\" memories from previous years",
"variables": {**scheduled_vars, "assets": "List of asset dicts (use {% for asset in assets %})"}, "variables": {
**scheduled_vars,
"assets": "List of asset dicts (use {% for asset in assets %})",
"album_name": "Source album name (when rendered per-album)",
"public_url": "Public share link URL for the source album (empty if none)",
},
"asset_fields": asset_fields, "asset_fields": asset_fields,
}, },
# --- Generic Webhook slots --- # --- Generic Webhook slots ---
@@ -76,16 +76,28 @@ def build_asset_dict(
public_url: str = "", public_url: str = "",
year: int | None = None, year: int | None = None,
) -> dict[str, Any]: ) -> dict[str, Any]:
"""Build a rich asset dict for command templates from an ImmichAssetInfo or raw dict.""" """Build a rich asset dict for command templates from an ImmichAssetInfo or raw dict.
Asset-dict contract (shared with notification templates see
``notify_bridge_core.templates.context``): templates may read either
``filename`` (the canonical field, used by notification defaults) or
``originalFileName`` (the historical command-default field); both are
populated so a custom template authored against either key keeps working.
Same story for ``created_at`` / ``createdAt``.
"""
if isinstance(asset, dict): if isinstance(asset, dict):
# Immich raw search responses nest geo under exifInfo — pull it out so # Immich raw search responses nest geo under exifInfo — pull it out so
# templates can use flat asset.city / asset.country. # templates can use flat asset.city / asset.country.
exif = asset.get("exifInfo") or {} exif = asset.get("exifInfo") or {}
fname = asset.get("originalFileName") or asset.get("filename") or ""
created = asset.get("createdAt") or asset.get("created_at") or asset.get("fileCreatedAt") or ""
d = { d = {
"id": asset.get("id", ""), "id": asset.get("id", ""),
"originalFileName": asset.get("originalFileName", asset.get("filename", "")), "filename": fname,
"originalFileName": fname,
"type": asset.get("type", "IMAGE"), "type": asset.get("type", "IMAGE"),
"createdAt": asset.get("createdAt", asset.get("created_at", asset.get("fileCreatedAt", ""))), "created_at": created,
"createdAt": created,
"city": asset.get("city") or exif.get("city") or "", "city": asset.get("city") or exif.get("city") or "",
"country": asset.get("country") or exif.get("country") or "", "country": asset.get("country") or exif.get("country") or "",
"is_favorite": asset.get("is_favorite", asset.get("isFavorite", False)), "is_favorite": asset.get("is_favorite", asset.get("isFavorite", False)),
@@ -97,8 +109,10 @@ def build_asset_dict(
# ImmichAssetInfo dataclass # ImmichAssetInfo dataclass
return { return {
"id": asset.id, "id": asset.id,
"filename": asset.filename,
"originalFileName": asset.filename, "originalFileName": asset.filename,
"type": asset.type, "type": asset.type,
"created_at": asset.created_at,
"createdAt": asset.created_at, "createdAt": asset.created_at,
"city": getattr(asset, "city", "") or "", "city": getattr(asset, "city", "") or "",
"country": getattr(asset, "country", "") or "", "country": getattr(asset, "country", "") or "",
@@ -120,22 +120,43 @@ async def dispatch_test_notification(
), ),
} }
# Fetch assets and build event # Build events (single or per-album) via the shared helper so test and
# cron dispatch stay in lockstep on the mode decision.
try: try:
event = await _build_event( if provider.type == "immich" and test_type in ("periodic", "scheduled", "memory"):
provider_type=provider.type, events = await build_immich_dispatch_events(
provider_config=provider_config, provider_config=provider_config,
provider_name=provider.name or provider.type, provider_name=provider.name or provider.type,
tracker_name=tracker.name or "", tracker_name=tracker.name or "",
tracker_filters=dict(tracker.filters) if tracker.filters else {}, collection_ids=collection_ids,
collection_ids=collection_ids, kind=test_type,
test_type=test_type, tracking_config=tracking_config,
tracking_config=tracking_config, )
) else:
ev = await _build_event(
provider_type=provider.type,
provider_config=provider_config,
provider_name=provider.name or provider.type,
tracker_name=tracker.name or "",
tracker_filters=dict(tracker.filters) if tracker.filters else {},
collection_ids=collection_ids,
test_type=test_type,
tracking_config=tracking_config,
)
events = [ev] if ev is not None else []
except Exception as err: # noqa: BLE001 except Exception as err: # noqa: BLE001
_LOGGER.exception("Test dispatch event build failed") _LOGGER.exception("Test dispatch event build failed")
return {"success": False, "error": f"Provider connection failed: {err}"} return {"success": False, "error": f"Provider connection failed: {err}"}
if event is None:
if not events:
if test_type in ("scheduled", "memory"):
return {
"success": False,
"error": (
"No matching assets found. Verify the tracker's albums contain assets "
"that pass the tracking config filters (favorites only, rating, asset type)."
) + (" for today" if test_type == "memory" else ""),
}
return { return {
"success": False, "success": False,
"error": ( "error": (
@@ -143,24 +164,92 @@ async def dispatch_test_notification(
"credentials are valid, and the tracker has collections configured." "credentials are valid, and the tracker has collections configured."
), ),
} }
# Periodic summary only needs album stats (extra.albums), not assets — skip the asset check.
if not event.added_assets and test_type in ("scheduled", "memory"):
return {
"success": False,
"error": (
"No matching assets found. Verify the tracker's albums contain assets "
"that pass the tracking config filters (favorites only, rating, asset type)."
) + (" for today" if test_type == "memory" else ""),
}
# Dispatch through the real NotificationDispatcher # Dispatch each event to the same target (per-album fan-out sends N messages).
url_cache, asset_cache = await _get_telegram_caches() url_cache, asset_cache = await _get_telegram_caches()
dispatcher = NotificationDispatcher(url_cache=url_cache, asset_cache=asset_cache) dispatcher = NotificationDispatcher(url_cache=url_cache, asset_cache=asset_cache)
results = await dispatcher.dispatch(event, [target_cfg]) all_results: list[dict[str, Any]] = []
for event in events:
results = await dispatcher.dispatch(event, [target_cfg])
if results:
all_results.append(results[0])
if not results: if not all_results:
return {"success": False, "error": "No dispatch results"} return {"success": False, "error": "No dispatch results"}
return results[0] all_ok = all(r.get("success") for r in all_results)
if all_ok:
return {"success": True, "dispatched": len(all_results)}
first_err = next(
(r.get("error") for r in all_results if not r.get("success")),
"Unknown error",
)
return {
"success": False,
"error": first_err,
"dispatched": sum(1 for r in all_results if r.get("success")),
"failed": sum(1 for r in all_results if not r.get("success")),
}
async def build_immich_dispatch_events(
*,
provider_config: dict,
provider_name: str,
tracker_name: str,
collection_ids: list[str],
kind: str,
tracking_config: TrackingConfig | None,
) -> list[ServiceEvent]:
"""Build the list of ServiceEvents to dispatch for an Immich scheduled kind.
Single source of truth for the mode decision: ``periodic`` is always one
summary event; ``scheduled``/``memory`` honour the ``{kind}_collection_mode``
on the tracking config and fan out one event per album in ``per_collection``
mode, or one combined event in ``combined`` mode.
Empty-payload filtering (no assets matched) is applied here so callers get
back only events that should actually dispatch. ``periodic`` is exempt
a zero-asset summary is still meaningful (shows album stats only).
"""
if kind == "periodic":
ev = await _build_immich_periodic_event(
provider_config=provider_config,
provider_name=provider_name,
tracker_name=tracker_name,
collection_ids=collection_ids,
)
return [ev] if ev is not None else []
mode = getattr(
tracking_config, f"{kind}_collection_mode", "combined"
) or "combined"
if mode == "per_collection" and len(collection_ids) > 1:
events: list[ServiceEvent] = []
for aid in collection_ids:
ev = await _build_immich_event(
provider_config=provider_config,
provider_name=provider_name,
tracker_name=tracker_name,
collection_ids=[aid],
test_type=kind,
tracking_config=tracking_config,
)
if ev is not None and ev.added_assets:
events.append(ev)
return events
ev = await _build_immich_event(
provider_config=provider_config,
provider_name=provider_name,
tracker_name=tracker_name,
collection_ids=collection_ids,
test_type=kind,
tracking_config=tracking_config,
)
if ev is None or not ev.added_assets:
return []
return [ev]
async def _build_event( async def _build_event(
@@ -8,12 +8,18 @@ IMPORTANT: Keep sample assets and context in sync with:
When adding new template variables, update all four locations. When adding new template variables, update all four locations.
""" """
# Sample asset matching what build_asset_detail() actually returns # Sample asset matching what build_asset_detail() / build_asset_dict() actually
# return. Command-template defaults use ``asset.filename`` (the canonical key
# shared with notification templates); ``originalFileName`` and ``createdAt``
# are kept as aliases so user templates authored against the historical command
# keys still preview correctly.
_SAMPLE_ASSET = { _SAMPLE_ASSET = {
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"filename": "IMG_001.jpg", "filename": "IMG_001.jpg",
"originalFileName": "IMG_001.jpg",
"type": "IMAGE", "type": "IMAGE",
"created_at": "2026-03-19T10:30:00", "created_at": "2026-03-19T10:30:00",
"createdAt": "2026-03-19T10:30:00",
"owner": "Alice", "owner": "Alice",
"owner_id": "user-uuid-1", "owner_id": "user-uuid-1",
"description": "Family picnic", "description": "Family picnic",
@@ -32,12 +38,18 @@ _SAMPLE_ASSET = {
"file_size": 3_500_000, # 3.5 MB — original asset bytes "file_size": 3_500_000, # 3.5 MB — original asset bytes
"playback_size": None, # photos are sent as-is, no transcoded variant "playback_size": None, # photos are sent as-is, no transcoded variant
"oversized": False, "oversized": False,
# Per-asset album attribution — populated by collect_scheduled_assets so
# combined-mode templates can label each row with its source album.
"album_name": "Family Photos",
"album_url": "https://immich.example.com/share/abc123",
"album_public_url": "https://immich.example.com/share/abc123",
} }
_SAMPLE_VIDEO_ASSET = { _SAMPLE_VIDEO_ASSET = {
**_SAMPLE_ASSET, **_SAMPLE_ASSET,
"id": "d4e5f6a7-b8c9-0123-defg-456789abcdef", "id": "d4e5f6a7-b8c9-0123-defg-456789abcdef",
"filename": "VID_002.mp4", "filename": "VID_002.mp4",
"originalFileName": "VID_002.mp4",
"type": "VIDEO", "type": "VIDEO",
"is_favorite": False, "is_favorite": False,
"rating": None, "rating": None,
@@ -54,7 +66,10 @@ _SAMPLE_COLLECTION = {
"url": "https://immich.example.com/share/abc123", "url": "https://immich.example.com/share/abc123",
"public_url": "https://immich.example.com/share/abc123", "public_url": "https://immich.example.com/share/abc123",
"asset_count": 42, "asset_count": 42,
"photo_count": 37,
"video_count": 5,
"shared": True, "shared": True,
"owner": "Alice",
} }
# Full context covering ALL possible template variables # Full context covering ALL possible template variables
@@ -103,7 +118,9 @@ _SAMPLE_CONTEXT = {
# Scheduled/periodic variables (for those templates) # Scheduled/periodic variables (for those templates)
"collections": [_SAMPLE_COLLECTION, {**_SAMPLE_COLLECTION, "name": "Vacation 2025", "asset_count": 120}], "collections": [_SAMPLE_COLLECTION, {**_SAMPLE_COLLECTION, "name": "Vacation 2025", "asset_count": 120}],
"albums": [_SAMPLE_COLLECTION, {**_SAMPLE_COLLECTION, "name": "Vacation 2025", "asset_count": 120}], "albums": [_SAMPLE_COLLECTION, {**_SAMPLE_COLLECTION, "name": "Vacation 2025", "asset_count": 120}],
"assets": [_SAMPLE_ASSET, {**_SAMPLE_ASSET, "id": "x1y2z3", "filename": "IMG_002.jpg", "city": "London", "country": "UK", "public_url": "https://immich.example.com/share/abc123/photos/x1y2z3"}], # Second sample asset belongs to a different album so the preview exercises
# the combined-mode branch (>1 distinct album → per-row "— Album" suffix).
"assets": [_SAMPLE_ASSET, {**_SAMPLE_ASSET, "id": "x1y2z3", "filename": "IMG_002.jpg", "originalFileName": "IMG_002.jpg", "city": "London", "country": "UK", "public_url": "https://immich.example.com/share/def456/photos/x1y2z3", "album_name": "Vacation 2025", "album_url": "https://immich.example.com/share/def456", "album_public_url": "https://immich.example.com/share/def456"}],
"date": "2026-03-19", "date": "2026-03-19",
"photo_count": 30, "photo_count": 30,
"video_count": 5, "video_count": 5,
@@ -46,12 +46,62 @@ from .dispatch_helpers import (
get_app_timezone, get_app_timezone,
load_link_data, load_link_data,
) )
from .manual_dispatch import _build_immich_event, _build_immich_periodic_event from .manual_dispatch import build_immich_dispatch_events
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ScheduledKind = Literal["scheduled", "periodic", "memory"] ScheduledKind = Literal["scheduled", "periodic", "memory"]
# Reasons a scheduled cron fire can end up producing no notification. We write
# these to EventLog.details.skip_reason so users can see *why* a 09:00 memory
# didn't arrive, rather than silently treating the fire as if it never happened.
_SKIP_REASON_TRACKER_DISABLED = "tracker_disabled"
_SKIP_REASON_NOT_IMMICH = "not_immich_provider"
_SKIP_REASON_KIND_DISABLED = "kind_disabled_on_default_config"
_SKIP_REASON_NO_LINKS = "no_enabled_links"
_SKIP_REASON_NO_EVENT = "provider_returned_no_event"
_SKIP_REASON_EMPTY_PAYLOAD = "zero_assets_matched"
_SKIP_REASON_NO_TARGETS = "no_targets_after_filtering"
async def _log_skip(
tracker_id: int,
kind: ScheduledKind,
reason: str,
*,
tracker_user_id: int | None = None,
tracker_name: str = "",
provider_id: int | None = None,
provider_name: str = "",
) -> None:
"""Persist an EventLog row for a skipped scheduled fire.
Separate from the success-path log (which records targets dispatched) so
operators and users can filter "why didn't this fire" from "what was sent".
``event_type`` mirrors the success path's value; the skip is disambiguated
by ``details.status == "skipped"``.
"""
engine = get_engine()
async with AsyncSession(engine) as session:
session.add(EventLog(
user_id=tracker_user_id,
tracker_id=tracker_id,
tracker_name=tracker_name,
provider_id=provider_id,
provider_name=provider_name,
event_type=EventType.SCHEDULED_MESSAGE.value,
collection_id="",
collection_name="",
assets_count=0,
details={
"kind": kind,
"trigger": "cron",
"status": "skipped",
"skip_reason": reason,
},
))
await session.commit()
# Maps the dispatch kind to the DB slot name that holds its template. # Maps the dispatch kind to the DB slot name that holds its template.
# The dispatcher keys templates by ``event.event_type.value`` (always # The dispatcher keys templates by ``event.event_type.value`` (always
# ``scheduled_message`` here), so we read the right ``TemplateSlot`` row and # ``scheduled_message`` here), so we read the right ``TemplateSlot`` row and
@@ -76,9 +126,23 @@ async def dispatch_scheduled_for_tracker(
async with AsyncSession(engine) as session: async with AsyncSession(engine) as session:
tracker = await session.get(NotificationTracker, tracker_id) tracker = await session.get(NotificationTracker, tracker_id)
if not tracker or not tracker.enabled: if not tracker or not tracker.enabled:
# No user context available (tracker missing/disabled); still log so
# operators can correlate cron fires that went nowhere.
await _log_skip(
tracker_id, kind, _SKIP_REASON_TRACKER_DISABLED,
tracker_user_id=(tracker.user_id if tracker else None),
tracker_name=(tracker.name if tracker else ""),
)
return return
provider = await session.get(ServiceProvider, tracker.provider_id) provider = await session.get(ServiceProvider, tracker.provider_id)
if not provider or provider.type != "immich": if not provider or provider.type != "immich":
await _log_skip(
tracker_id, kind, _SKIP_REASON_NOT_IMMICH,
tracker_user_id=tracker.user_id,
tracker_name=tracker.name or "",
provider_id=(provider.id if provider else None),
provider_name=(provider.name if provider else ""),
)
return return
default_tc: TrackingConfig | None = None default_tc: TrackingConfig | None = None
@@ -94,6 +158,13 @@ async def dispatch_scheduled_for_tracker(
"Scheduled %s skipped for tracker %d: kind disabled on default config", "Scheduled %s skipped for tracker %d: kind disabled on default config",
kind, tracker_id, kind, tracker_id,
) )
await _log_skip(
tracker_id, kind, _SKIP_REASON_KIND_DISABLED,
tracker_user_id=tracker.user_id,
tracker_name=tracker.name or "",
provider_id=provider.id,
provider_name=provider.name or provider.type,
)
return return
# Snapshot every field we need outside the session — after the # Snapshot every field we need outside the session — after the
@@ -115,90 +186,54 @@ async def dispatch_scheduled_for_tracker(
"Scheduled %s for tracker %d: no enabled links, skipping", "Scheduled %s for tracker %d: no enabled links, skipping",
kind, tracker_id, kind, tracker_id,
) )
return await _log_skip(
tracker_id, kind, _SKIP_REASON_NO_LINKS,
if kind == "periodic": tracker_user_id=tracker_user_id,
event = await _build_immich_periodic_event(
provider_config=provider_config,
provider_name=provider_name,
tracker_name=tracker_name, tracker_name=tracker_name,
collection_ids=collection_ids, provider_id=provider_id,
)
else:
event = await _build_immich_event(
provider_config=provider_config,
provider_name=provider_name, provider_name=provider_name,
tracker_name=tracker_name,
collection_ids=collection_ids,
test_type=kind,
tracking_config=default_tc,
)
if event is None:
_LOGGER.warning(
"Scheduled %s for tracker %d: provider returned no event",
kind, tracker_id,
) )
return return
# Skip empty payloads for asset-bearing kinds — sending the bare # Resolve mode + build events via the shared helper (same decision logic
# "On this day:" / "Scheduled delivery —" header with no items below # the test-dispatch path uses). "per_collection" fans out one event per
# spams chats with title-only messages every day. ``periodic`` is # album; "combined" pools assets into a single event. ``collection_mode``
# different: it's a stats summary that's still meaningful with zero # is threaded through to EventLog.details so operators can see *which*
# assets, so we let it through. # mode a fire used when auditing behaviour.
if kind in ("scheduled", "memory") and not event.added_assets: collection_mode = (
"combined" if kind == "periodic"
else getattr(default_tc, f"{kind}_collection_mode", "combined") or "combined"
)
events = await build_immich_dispatch_events(
provider_config=provider_config,
provider_name=provider_name,
tracker_name=tracker_name,
collection_ids=collection_ids,
kind=kind,
tracking_config=default_tc,
)
if not events:
# All albums yielded 0 matching assets (per_collection), or the single
# combined build produced nothing. Log the same skip reason used for
# the legacy single-event path so operators see a consistent signal.
reason = (
_SKIP_REASON_NO_EVENT if kind == "periodic" else _SKIP_REASON_EMPTY_PAYLOAD
)
_LOGGER.info( _LOGGER.info(
"Scheduled %s for tracker %d: 0 assets matched, skipping dispatch", "Scheduled %s for tracker %d: no events to dispatch (mode=%s)",
kind, tracker_id, kind, tracker_id, collection_mode,
)
await _log_skip(
tracker_id, kind, reason,
tracker_user_id=tracker_user_id,
tracker_name=tracker_name,
provider_id=provider_id,
provider_name=provider_name,
) )
return return
slot_name = _SLOT_MAP[kind] slot_name = _SLOT_MAP[kind]
target_configs: list[TargetConfig] = []
async with AsyncSession(engine) as session:
for ld in link_data:
tc = ld["tracking_config"] or default_tc
tmpl = ld["template_config"]
if tc is not None:
# Per-link override may disable this kind even when the
# default has it on — honour that here.
if not getattr(tc, f"{kind}_enabled", True):
continue
if not event_allowed_by_config(event, tc, app_tz):
continue
if tmpl is None:
continue
slot_rows = (await session.exec(
select(TemplateSlot).where(
TemplateSlot.config_id == tmpl.id,
TemplateSlot.slot_name == slot_name,
)
)).all()
if not slot_rows:
continue
locale_map = {s.locale: s.template for s in slot_rows}
template_slots = {EventType.SCHEDULED_MESSAGE.value: locale_map}
target_configs.append(TargetConfig(
type=ld["target_type"],
config=ld["target_config"],
template_slots=template_slots,
date_format=tmpl.date_format,
date_only_format=(
tmpl.date_only_format or "%d.%m.%Y"
),
provider_api_key=provider_config.get("api_key"),
provider_internal_url=provider_config.get("url", ""),
provider_external_url=provider_config.get("external_domain", ""),
receivers=ld["receivers"],
))
if not target_configs:
_LOGGER.info(
"Scheduled %s for tracker %d: no targets after filtering",
kind, tracker_id,
)
return
# Lazy import to break the watcher↔scheduler↔scheduled_dispatch cycle. # Lazy import to break the watcher↔scheduler↔scheduled_dispatch cycle.
from .watcher import _get_telegram_caches from .watcher import _get_telegram_caches
@@ -209,34 +244,96 @@ async def dispatch_scheduled_for_tracker(
dispatcher = NotificationDispatcher( dispatcher = NotificationDispatcher(
url_cache=url_cache, asset_cache=asset_cache, session=http_session, url_cache=url_cache, asset_cache=asset_cache, session=http_session,
) )
_LOGGER.info(
"Dispatching scheduled %s for tracker %d to %d link(s)",
kind, tracker_id, len(target_configs),
)
results = await dispatcher.dispatch(event, target_configs)
# Mirror the watcher's audit trail: surface scheduled fires in EventLog so any_sent = False
# the dashboard shows *why* a notification arrived (otherwise these would for event in events:
# be invisible to the activity feed). # Target config assembly depends on the event for quiet-hours /
successes = sum(1 for r in results if isinstance(r, dict) and r.get("success")) # event_allowed_by_config, which inspects event timestamp. Per-event
async with AsyncSession(engine) as session: # rebuilding also lets a per-link override disable one kind while
session.add(EventLog( # keeping others live.
user_id=tracker_user_id, target_configs: list[TargetConfig] = []
tracker_id=tracker_id, async with AsyncSession(engine) as session:
for ld in link_data:
tc = ld["tracking_config"] or default_tc
tmpl = ld["template_config"]
if tc is not None:
if not getattr(tc, f"{kind}_enabled", True):
continue
if not event_allowed_by_config(event, tc, app_tz):
continue
if tmpl is None:
continue
slot_rows = (await session.exec(
select(TemplateSlot).where(
TemplateSlot.config_id == tmpl.id,
TemplateSlot.slot_name == slot_name,
)
)).all()
if not slot_rows:
continue
locale_map = {s.locale: s.template for s in slot_rows}
template_slots = {EventType.SCHEDULED_MESSAGE.value: locale_map}
target_configs.append(TargetConfig(
type=ld["target_type"],
config=ld["target_config"],
template_slots=template_slots,
date_format=tmpl.date_format,
date_only_format=(
tmpl.date_only_format or "%d.%m.%Y"
),
provider_api_key=provider_config.get("api_key"),
provider_internal_url=provider_config.get("url", ""),
provider_external_url=provider_config.get("external_domain", ""),
receivers=ld["receivers"],
))
if not target_configs:
_LOGGER.info(
"Scheduled %s for tracker %d (collection=%r): no targets after filtering",
kind, tracker_id, event.collection_name,
)
continue
_LOGGER.info(
"Dispatching scheduled %s for tracker %d (collection=%r) to %d link(s)",
kind, tracker_id, event.collection_name, len(target_configs),
)
results = await dispatcher.dispatch(event, target_configs)
any_sent = True
successes = sum(1 for r in results if isinstance(r, dict) and r.get("success"))
async with AsyncSession(engine) as session:
session.add(EventLog(
user_id=tracker_user_id,
tracker_id=tracker_id,
tracker_name=tracker_name,
provider_id=provider_id,
provider_name=provider_name,
event_type=event.event_type.value,
collection_id=event.collection_id,
collection_name=event.collection_name,
assets_count=event.added_count or 0,
details={
"kind": kind,
"slot": slot_name,
"trigger": "cron",
"timezone": app_tz,
"collection_mode": collection_mode,
"status": "sent",
"targets_dispatched": len(target_configs),
"targets_succeeded": successes,
},
))
await session.commit()
if not any_sent:
# All events produced zero targets after filtering (quiet hours, etc.).
await _log_skip(
tracker_id, kind, _SKIP_REASON_NO_TARGETS,
tracker_user_id=tracker_user_id,
tracker_name=tracker_name, tracker_name=tracker_name,
provider_id=provider_id, provider_id=provider_id,
provider_name=provider_name, provider_name=provider_name,
event_type=event.event_type.value, )
collection_id=event.collection_id,
collection_name=event.collection_name,
assets_count=event.added_count or 0,
details={
"kind": kind,
"slot": slot_name,
"trigger": "cron",
"timezone": app_tz,
"targets_dispatched": len(target_configs),
"targets_succeeded": successes,
},
))
await session.commit()