feat: batched auto-rules emails, thumbnail fallback, and approve form
This commit is contained in:
1 parent
4667615ed0
commit
9fdd76645c
8 files changed
+196
-61
No files matched your search
@@ -1,11 +1,19 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { Plus, Play, Trash2, ArrowLeft } from "lucide-react";
|
||||||
import { notFound } from "next/navigation";
|
import { notFound } from "next/navigation";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
import { requireAdmin } from "@/modules/auth/principal";
|
import { requireAdmin } from "@/modules/auth/principal";
|
||||||
import { autoRuleService } from "@/modules/albums/auto-rules";
|
import { autoRuleService } from "@/modules/albums/auto-rules";
|
||||||
import { db } from "@/db/client";
|
import { db } from "@/db/client";
|
||||||
import { editorialAccounts } from "@/db/schema";
|
import { editorialAccounts } from "@/db/schema";
|
||||||
import { eq } from "drizzle-orm";
|
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";
|
import { applyAutoRulesAction, createAutoRuleAction, deleteAutoRuleAction } from "./actions";
|
||||||
|
|
||||||
type AutoRulesPageProps = Readonly<{
|
type AutoRulesPageProps = Readonly<{
|
||||||
@@ -28,45 +36,95 @@ export default async function AutoRulesPage({ params }: AutoRulesPageProps) {
|
|||||||
const rules = await autoRuleService.listRules(id);
|
const rules = await autoRuleService.listRules(id);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="content-section" aria-labelledby="auto-rules-title">
|
<div className="space-y-8 max-w-4xl animate-in fade-in slide-in-from-bottom-4 duration-500">
|
||||||
<p className="eyebrow">Redaktion · Auto-Zuweisungsregeln</p>
|
<PageHeader
|
||||||
<h1 id="auto-rules-title">Auto-Regeln für {editorial.name}</h1>
|
kicker="Redaktion · Auto-Zuweisungsregeln"
|
||||||
<p>
|
title={`Auto-Regeln für ${editorial.name}`}
|
||||||
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>
|
|
||||||
|
|
||||||
<form action={createAutoRuleAction.bind(null, editorial.id)}>
|
<div className="flex gap-4 mb-6">
|
||||||
<label>
|
<Link
|
||||||
<span>Neues Schlüsselwort</span>
|
href={`/admin/redaktionen/${editorial.id}/alben`}
|
||||||
<input name="keyword" type="text" required placeholder="z.B. FC Bayern" />
|
className="inline-flex items-center text-sm font-medium text-primary-600 hover:underline"
|
||||||
</label>
|
>
|
||||||
<button type="submit">Regel hinzufügen</button>
|
<ArrowLeft className="w-4 h-4 mr-1" />
|
||||||
</form>
|
Zurück zur Album-Verwaltung
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form action={applyAutoRulesAction.bind(null, editorial.id)}>
|
<div className="grid gap-6">
|
||||||
<button type="submit">Regeln jetzt anwenden</button>
|
<Card>
|
||||||
</form>
|
<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>
|
||||||
|
<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>
|
||||||
|
|
||||||
{rules.length === 0 ? (
|
<Card>
|
||||||
<p>Noch keine Auto-Regeln angelegt.</p>
|
<CardHeader>
|
||||||
) : (
|
<div className="flex items-start justify-between">
|
||||||
<ul className="auto-rules-list">
|
<div>
|
||||||
{rules.map((rule) => (
|
<CardTitle>Bestehende Regeln</CardTitle>
|
||||||
<li key={rule.id} className="auto-rule-item">
|
<CardDescription>
|
||||||
<span className="auto-rule-keyword">{rule.keyword}</span>
|
Alle derzeit aktiven automatischen Zuweisungen.
|
||||||
<span className="auto-rule-date">
|
</CardDescription>
|
||||||
{new Date(rule.createdAt).toLocaleDateString('de-DE')}
|
</div>
|
||||||
</span>
|
<form action={applyAutoRulesAction.bind(null, editorial.id)}>
|
||||||
<form action={deleteAutoRuleAction.bind(null, editorial.id, rule.id)}>
|
<Button type="submit" variant="secondary">
|
||||||
<button type="submit" className="auto-rule-delete">Entfernen</button>
|
<Play className="w-4 h-4 mr-2" />
|
||||||
|
Regeln jetzt anwenden
|
||||||
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</div>
|
||||||
))}
|
</CardHeader>
|
||||||
</ul>
|
<CardContent>
|
||||||
)}
|
{rules.length === 0 ? (
|
||||||
</section>
|
<p className="text-muted-foreground text-sm">Noch keine Auto-Regeln angelegt.</p>
|
||||||
|
) : (
|
||||||
|
<ul className="divide-y divide-border border rounded-md">
|
||||||
|
{rules.map((rule) => (
|
||||||
|
<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" 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>
|
||||||
|
)}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -150,6 +150,7 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.primary-action {
|
.primary-action {
|
||||||
|
display: inline-block;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
margin-top: 2.25rem;
|
margin-top: 2.25rem;
|
||||||
padding: 0.9rem 1.25rem;
|
padding: 0.9rem 1.25rem;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ export function createAutoRuleService({
|
|||||||
|
|
||||||
const grantedAlbumIds = new Set(await grantService.getGrantedAlbumIds(editorialId));
|
const grantedAlbumIds = new Set(await grantService.getGrantedAlbumIds(editorialId));
|
||||||
let newlyGranted = 0;
|
let newlyGranted = 0;
|
||||||
|
const newlyGrantedAlbumNames: string[] = [];
|
||||||
|
|
||||||
let editorialEmail: string | undefined;
|
let editorialEmail: string | undefined;
|
||||||
try {
|
try {
|
||||||
@@ -88,16 +89,17 @@ export function createAutoRuleService({
|
|||||||
await grantService.grantAlbum({ editorialId, immichAlbumId: album.id, adminUserId });
|
await grantService.grantAlbum({ editorialId, immichAlbumId: album.id, adminUserId });
|
||||||
newlyGranted++;
|
newlyGranted++;
|
||||||
grantedAlbumIds.add(album.id);
|
grantedAlbumIds.add(album.id);
|
||||||
|
newlyGrantedAlbumNames.push(album.albumName);
|
||||||
if (editorialEmail) {
|
|
||||||
await emailService.sendNewAlbumNotification(editorialEmail, album.albumName).catch(() => {});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore individual album grant failures
|
// Ignore individual album grant failures
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newlyGrantedAlbumNames.length > 0 && editorialEmail) {
|
||||||
|
await emailService.sendNewAlbumNotification(editorialEmail, newlyGrantedAlbumNames).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
return { granted: newlyGranted };
|
return { granted: newlyGranted };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -106,25 +106,29 @@ export function RegistrationForm({
|
|||||||
<legend>Verbindliche Angaben</legend>
|
<legend>Verbindliche Angaben</legend>
|
||||||
<label className="checkbox-label">
|
<label className="checkbox-label">
|
||||||
<input name="actsForBusiness" required type="checkbox" />
|
<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>
|
</label>
|
||||||
<FieldError message={state.errors?.actsForBusiness} />
|
<FieldError message={state.errors?.actsForBusiness} />
|
||||||
<label className="checkbox-label">
|
<label className="checkbox-label">
|
||||||
<input name="termsAccepted" required type="checkbox" />
|
<input name="termsAccepted" required type="checkbox" />
|
||||||
Ich akzeptiere die{" "}
|
<span>
|
||||||
<a href={legalUrls.terms} rel="noreferrer" target="_blank">
|
Ich akzeptiere die{" "}
|
||||||
Nutzungs- und Lizenzbedingungen
|
<a href={legalUrls.terms} rel="noreferrer" target="_blank">
|
||||||
</a>
|
Nutzungs- und Lizenzbedingungen
|
||||||
.
|
</a>
|
||||||
|
.
|
||||||
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<FieldError message={state.errors?.termsVersion} />
|
<FieldError message={state.errors?.termsVersion} />
|
||||||
<label className="checkbox-label">
|
<label className="checkbox-label">
|
||||||
<input name="privacyAcknowledged" required type="checkbox" />
|
<input name="privacyAcknowledged" required type="checkbox" />
|
||||||
Ich habe die{" "}
|
<span>
|
||||||
<a href={legalUrls.privacy} rel="noreferrer" target="_blank">
|
Ich habe die{" "}
|
||||||
Datenschutzerklärung
|
<a href={legalUrls.privacy} rel="noreferrer" target="_blank">
|
||||||
</a>{" "}
|
Datenschutzerklärung
|
||||||
zur Kenntnis genommen.
|
</a>{" "}
|
||||||
|
zur Kenntnis genommen.
|
||||||
|
</span>
|
||||||
</label>
|
</label>
|
||||||
<FieldError message={state.errors?.privacyAcknowledged} />
|
<FieldError message={state.errors?.privacyAcknowledged} />
|
||||||
</fieldset>
|
</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 { Input } from "@/components/ui/input";
|
||||||
import { archiveEditorialAction, suspendEditorialAction, reactivateEditorialAction, updateFlatrateAction } from "@/app/admin/redaktionen/[id]/actions";
|
import { archiveEditorialAction, suspendEditorialAction, reactivateEditorialAction, updateFlatrateAction } from "@/app/admin/redaktionen/[id]/actions";
|
||||||
import { DangerZone } from "./DangerZone";
|
import { DangerZone } from "./DangerZone";
|
||||||
|
import { ApproveForm } from "./ApproveForm";
|
||||||
|
|
||||||
export type EditorialDetail = {
|
export type EditorialDetail = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -80,9 +81,13 @@ export function EditorialDetailContent({
|
|||||||
</CardDescription>
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="flex flex-col sm:flex-row gap-4 items-start sm:items-center">
|
<CardContent className="flex flex-col sm:flex-row gap-4 items-start sm:items-center">
|
||||||
<Button disabled variant="outline">
|
{editorial.status === "pending_approval" && hasActiveGrant ? (
|
||||||
Redaktion freigeben
|
<ApproveForm editorialId={editorial.id} />
|
||||||
</Button>
|
) : editorial.status === "pending_approval" && !hasActiveGrant ? (
|
||||||
|
<Button disabled variant="outline">
|
||||||
|
Redaktion freigeben
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
<div className="flex gap-4 text-sm font-medium">
|
<div className="flex gap-4 text-sm font-medium">
|
||||||
<Link href={`/admin/redaktionen/${editorial.id}/alben`} className="text-primary-600 hover:underline">
|
<Link href={`/admin/redaktionen/${editorial.id}/alben`} className="text-primary-600 hover:underline">
|
||||||
Albumrechte verwalten
|
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({
|
await transporter.sendMail({
|
||||||
from: env.SMTP_FROM,
|
from: env.SMTP_FROM,
|
||||||
to: toEmail,
|
to: toEmail,
|
||||||
subject: `Neues Fotoalbum verfügbar: ${albumName}`,
|
subject,
|
||||||
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`,
|
text: textBody,
|
||||||
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` }),
|
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,
|
signal,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
getThumbnail(assetId, signal) {
|
async getThumbnail(assetId, signal) {
|
||||||
// Request 'preview' size to get a larger image, so we can resize it cleanly to 480px
|
try {
|
||||||
return requestBinary(`/assets/${encodeURIComponent(assetId)}/thumbnail?size=preview`, signal);
|
// 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) {
|
getOriginal(assetId, signal) {
|
||||||
return requestBinary(`/assets/${encodeURIComponent(assetId)}/original`, signal);
|
return requestBinary(`/assets/${encodeURIComponent(assetId)}/original`, signal);
|
||||||
|
|||||||
Reference in new issue
Block a user