feat: Add flatrate billing model for editorial accounts
This commit is contained in:
1 parent
699580a6a0
commit
0b1ffdfdfc
39 files changed
+4900
-57
No files matched your search
@@ -4,12 +4,13 @@ import { notFound } from "next/navigation";
|
||||
import { AlbumCatalogError, albumCatalog, normalizePage } from "@/modules/albums/catalog";
|
||||
import { PhotoContactSheet } from "@/modules/albums/catalog-content";
|
||||
import { loadEditorialDownloadOptions } from "@/modules/downloads/stream";
|
||||
import { lightboxService } from "@/modules/lightbox/service";
|
||||
|
||||
import { requireEditorial } from "../../access";
|
||||
|
||||
type AlbumPageProps = Readonly<{
|
||||
params: Promise<{ albumId: string }>;
|
||||
searchParams: Promise<{ page?: string | string[]; suche?: string | string[] }>;
|
||||
searchParams: Promise<{ page?: string | string[]; suche?: string | string[]; format?: string | string[]; jahr?: string | string[] }>;
|
||||
}>;
|
||||
|
||||
export default async function AlbumPage({ params, searchParams }: AlbumPageProps) {
|
||||
@@ -20,11 +21,15 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
||||
]);
|
||||
const query = normalizedQuery(singleValue(rawSearchParams.suche));
|
||||
const currentPage = normalizePage(singleValue(rawSearchParams.page));
|
||||
const format = singleValue(rawSearchParams.format);
|
||||
const jahr = singleValue(rawSearchParams.jahr);
|
||||
const result = await loadAlbumPage({
|
||||
editorialId: principal.editorialId,
|
||||
albumId,
|
||||
query,
|
||||
page: singleValue(rawSearchParams.page),
|
||||
format,
|
||||
jahr,
|
||||
});
|
||||
|
||||
if (result.unavailable) {
|
||||
@@ -43,6 +48,7 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
||||
Alle Alben
|
||||
</Link>
|
||||
</div>
|
||||
<AlbumSearchForm albumId={result.album.id} query={query} format={format} jahr={jahr} />
|
||||
<PhotoContactSheet
|
||||
albumId={result.album.id}
|
||||
albumName={result.album.albumName}
|
||||
@@ -50,21 +56,60 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
||||
downloadOptions={result.downloadOptions}
|
||||
page={result.page}
|
||||
query={query}
|
||||
lightboxAssetIds={result.lightboxAssetIds}
|
||||
/>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; query: string; format?: string; jahr?: string; }) {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const years = Array.from({ length: 10 }, (_, i) => currentYear - i);
|
||||
|
||||
return (
|
||||
<form action={`/redaktion/alben/${albumId}`} className="global-search-form flex flex-wrap gap-4 items-center mb-8 bg-gray-50 p-4 rounded-xl border border-gray-200" role="search">
|
||||
<div className="flex-grow">
|
||||
<input
|
||||
type="search"
|
||||
name="suche"
|
||||
defaultValue={query}
|
||||
placeholder="Dieses Album durchsuchen..."
|
||||
aria-label="Dieses Album durchsuchen"
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-4">
|
||||
<select name="format" defaultValue={format || ""} className="px-3 py-2 border border-gray-300 rounded-md">
|
||||
<option value="">Alle Formate</option>
|
||||
<option value="quer">Querformat</option>
|
||||
<option value="hoch">Hochformat</option>
|
||||
</select>
|
||||
<select name="jahr" defaultValue={jahr || ""} className="px-3 py-2 border border-gray-300 rounded-md">
|
||||
<option value="">Alle Jahre</option>
|
||||
{years.map(y => (
|
||||
<option key={y} value={y.toString()}>{y}</option>
|
||||
))}
|
||||
</select>
|
||||
<button type="submit">Suchen</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
async function loadAlbumPage({
|
||||
editorialId,
|
||||
albumId,
|
||||
query,
|
||||
page,
|
||||
format,
|
||||
jahr,
|
||||
}: {
|
||||
editorialId: string;
|
||||
albumId: string;
|
||||
query: string;
|
||||
page: string | undefined;
|
||||
format?: string;
|
||||
jahr?: string;
|
||||
}) {
|
||||
try {
|
||||
const albums = await albumCatalog.getVisibleAlbums(editorialId);
|
||||
@@ -77,11 +122,40 @@ async function loadAlbumPage({
|
||||
description: query,
|
||||
page,
|
||||
});
|
||||
|
||||
// Client-side filtering for format and year
|
||||
if (format || jahr) {
|
||||
results.items = results.items.filter(asset => {
|
||||
let matches = true;
|
||||
|
||||
if (format) {
|
||||
const width = asset.exifInfo?.exifImageWidth ?? 0;
|
||||
const height = asset.exifInfo?.exifImageHeight ?? 0;
|
||||
if (width > 0 && height > 0) {
|
||||
const isLandscape = width >= height;
|
||||
if (format === 'quer' && !isLandscape) matches = false;
|
||||
if (format === 'hoch' && isLandscape) matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (jahr && matches) {
|
||||
const dateStr = asset.localDateTime ?? asset.fileCreatedAt;
|
||||
if (!dateStr || !dateStr.startsWith(jahr)) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
});
|
||||
}
|
||||
|
||||
const downloadOptions = await loadEditorialDownloadOptions(
|
||||
editorialId,
|
||||
results.items.map((asset) => asset.id),
|
||||
);
|
||||
return { album, page: results, downloadOptions, unavailable: false as const };
|
||||
const lightboxItems = await lightboxService.getLightboxItems(editorialId);
|
||||
const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId));
|
||||
return { album, page: results, downloadOptions, lightboxAssetIds, unavailable: false as const };
|
||||
} catch (error) {
|
||||
if (error instanceof AlbumCatalogError && error.code === "IMMICH_UNAVAILABLE") {
|
||||
return { album: null, page: null, unavailable: true as const };
|
||||
|
||||
Reference in new issue
Block a user