feat: batched auto-rules emails, thumbnail fallback, and approve form
This commit is contained in:
1 parent
4667615ed0
commit
9fdd76645c
8 files changed
+171
-36
No files matched your search
@@ -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 (
|
||||
<section className="content-section" aria-labelledby="auto-rules-title">
|
||||
<p className="eyebrow">Redaktion · Auto-Zuweisungsregeln</p>
|
||||
<h1 id="auto-rules-title">Auto-Regeln für {editorial.name}</h1>
|
||||
<p>
|
||||
Alben, deren Name eines der folgenden Schlüsselwörter enthält, werden automatisch zugewiesen.
|
||||
</p>
|
||||
<p>
|
||||
<Link href={`/admin/redaktionen/${editorial.id}/alben`}>Zurück zu Albumrechte</Link>
|
||||
</p>
|
||||
<div className="space-y-8 max-w-4xl animate-in fade-in slide-in-from-bottom-4 duration-500">
|
||||
<PageHeader
|
||||
kicker="Redaktion · Auto-Zuweisungsregeln"
|
||||
title={`Auto-Regeln für ${editorial.name}`}
|
||||
/>
|
||||
|
||||
<form action={createAutoRuleAction.bind(null, editorial.id)}>
|
||||
<label>
|
||||
<span>Neues Schlüsselwort</span>
|
||||
<input name="keyword" type="text" required placeholder="z.B. FC Bayern" />
|
||||
<div className="flex gap-4 mb-6">
|
||||
<Link
|
||||
href={`/admin/redaktionen/${editorial.id}/alben`}
|
||||
className="inline-flex items-center text-sm font-medium text-primary-600 hover:underline"
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4 mr-1" />
|
||||
Zurück zur Album-Verwaltung
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Neue Regel hinzufügen</CardTitle>
|
||||
<CardDescription>
|
||||
Alben, deren Name eines der folgenden Schlüsselwörter enthält, werden dieser Redaktion automatisch zugewiesen, sobald sie von Immich synchronisiert werden.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form action={createAutoRuleAction.bind(null, editorial.id)} className="flex gap-4 items-end">
|
||||
<div className="grid gap-2 flex-grow">
|
||||
<label className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
|
||||
Schlüsselwort
|
||||
</label>
|
||||
<button type="submit">Regel hinzufügen</button>
|
||||
<Input
|
||||
name="keyword"
|
||||
type="text"
|
||||
required
|
||||
placeholder="z.B. FC Bayern"
|
||||
className="max-w-md"
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit">
|
||||
<Plus className="w-4 h-4 mr-2" />
|
||||
Regel hinzufügen
|
||||
</Button>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex items-start justify-between">
|
||||
<div>
|
||||
<CardTitle>Bestehende Regeln</CardTitle>
|
||||
<CardDescription>
|
||||
Alle derzeit aktiven automatischen Zuweisungen.
|
||||
</CardDescription>
|
||||
</div>
|
||||
<form action={applyAutoRulesAction.bind(null, editorial.id)}>
|
||||
<button type="submit">Regeln jetzt anwenden</button>
|
||||
<Button type="submit" variant="secondary">
|
||||
<Play className="w-4 h-4 mr-2" />
|
||||
Regeln jetzt anwenden
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{rules.length === 0 ? (
|
||||
<p>Noch keine Auto-Regeln angelegt.</p>
|
||||
<p className="text-muted-foreground text-sm">Noch keine Auto-Regeln angelegt.</p>
|
||||
) : (
|
||||
<ul className="auto-rules-list">
|
||||
<ul className="divide-y divide-border border rounded-md">
|
||||
{rules.map((rule) => (
|
||||
<li key={rule.id} className="auto-rule-item">
|
||||
<span className="auto-rule-keyword">{rule.keyword}</span>
|
||||
<span className="auto-rule-date">
|
||||
{new Date(rule.createdAt).toLocaleDateString('de-DE')}
|
||||
<li key={rule.id} className="flex items-center justify-between p-4">
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium">{rule.keyword}</span>
|
||||
<span className="text-xs text-muted-foreground mt-1">
|
||||
Erstellt am {new Date(rule.createdAt).toLocaleDateString('de-DE')}
|
||||
</span>
|
||||
</div>
|
||||
<form action={deleteAutoRuleAction.bind(null, editorial.id, rule.id)}>
|
||||
<button type="submit" className="auto-rule-delete">Entfernen</button>
|
||||
<Button type="submit" variant="ghost" size="sm" className="text-destructive hover:bg-destructive/10 hover:text-destructive">
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
Entfernen
|
||||
</Button>
|
||||
</form>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -150,6 +150,7 @@ a {
|
||||
}
|
||||
|
||||
.primary-action {
|
||||
display: inline-block;
|
||||
width: fit-content;
|
||||
margin-top: 2.25rem;
|
||||
padding: 0.9rem 1.25rem;
|
||||
|
||||
@@ -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 };
|
||||
},
|
||||
};
|
||||
|
||||
@@ -106,25 +106,29 @@ export function RegistrationForm({
|
||||
<legend>Verbindliche Angaben</legend>
|
||||
<label className="checkbox-label">
|
||||
<input name="actsForBusiness" required type="checkbox" />
|
||||
Ich handle im Namen einer Redaktion oder eines Unternehmens.
|
||||
<span>Ich handle im Namen einer Redaktion oder eines Unternehmens.</span>
|
||||
</label>
|
||||
<FieldError message={state.errors?.actsForBusiness} />
|
||||
<label className="checkbox-label">
|
||||
<input name="termsAccepted" required type="checkbox" />
|
||||
<span>
|
||||
Ich akzeptiere die{" "}
|
||||
<a href={legalUrls.terms} rel="noreferrer" target="_blank">
|
||||
Nutzungs- und Lizenzbedingungen
|
||||
</a>
|
||||
.
|
||||
</span>
|
||||
</label>
|
||||
<FieldError message={state.errors?.termsVersion} />
|
||||
<label className="checkbox-label">
|
||||
<input name="privacyAcknowledged" required type="checkbox" />
|
||||
<span>
|
||||
Ich habe die{" "}
|
||||
<a href={legalUrls.privacy} rel="noreferrer" target="_blank">
|
||||
Datenschutzerklärung
|
||||
</a>{" "}
|
||||
zur Kenntnis genommen.
|
||||
</span>
|
||||
</label>
|
||||
<FieldError message={state.errors?.privacyAcknowledged} />
|
||||
</fieldset>
|
||||
|
||||
@@ -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<ApproveActionResult, FormData>(
|
||||
approveEditorialAction.bind(null, editorialId),
|
||||
{ ok: true, message: "" }
|
||||
);
|
||||
|
||||
return (
|
||||
<form action={formAction} className="flex flex-col sm:flex-row gap-4 items-start sm:items-center">
|
||||
<div className="flex gap-2 items-center">
|
||||
<label htmlFor="priceEuros" className="text-sm font-medium whitespace-nowrap">
|
||||
Individueller Nettopreis (€)
|
||||
</label>
|
||||
<Input
|
||||
id="priceEuros"
|
||||
name="priceEuros"
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0.01"
|
||||
required
|
||||
placeholder="z.B. 15.00"
|
||||
className="w-32 bg-background"
|
||||
disabled={pending}
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" disabled={pending}>
|
||||
<Check className="w-4 h-4 mr-2" />
|
||||
{pending ? "Wird freigegeben..." : "Redaktion freigeben"}
|
||||
</Button>
|
||||
{!state.ok && <p className="text-sm text-destructive font-medium">{state.message}</p>}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -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({
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-col sm:flex-row gap-4 items-start sm:items-center">
|
||||
{editorial.status === "pending_approval" && hasActiveGrant ? (
|
||||
<ApproveForm editorialId={editorial.id} />
|
||||
) : editorial.status === "pending_approval" && !hasActiveGrant ? (
|
||||
<Button disabled variant="outline">
|
||||
Redaktion freigeben
|
||||
</Button>
|
||||
) : null}
|
||||
<div className="flex gap-4 text-sm font-medium">
|
||||
<Link href={`/admin/redaktionen/${editorial.id}/alben`} className="text-primary-600 hover:underline">
|
||||
Albumrechte verwalten
|
||||
|
||||
@@ -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 => `<li><strong>${a}</strong></li>`).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<ul>${htmlList}</ul>\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` }),
|
||||
});
|
||||
},
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user