Merge branch 'codex/immich-redaktionsportal' into main
This commit is contained in:
commit
64147a3282
13 files changed
+909
-106
No files matched your search
@@ -101,8 +101,6 @@ function createService() {
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
localDateTime: null,
|
||||
fileCreatedAt: null,
|
||||
albums: [{ id: albumId }],
|
||||
}),
|
||||
};
|
||||
@@ -157,7 +155,7 @@ test("canonicalizes every UUID before fingerprinting, lookup, Immich calls, and
|
||||
expect(second).toEqual(first);
|
||||
expect(usages).toHaveLength(1);
|
||||
expect(usages[0]).toMatchObject({ editorialId, assetId, albumId, idempotencyKey });
|
||||
expect(immich.getAlbum).toHaveBeenCalledWith(albumId);
|
||||
expect(immich.listAlbumsForAsset).toHaveBeenCalledWith(assetId);
|
||||
expect(immich.getAsset).toHaveBeenCalledWith(assetId);
|
||||
});
|
||||
|
||||
@@ -226,8 +224,8 @@ test.each([
|
||||
}),
|
||||
).rejects.toMatchObject({ code });
|
||||
expect(findIntent).not.toHaveBeenCalled();
|
||||
expect(immich.getAlbum).not.toHaveBeenCalled();
|
||||
expect(immich.getAsset).not.toHaveBeenCalled();
|
||||
expect(immich.getAlbum).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
@@ -235,8 +233,9 @@ test("rejects an asset outside the exact requested album", async () => {
|
||||
const { service, immich, usages } = createService();
|
||||
immich.getAsset.mockResolvedValue({
|
||||
id: assetId,
|
||||
type: "IMAGE",
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
albums: [{ id: otherAlbumId }],
|
||||
});
|
||||
|
||||
@@ -249,18 +248,21 @@ test("rejects an asset outside the exact requested album", async () => {
|
||||
|
||||
test("rejects removal from the requested album between preflight and locked refresh", async () => {
|
||||
const { service, immich, usages } = createService();
|
||||
const currentAsset = {
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
localDateTime: null,
|
||||
fileCreatedAt: null,
|
||||
albums: [{ id: albumId }],
|
||||
};
|
||||
immich.getAsset
|
||||
.mockResolvedValueOnce(currentAsset)
|
||||
.mockResolvedValueOnce({ ...currentAsset, albums: [] });
|
||||
.mockResolvedValueOnce({
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
albums: [{ id: albumId }],
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
albums: [],
|
||||
});
|
||||
|
||||
await expect(service.createNewUsage(newUsageInput)).rejects.toMatchObject({
|
||||
code: "ASSET_NOT_IN_ALBUM",
|
||||
@@ -271,9 +273,23 @@ test("rejects removal from the requested album between preflight and locked refr
|
||||
|
||||
test("persists metadata from the locked final Immich refresh", async () => {
|
||||
const { service, immich, usages } = createService();
|
||||
immich.getAlbum
|
||||
.mockResolvedValueOnce({ id: albumId, albumName: "Presse 2026" })
|
||||
.mockResolvedValueOnce({ id: albumId, albumName: "Presse final" });
|
||||
immich.getAsset
|
||||
.mockResolvedValueOnce({
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
originalFileName: "jubel.jpg",
|
||||
originalMimeType: "image/jpeg",
|
||||
albums: [{ id: albumId }],
|
||||
})
|
||||
.mockResolvedValueOnce([
|
||||
{
|
||||
id: albumId,
|
||||
albumName: "Presse final",
|
||||
description: null,
|
||||
albumThumbnailAssetId: assetId,
|
||||
assetCount: 1,
|
||||
},
|
||||
]);
|
||||
const currentAsset = {
|
||||
id: assetId,
|
||||
type: "IMAGE" as const,
|
||||
@@ -294,7 +310,6 @@ test("persists metadata from the locked final Immich refresh", async () => {
|
||||
await service.createNewUsage(newUsageInput);
|
||||
|
||||
expect(immich.getAsset).toHaveBeenCalledTimes(2);
|
||||
expect(immich.getAlbum).toHaveBeenCalledTimes(2);
|
||||
expect(usages).toEqual([
|
||||
expect.objectContaining({ albumName: "Presse final", filename: "final.jpg" }),
|
||||
]);
|
||||
|
||||
@@ -60,9 +60,10 @@ type UsageImmich = {
|
||||
getAlbum(albumId: string): Promise<{ id: string; albumName: string }>;
|
||||
getAsset(assetId: string): Promise<{
|
||||
id: string;
|
||||
type: string;
|
||||
originalFileName: string;
|
||||
albums?: { id: string }[];
|
||||
originalMimeType: string;
|
||||
type: string;
|
||||
albums: Array<{ id: string }>;
|
||||
}>;
|
||||
};
|
||||
|
||||
@@ -88,16 +89,16 @@ export function createUsageService({
|
||||
const existing = await repository.findIntent(input.editorialId, input.idempotencyKey);
|
||||
if (existing) return resolveIntent(existing, fingerprint, "new_usage");
|
||||
|
||||
const album = await loadRequestedAlbum(immich, input.assetId, input.albumId);
|
||||
const asset = await loadImageAsset(immich, input.assetId);
|
||||
const album = await loadRequestedAlbum(immich, asset, input.albumId);
|
||||
const persisted = await repository.createBillableIntent({
|
||||
...input,
|
||||
albumName: normalizeUpstreamSnapshot(album.albumName),
|
||||
filename: normalizeUpstreamSnapshot(asset.originalFileName),
|
||||
requestFingerprint: fingerprint,
|
||||
}, async () => {
|
||||
const currentAlbum = await loadRequestedAlbum(immich, input.assetId, input.albumId);
|
||||
const currentAsset = await loadImageAsset(immich, input.assetId);
|
||||
const currentAlbum = await loadRequestedAlbum(immich, currentAsset, input.albumId);
|
||||
return {
|
||||
albumName: normalizeUpstreamSnapshot(currentAlbum.albumName),
|
||||
filename: normalizeUpstreamSnapshot(currentAsset.originalFileName),
|
||||
@@ -329,18 +330,27 @@ function normalizeNewUsageInput(input: CreateNewUsageInput): CreateNewUsageInput
|
||||
|
||||
async function loadRequestedAlbum(
|
||||
immich: UsageImmich,
|
||||
asset: Awaited<ReturnType<UsageImmich["getAsset"]>>,
|
||||
assetId: string,
|
||||
albumId: string,
|
||||
): Promise<{ id: string; albumName: string }> {
|
||||
if (!asset.albums?.some((a) => a.id === albumId)) {
|
||||
let asset;
|
||||
try {
|
||||
asset = await immich.getAsset(assetId);
|
||||
} catch {
|
||||
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
|
||||
}
|
||||
|
||||
if (!asset.albums.some((a) => a.id === albumId)) {
|
||||
throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
|
||||
}
|
||||
|
||||
let album;
|
||||
try {
|
||||
album = await immich.getAlbum(albumId);
|
||||
} catch {
|
||||
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
|
||||
}
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user