From ce66dba0c876f1e6256bb3810d29ce5e22660975 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Wed, 30 Apr 2025 17:50:57 +0200 Subject: [PATCH] Add unmatched paths in `GET /videos` (for scanner) --- api/src/controllers/videos.ts | 18 +++++++++++++++++- api/src/models/video.ts | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/api/src/controllers/videos.ts b/api/src/controllers/videos.ts index 9cd1bdc4..5b9298d4 100644 --- a/api/src/controllers/videos.ts +++ b/api/src/controllers/videos.ts @@ -84,7 +84,23 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] }) const paths = await db.select({ path: videos.path }).from(videos); - return { paths: paths.map((x) => x.path), guesses }; + const unmatched = await db + .select({ path: videos.path }) + .from(videos) + .where( + notExists( + db + .select() + .from(entryVideoJoin) + .where(eq(entryVideoJoin.videoPk, videos.pk)), + ), + ); + + return { + paths: paths.map((x) => x.path), + guesses, + unmatched: unmatched.map((x) => x.path), + }; }, { detail: { description: "Get all video registered & guessed made" }, diff --git a/api/src/models/video.ts b/api/src/models/video.ts index c36635fe..4877093a 100644 --- a/api/src/models/video.ts +++ b/api/src/models/video.ts @@ -137,6 +137,7 @@ export const Guesses = t.Object({ Resource(), ), ), + unmatched: t.Array(t.String()), }); export type Guesses = typeof Guesses.static; @@ -144,6 +145,7 @@ registerExamples(Guesses, { paths: [ "/videos/Evangelion S01E02.mkv", "/videos/Evangelion (1995) S01E26.mkv", + "/videos/SomeUnknownThing.mkv", ], guesses: { Evangelion: { @@ -157,4 +159,5 @@ registerExamples(Guesses, { }, }, }, + unmatched: ["/videos/SomeUnknownThing.mkv"], });