From 9fdd76645ce9c9da62966a25cd2a479693040e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Tue, 11 Aug 2026 12:52:01 +0200 Subject: [PATCH] feat: batched auto-rules emails, thumbnail fallback, and approve form --- .../redaktionen/[id]/auto-regeln/page.tsx | 130 +++++++++++++----- src/app/globals.css | 1 + src/modules/albums/auto-rules.ts | 10 +- src/modules/auth/public-forms.tsx | 26 ++-- src/modules/editorials/ApproveForm.tsx | 40 ++++++ src/modules/editorials/admin-detail.tsx | 11 +- src/modules/email/service.ts | 28 +++- src/modules/immich/client.ts | 11 +- 8 files changed, 196 insertions(+), 61 deletions(-) create mode 100644 src/modules/editorials/ApproveForm.tsx diff --git a/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx b/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx index b6dc9f8..764c64e 100644 --- a/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx +++ b/src/app/admin/redaktionen/[id]/auto-regeln/page.tsx @@ -1,11 +1,19 @@ import Link from "next/link"; +import { Plus, Play, Trash2, ArrowLeft } from "lucide-react"; import { notFound } from "next/navigation"; import { headers } from "next/headers"; + import { requireAdmin } from "@/modules/auth/principal"; import { autoRuleService } from "@/modules/albums/auto-rules"; import { db } from "@/db/client"; import { editorialAccounts } from "@/db/schema"; import { eq } from "drizzle-orm"; + +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; +import { PageHeader } from "@/components/ui/page-header"; + import { applyAutoRulesAction, createAutoRuleAction, deleteAutoRuleAction } from "./actions"; type AutoRulesPageProps = Readonly<{ @@ -28,45 +36,95 @@ export default async function AutoRulesPage({ params }: AutoRulesPageProps) { const rules = await autoRuleService.listRules(id); return ( -
-

Redaktion · Auto-Zuweisungsregeln

-

Auto-Regeln für {editorial.name}

-

- Alben, deren Name eines der folgenden Schlüsselwörter enthält, werden automatisch zugewiesen. -

-

- Zurück zu Albumrechte -

+
+ -
- - -
+
+ + + Zurück zur Album-Verwaltung + +
-
- -
+
+ + + Neue Regel hinzufügen + + Alben, deren Name eines der folgenden Schlüsselwörter enthält, werden dieser Redaktion automatisch zugewiesen, sobald sie von Immich synchronisiert werden. + + + +
+
+ + +
+ +
+
+
- {rules.length === 0 ? ( -

Noch keine Auto-Regeln angelegt.

- ) : ( -
    - {rules.map((rule) => ( -
  • - {rule.keyword} - - {new Date(rule.createdAt).toLocaleDateString('de-DE')} - -
    - + + +
    +
    + Bestehende Regeln + + Alle derzeit aktiven automatischen Zuweisungen. + +
    + + -
  • - ))} -
- )} -
+ + + + {rules.length === 0 ? ( +

Noch keine Auto-Regeln angelegt.

+ ) : ( + + )} +
+ + + ); } diff --git a/src/app/globals.css b/src/app/globals.css index 42708bd..d66ffb6 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -150,6 +150,7 @@ a { } .primary-action { + display: inline-block; width: fit-content; margin-top: 2.25rem; padding: 0.9rem 1.25rem; diff --git a/src/modules/albums/auto-rules.ts b/src/modules/albums/auto-rules.ts index 8ba3dbc..a125c1d 100644 --- a/src/modules/albums/auto-rules.ts +++ b/src/modules/albums/auto-rules.ts @@ -62,6 +62,7 @@ export function createAutoRuleService({ const grantedAlbumIds = new Set(await grantService.getGrantedAlbumIds(editorialId)); let newlyGranted = 0; + const newlyGrantedAlbumNames: string[] = []; let editorialEmail: string | undefined; try { @@ -88,16 +89,17 @@ export function createAutoRuleService({ await grantService.grantAlbum({ editorialId, immichAlbumId: album.id, adminUserId }); newlyGranted++; grantedAlbumIds.add(album.id); - - if (editorialEmail) { - await emailService.sendNewAlbumNotification(editorialEmail, album.albumName).catch(() => {}); - } + newlyGrantedAlbumNames.push(album.albumName); } catch (error) { // Ignore individual album grant failures } } } + if (newlyGrantedAlbumNames.length > 0 && editorialEmail) { + await emailService.sendNewAlbumNotification(editorialEmail, newlyGrantedAlbumNames).catch(() => {}); + } + return { granted: newlyGranted }; }, }; diff --git a/src/modules/auth/public-forms.tsx b/src/modules/auth/public-forms.tsx index 6750634..b8d588b 100644 --- a/src/modules/auth/public-forms.tsx +++ b/src/modules/auth/public-forms.tsx @@ -106,25 +106,29 @@ export function RegistrationForm({ Verbindliche Angaben diff --git a/src/modules/editorials/ApproveForm.tsx b/src/modules/editorials/ApproveForm.tsx new file mode 100644 index 0000000..f87a92c --- /dev/null +++ b/src/modules/editorials/ApproveForm.tsx @@ -0,0 +1,40 @@ +"use client"; + +import { useActionState } from "react"; +import { approveEditorialAction, type ApproveActionResult } from "@/app/admin/redaktionen/[id]/actions"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Check } from "lucide-react"; + +export function ApproveForm({ editorialId }: { editorialId: string }) { + const [state, formAction, pending] = useActionState( + approveEditorialAction.bind(null, editorialId), + { ok: true, message: "" } + ); + + return ( +
+
+ + +
+ + {!state.ok &&

{state.message}

} +
+ ); +} diff --git a/src/modules/editorials/admin-detail.tsx b/src/modules/editorials/admin-detail.tsx index 197a95c..822db1c 100644 --- a/src/modules/editorials/admin-detail.tsx +++ b/src/modules/editorials/admin-detail.tsx @@ -4,6 +4,7 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { archiveEditorialAction, suspendEditorialAction, reactivateEditorialAction, updateFlatrateAction } from "@/app/admin/redaktionen/[id]/actions"; import { DangerZone } from "./DangerZone"; +import { ApproveForm } from "./ApproveForm"; export type EditorialDetail = { id: string; @@ -80,9 +81,13 @@ export function EditorialDetailContent({ - + {editorial.status === "pending_approval" && hasActiveGrant ? ( + + ) : editorial.status === "pending_approval" && !hasActiveGrant ? ( + + ) : null}
Albumrechte verwalten diff --git a/src/modules/email/service.ts b/src/modules/email/service.ts index 5d4625f..1a4c078 100644 --- a/src/modules/email/service.ts +++ b/src/modules/email/service.ts @@ -71,13 +71,33 @@ export const emailService = { }); }, - async sendNewAlbumNotification(toEmail: string, albumName: string) { + async sendNewAlbumNotification(toEmail: string, albumNames: string | string[]) { + const albums = Array.isArray(albumNames) ? albumNames : [albumNames]; + + if (albums.length === 0) return; + + const isMultiple = albums.length > 1; + const subject = isMultiple + ? `Neue Fotoalben verfügbar (${albums.length})` + : `Neues Fotoalbum verfügbar: ${albums[0]}`; + + const textList = albums.map(a => `- ${a}`).join("\n"); + const htmlList = albums.map(a => `
  • ${a}
  • `).join(""); + + const textBody = isMultiple + ? `Hallo,\n\nes wurden ${albums.length} neue Fotoalben für Ihre Redaktion freigegeben:\n\n${textList}\n\nSie können die Bilder ab sofort im Redaktionsportal ansehen und lizenzieren.\n\nViele Grüße,\nIhr Redaktions-Team` + : `Hallo,\n\nein neues Fotoalbum "${albums[0]}" wurde für Ihre Redaktion freigegeben. Sie können die Bilder ab sofort im Redaktionsportal ansehen und lizenzieren.\n\nViele Grüße,\nIhr Redaktions-Team`; + + const htmlBody = isMultiple + ? `Hallo,\n\nes wurden soeben **${albums.length} neue Fotoalben** für Ihre Redaktion freigegeben:\n\n
      ${htmlList}
    \n\nSie können die Bilder ab sofort im Redaktionsportal ansehen und herunterladen.\n\nViele Grüße,\nIhr Redaktions-Team` + : `Hallo,\n\nein neues Fotoalbum **"${albums[0]}"** wurde soeben für Ihre Redaktion freigegeben.\n\nSie können die Bilder ab sofort im Redaktionsportal ansehen und herunterladen.\n\nViele Grüße,\nIhr Redaktions-Team`; + await transporter.sendMail({ from: env.SMTP_FROM, to: toEmail, - subject: `Neues Fotoalbum verfügbar: ${albumName}`, - text: `Hallo,\n\nein neues Fotoalbum "${albumName}" wurde für Ihre Redaktion freigegeben. Sie können die Bilder ab sofort im Redaktionsportal ansehen und lizenzieren.\n\nViele Grüße,\nIhr Redaktions-Team`, - html: buildHtml("Neues Album verfügbar", `Hallo,\n\nein neues Fotoalbum **"${albumName}"** wurde soeben für Ihre Redaktion freigegeben.\n\nSie können die Bilder ab sofort im Redaktionsportal ansehen und herunterladen.\n\nViele Grüße,\nIhr Redaktions-Team`, { text: "Zum Portal", url: `${env.BETTER_AUTH_URL}/login` }), + subject, + text: textBody, + html: buildHtml(isMultiple ? "Neue Alben verfügbar" : "Neues Album verfügbar", htmlBody, { text: "Zum Portal", url: `${env.BETTER_AUTH_URL}/login` }), }); }, }; diff --git a/src/modules/immich/client.ts b/src/modules/immich/client.ts index a56017a..a6d28d4 100644 --- a/src/modules/immich/client.ts +++ b/src/modules/immich/client.ts @@ -380,9 +380,14 @@ export function createImmichClient({ signal, ); }, - getThumbnail(assetId, signal) { - // Request 'preview' size to get a larger image, so we can resize it cleanly to 480px - return requestBinary(`/assets/${encodeURIComponent(assetId)}/thumbnail?size=preview`, signal); + async getThumbnail(assetId, signal) { + try { + // Try to get 'preview' size first for better watermark quality + return await requestBinary(`/assets/${encodeURIComponent(assetId)}/thumbnail?size=preview`, signal); + } catch (err) { + // Fallback to standard thumbnail if preview doesn't exist + return await requestBinary(`/assets/${encodeURIComponent(assetId)}/thumbnail`, signal); + } }, getOriginal(assetId, signal) { return requestBinary(`/assets/${encodeURIComponent(assetId)}/original`, signal);