feat: add usage and download intent accounting
This commit is contained in:
1 parent
846904f3db
commit
22fe6bf659
14 files changed
+3008
-2
No files matched your search
@@ -6,6 +6,7 @@ import { createImmichClient } from "./client";
|
||||
import {
|
||||
immichAlbum,
|
||||
immichAlbumDetail,
|
||||
immichAsset,
|
||||
immichMetadataSearchResponse,
|
||||
} from "../../../tests/fixtures/immich";
|
||||
|
||||
@@ -73,6 +74,18 @@ test("gets album details from the documented album endpoint", async () => {
|
||||
await expect(client.getAlbum("album-1")).resolves.toEqual(immichAlbumDetail);
|
||||
});
|
||||
|
||||
test("gets current asset metadata immediately before accounting", async () => {
|
||||
server.use(
|
||||
http.get(`${baseUrl}/api/assets/asset-1`, ({ request }) => {
|
||||
expect(request.method).toBe("GET");
|
||||
expect(request.headers.get("x-api-key")).toBe(apiKey);
|
||||
return HttpResponse.json(immichAsset);
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(client.getAsset("asset-1")).resolves.toEqual(immichAsset);
|
||||
});
|
||||
|
||||
test("forces IMAGE and authorized album IDs in metadata search", async () => {
|
||||
server.use(
|
||||
http.post(`${baseUrl}/api/search/metadata`, async ({ request }) => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { ImmichClientError, type ImmichErrorCode } from "./errors";
|
||||
import type {
|
||||
ImmichAlbum,
|
||||
ImmichAlbumSummary,
|
||||
ImmichAsset,
|
||||
ImmichBinary,
|
||||
ImmichClient,
|
||||
ImmichSearchPage,
|
||||
@@ -27,6 +28,10 @@ const assetSchema = z
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
const currentAssetSchema = assetSchema.extend({
|
||||
type: z.enum(["IMAGE", "VIDEO"]),
|
||||
});
|
||||
|
||||
const albumSummarySchema = z
|
||||
.object({
|
||||
id: z.string(),
|
||||
@@ -325,6 +330,14 @@ export function createImmichClient({
|
||||
signal,
|
||||
);
|
||||
},
|
||||
getAsset(assetId, signal) {
|
||||
return requestJson<ImmichAsset>(
|
||||
`/assets/${encodeURIComponent(assetId)}`,
|
||||
{ method: "GET" },
|
||||
currentAssetSchema,
|
||||
signal,
|
||||
);
|
||||
},
|
||||
searchPhotos(input, signal) {
|
||||
return requestJson<ImmichSearchPage>(
|
||||
"/search/metadata",
|
||||
|
||||
@@ -8,7 +8,7 @@ export type ImmichAlbumSummary = {
|
||||
|
||||
export type ImmichAsset = {
|
||||
id: string;
|
||||
type: "IMAGE";
|
||||
type: "IMAGE" | "VIDEO";
|
||||
originalFileName: string;
|
||||
originalMimeType: string;
|
||||
localDateTime: string | null;
|
||||
@@ -38,6 +38,7 @@ export interface ImmichClient {
|
||||
listAlbums(signal?: AbortSignal): Promise<ImmichAlbumSummary[]>;
|
||||
listAlbumsForAsset(assetId: string, signal?: AbortSignal): Promise<ImmichAlbumSummary[]>;
|
||||
getAlbum(albumId: string, signal?: AbortSignal): Promise<ImmichAlbum>;
|
||||
getAsset(assetId: string, signal?: AbortSignal): Promise<ImmichAsset>;
|
||||
searchPhotos(
|
||||
input: { albumIds: string[]; description?: string; page: number; size: number; type?: "IMAGE" },
|
||||
signal?: AbortSignal,
|
||||
|
||||
Reference in new issue
Block a user