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
@@ -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" />
|
||||
Ich akzeptiere die{" "}
|
||||
<a href={legalUrls.terms} rel="noreferrer" target="_blank">
|
||||
Nutzungs- und Lizenzbedingungen
|
||||
</a>
|
||||
.
|
||||
<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" />
|
||||
Ich habe die{" "}
|
||||
<a href={legalUrls.privacy} rel="noreferrer" target="_blank">
|
||||
Datenschutzerklärung
|
||||
</a>{" "}
|
||||
zur Kenntnis genommen.
|
||||
<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">
|
||||
<Button disabled variant="outline">
|
||||
Redaktion freigeben
|
||||
</Button>
|
||||
{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