feat: implement hard delete, email notifications, watermark, and fix bulk download

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 12:28:39 +02:00
1 parent 8dd1e10fea
commit 4667615ed0
15 files changed
+369 -65

No files matched your search

@@ -5,6 +5,8 @@ import { albumGrantService } from "@/modules/albums/grants";
import { immichClient } from "@/modules/immich/client";
import type { ImmichBinary } from "@/modules/immich/types";
import sharp from "sharp";
import fs from "node:fs/promises";
import path from "node:path";
type ThumbnailRouteContext = Readonly<{ params: Promise<{ assetId: string }> }>;
@@ -128,27 +130,48 @@ async function watermarkedThumbnailResponse(thumbnail: ImmichBinary, assetId: st
}
const buffer = Buffer.concat(chunks);
const metadata = await sharp(buffer).metadata();
const width = metadata.width ?? 400;
const height = metadata.height ?? 300;
const svgText = `
<svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg">
<text x="50%" y="50%" font-family="Arial, sans-serif" font-size="${Math.max(24, width / 8)}" font-weight="bold" fill="white" opacity="0.5" text-anchor="middle" alignment-baseline="middle" transform="rotate(-30 ${width/2} ${height/2})">
PREVIEW
</text>
</svg>
`;
const watermarked = await sharp(buffer)
.composite([
{
input: Buffer.from(svgText),
gravity: "center",
},
])
.webp({ quality: 80 })
// Skaliere das Bild auf 480px Breite (wie vom User gewünscht)
const targetWidth = 480;
const resizedBuffer = await sharp(buffer)
.resize({ width: targetWidth, withoutEnlargement: true })
.toBuffer();
const resizedMetadata = await sharp(resizedBuffer).metadata();
const width = resizedMetadata.width ?? targetWidth;
const height = resizedMetadata.height ?? 300;
let watermarked = resizedBuffer;
try {
const logoPath = path.join(process.cwd(), "public", "brand", "logo-white.png");
const logoBuffer = await fs.readFile(logoPath);
// Logo auf 60% der Bildbreite skalieren
const logoTargetWidth = Math.round(width * 0.6);
const resizedLogo = await sharp(logoBuffer)
.resize({ width: logoTargetWidth, withoutEnlargement: true })
.toBuffer();
const logoBase64 = resizedLogo.toString("base64");
const logoMetadata = await sharp(resizedLogo).metadata();
const logoWidth = logoMetadata.width ?? logoTargetWidth;
const logoHeight = logoMetadata.height ?? (logoTargetWidth / 2);
const svgOverlay = `
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
<image href="data:image/png;base64,${logoBase64}" x="${(width - logoWidth) / 2}" y="${(height - logoHeight) / 2}" width="${logoWidth}" height="${logoHeight}" opacity="0.6"/>
</svg>
`;
watermarked = await sharp(resizedBuffer)
.composite([{ input: Buffer.from(svgOverlay), gravity: "center" }])
.webp({ quality: 80 })
.toBuffer();
} catch (err) {
console.error("Watermark logo error:", err);
// Fallback falls logo-white.png nicht existiert
watermarked = await sharp(resizedBuffer).webp({ quality: 80 }).toBuffer();
}
const responseHeaders = new Headers({
"cache-control": "private, max-age=86400, stale-while-revalidate=604800",