diff --git a/api/bun.lock b/api/bun.lock index a1983672..58911c32 100644 --- a/api/bun.lock +++ b/api/bun.lock @@ -8,7 +8,7 @@ "blurhash": "^2.0.5", "drizzle-kit": "^0.31.0", "drizzle-orm": "0.43.1", - "elysia": "^1.2.25", + "elysia": "^1.3.0", "jose": "^6.0.10", "parjs": "^1.3.9", "pg": "^8.15.6", @@ -27,7 +27,7 @@ "packages": { "@drizzle-team/brocli": ["@drizzle-team/brocli@0.10.2", "", {}, "sha512-z33Il7l5dKjUgGULTqBsQBQwckHh5AbIuxhdsIxDDiZAzBOrZO6q9ogcWC65kU382AfynTfgNumVcNIjuIua6w=="], - "@elysiajs/swagger": ["@elysiajs/swagger@github:zoriya/elysia-swagger#ef89c17", { "dependencies": { "@scalar/themes": "^0.9.81", "@scalar/types": "^0.1.3", "openapi-types": "^12.1.3", "pathe": "^1.1.2" }, "peerDependencies": { "elysia": ">= 1.2.0" } }, "zoriya-elysia-swagger-ef89c17"], + "@elysiajs/swagger": ["@elysiajs/swagger@github:zoriya/elysia-swagger#f88fbc7", { "dependencies": { "@scalar/themes": "^0.9.81", "@scalar/types": "^0.1.3", "openapi-types": "^12.1.3", "pathe": "^1.1.2" }, "peerDependencies": { "elysia": ">= 1.3.0" } }, "zoriya-elysia-swagger-f88fbc7"], "@emnapi/runtime": ["@emnapi/runtime@1.4.1", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-LMshMVP0ZhACNjQNYXiU1iZJ6QCcv0lUdPDPugqGvCGXt5xtRVBPdtA0qU12pEXZzpWAhWlZYptfdAFq10DOVQ=="], @@ -133,6 +133,10 @@ "@sinclair/typebox": ["@sinclair/typebox@0.34.33", "", {}, "sha512-5HAV9exOMcXRUxo+9iYB5n09XxzCXnfy4VTNW4xnDv+FgjzAGY989C28BIdljKqmF+ZltUwujE3aossvcVtq6g=="], + "@tokenizer/inflate": ["@tokenizer/inflate@0.2.7", "", { "dependencies": { "debug": "^4.4.0", "fflate": "^0.8.2", "token-types": "^6.0.0" } }, "sha512-MADQgmZT1eKjp06jpI2yozxaU9uVs4GzzgSL+uEq7bVcJ9V1ZXQkeGNql1fsSI0gMy1vhvNTNbUqrx+pZfJVmg=="], + + "@tokenizer/token": ["@tokenizer/token@0.3.0", "", {}, "sha512-OvjF+z51L3ov0OyAU0duzsYuvO01PH7x4t6DJx+guahgTnBHkhJdG7soQeTSFLWN3efnHyibZ4Z8l2EuWwJN3A=="], + "@types/node": ["@types/node@22.13.13", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-ClsL5nMwKaBRwPcCvH8E7+nU4GxHVx1axNvMZTFHMEfNI7oahimt26P5zjVCRrjiIWj6YFXfE1v3dEp94wLcGQ=="], "@types/pg": ["@types/pg@8.11.14", "", { "dependencies": { "@types/node": "*", "pg-protocol": "*", "pg-types": "^4.0.1" } }, "sha512-qyD11E5R3u0eJmd1lB0WnWKXJGA7s015nyARWljfz5DcX83TKAIlY+QrmvzQTsbIe+hkiFtkyL2gHC6qwF6Fbg=="], @@ -165,22 +169,30 @@ "drizzle-orm": ["drizzle-orm@0.43.1", "", { "peerDependencies": { "@aws-sdk/client-rds-data": ">=3", "@cloudflare/workers-types": ">=4", "@electric-sql/pglite": ">=0.2.0", "@libsql/client": ">=0.10.0", "@libsql/client-wasm": ">=0.10.0", "@neondatabase/serverless": ">=0.10.0", "@op-engineering/op-sqlite": ">=2", "@opentelemetry/api": "^1.4.1", "@planetscale/database": ">=1.13", "@prisma/client": "*", "@tidbcloud/serverless": "*", "@types/better-sqlite3": "*", "@types/pg": "*", "@types/sql.js": "*", "@vercel/postgres": ">=0.8.0", "@xata.io/client": "*", "better-sqlite3": ">=7", "bun-types": "*", "expo-sqlite": ">=14.0.0", "gel": ">=2", "knex": "*", "kysely": "*", "mysql2": ">=2", "pg": ">=8", "postgres": ">=3", "sql.js": ">=1", "sqlite3": ">=5" }, "optionalPeers": ["@aws-sdk/client-rds-data", "@cloudflare/workers-types", "@electric-sql/pglite", "@libsql/client", "@libsql/client-wasm", "@neondatabase/serverless", "@op-engineering/op-sqlite", "@opentelemetry/api", "@planetscale/database", "@prisma/client", "@tidbcloud/serverless", "@types/better-sqlite3", "@types/pg", "@types/sql.js", "@vercel/postgres", "@xata.io/client", "better-sqlite3", "bun-types", "expo-sqlite", "gel", "knex", "kysely", "mysql2", "pg", "postgres", "sql.js", "sqlite3"] }, "sha512-dUcDaZtE/zN4RV/xqGrVSMpnEczxd5cIaoDeor7Zst9wOe/HzC/7eAaulywWGYXdDEc9oBPMjayVEDg0ziTLJA=="], - "elysia": ["elysia@1.2.25", "", { "dependencies": { "@sinclair/typebox": "^0.34.27", "cookie": "^1.0.2", "memoirist": "^0.3.0", "openapi-types": "^12.1.3" }, "peerDependencies": { "typescript": ">= 5.0.0" }, "optionalPeers": ["typescript"] }, "sha512-WsdQpORJvb4uszzeqYT0lg97knw1iBW1NTzJ1Jm57tiHg+DfAotlWXYbjmvQ039ssV0fYELDHinLLoUazZkEHg=="], + "elysia": ["elysia@1.3.0", "", { "dependencies": { "cookie": "^1.0.2", "exact-mirror": "0.1.1", "fast-decode-uri-component": "^1.0.1" }, "optionalDependencies": { "@sinclair/typebox": "^0.34.33", "openapi-types": "^12.1.3" }, "peerDependencies": { "file-type": ">= 20.0.0", "typescript": ">= 5.0.0" } }, "sha512-ZhDB3i6eDYAYGgS19L/ATiEau5XUsbRVflPSsLkEUlIohgCimw24MgD+pgXXEy5mRsFJFeAdHOSL2yKsVVsJSw=="], "esbuild": ["esbuild@0.25.3", "", { "optionalDependencies": { "@esbuild/aix-ppc64": "0.25.3", "@esbuild/android-arm": "0.25.3", "@esbuild/android-arm64": "0.25.3", "@esbuild/android-x64": "0.25.3", "@esbuild/darwin-arm64": "0.25.3", "@esbuild/darwin-x64": "0.25.3", "@esbuild/freebsd-arm64": "0.25.3", "@esbuild/freebsd-x64": "0.25.3", "@esbuild/linux-arm": "0.25.3", "@esbuild/linux-arm64": "0.25.3", "@esbuild/linux-ia32": "0.25.3", "@esbuild/linux-loong64": "0.25.3", "@esbuild/linux-mips64el": "0.25.3", "@esbuild/linux-ppc64": "0.25.3", "@esbuild/linux-riscv64": "0.25.3", "@esbuild/linux-s390x": "0.25.3", "@esbuild/linux-x64": "0.25.3", "@esbuild/netbsd-arm64": "0.25.3", "@esbuild/netbsd-x64": "0.25.3", "@esbuild/openbsd-arm64": "0.25.3", "@esbuild/openbsd-x64": "0.25.3", "@esbuild/sunos-x64": "0.25.3", "@esbuild/win32-arm64": "0.25.3", "@esbuild/win32-ia32": "0.25.3", "@esbuild/win32-x64": "0.25.3" }, "bin": { "esbuild": "bin/esbuild" } }, "sha512-qKA6Pvai73+M2FtftpNKRxJ78GIjmFXFxd/1DVBqGo/qNhLSfv+G12n9pNoWdytJC8U00TrViOwpjT0zgqQS8Q=="], "esbuild-register": ["esbuild-register@3.6.0", "", { "dependencies": { "debug": "^4.3.4" }, "peerDependencies": { "esbuild": ">=0.12 <1" } }, "sha512-H2/S7Pm8a9CL1uhp9OvjwrBh5Pvx0H8qVOxNu8Wed9Y7qv56MPtq+GGM8RJpq6glYJn9Wspr8uw7l55uyinNeg=="], + "exact-mirror": ["exact-mirror@0.1.1", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-jygrs/z9JT3UBDVPsu4vLy8gqtTLTxVzoxLmDzkVXHizRGixDMdkdLF98ChZxsqHL0F7IcpTf8GUFRqa2qt3uw=="], + + "fast-decode-uri-component": ["fast-decode-uri-component@1.0.1", "", {}, "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg=="], + + "fflate": ["fflate@0.8.2", "", {}, "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="], + + "file-type": ["file-type@20.5.0", "", { "dependencies": { "@tokenizer/inflate": "^0.2.6", "strtok3": "^10.2.0", "token-types": "^6.0.0", "uint8array-extras": "^1.4.0" } }, "sha512-BfHZtG/l9iMm4Ecianu7P8HRD2tBHLtjXinm4X62XBOYzi7CYA7jyqfJzOvXHqzVrVPYqBo2/GvbARMaaJkKVg=="], + "get-tsconfig": ["get-tsconfig@4.10.0", "", { "dependencies": { "resolve-pkg-maps": "^1.0.0" } }, "sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A=="], "hookable": ["hookable@5.5.3", "", {}, "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ=="], + "ieee754": ["ieee754@1.2.1", "", {}, "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="], + "is-arrayish": ["is-arrayish@0.3.2", "", {}, "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ=="], "jose": ["jose@6.0.10", "", {}, "sha512-skIAxZqcMkOrSwjJvplIPYrlXGpxTPnro2/QWTDCxAdWQrSTV5/KqspMWmi5WAx5+ULswASJiZ0a+1B/Lxt9cw=="], - "memoirist": ["memoirist@0.3.0", "", {}, "sha512-wR+4chMgVPq+T6OOsk40u9Wlpw1Pjx66NMNiYxCQQ4EUJ7jDs3D9kTCeKdBOkvAiqXlHLVJlvYL01PvIJ1MPNg=="], - "ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="], "node-addon-api": ["node-addon-api@8.3.1", "", {}, "sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA=="], @@ -195,6 +207,8 @@ "pathe": ["pathe@1.1.2", "", {}, "sha512-whLdWMYL2TwI08hn8/ZqAbrVemu0LNaNNJZX73O6qaIdCTfXutsLhMkjdENX0qhsQ9uIimo4/aQOmXkoon2nDQ=="], + "peek-readable": ["peek-readable@7.0.0", "", {}, "sha512-nri2TO5JE3/mRryik9LlHFT53cgHfRK0Lt0BAZQXku/AW3E6XLt2GaY8siWi7dvW/m1z0ecn+J+bpDa9ZN3IsQ=="], + "pg": ["pg@8.15.6", "", { "dependencies": { "pg-connection-string": "^2.8.5", "pg-pool": "^3.9.6", "pg-protocol": "^1.9.5", "pg-types": "^2.1.0", "pgpass": "1.x" }, "optionalDependencies": { "pg-cloudflare": "^1.2.5" }, "peerDependencies": { "pg-native": ">=3.0.1" }, "optionalPeers": ["pg-native"] }, "sha512-yvao7YI3GdmmrslNVsZgx9PfntfWrnXwtR+K/DjI0I/sTKif4Z623um+sjVZ1hk5670B+ODjvHDAckKdjmPTsg=="], "pg-cloudflare": ["pg-cloudflare@1.2.5", "", {}, "sha512-OOX22Vt0vOSRrdoUPKJ8Wi2OpE/o/h9T8X1s4qSkCedbNah9ei2W2765be8iMVxQUsvgT7zIAT2eIa9fs5+vtg=="], @@ -239,8 +253,16 @@ "split2": ["split2@4.2.0", "", {}, "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg=="], + "strtok3": ["strtok3@10.2.2", "", { "dependencies": { "@tokenizer/token": "^0.3.0", "peek-readable": "^7.0.0" } }, "sha512-Xt18+h4s7Z8xyZ0tmBoRmzxcop97R4BAh+dXouUDCYn+Em+1P3qpkUfI5ueWLT8ynC5hZ+q4iPEmGG1urvQGBg=="], + + "token-types": ["token-types@6.0.0", "", { "dependencies": { "@tokenizer/token": "^0.3.0", "ieee754": "^1.2.1" } }, "sha512-lbDrTLVsHhOMljPscd0yitpozq7Ga2M5Cvez5AjGg8GASBjtt6iERCAJ93yommPmz62fb45oFIXHEZ3u9bfJEA=="], + "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], + "typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="], + + "uint8array-extras": ["uint8array-extras@1.4.0", "", {}, "sha512-ZPtzy0hu4cZjv3z5NW9gfKnNLjoz4y6uv4HlelAjDK7sY/xOkKZv9xK/WQpcsBB3jEybChz9DPC2U/+cusjJVQ=="], + "undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="], "xtend": ["xtend@4.0.2", "", {}, "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ=="], diff --git a/api/package.json b/api/package.json index 1206b686..c6054e9e 100644 --- a/api/package.json +++ b/api/package.json @@ -13,7 +13,7 @@ "blurhash": "^2.0.5", "drizzle-kit": "^0.31.0", "drizzle-orm": "0.43.1", - "elysia": "^1.2.25", + "elysia": "^1.3.0", "jose": "^6.0.10", "parjs": "^1.3.9", "pg": "^8.15.6", diff --git a/api/src/auth.ts b/api/src/auth.ts index 71a925be..363c085c 100644 --- a/api/src/auth.ts +++ b/api/src/auth.ts @@ -42,10 +42,10 @@ export const auth = new Elysia({ name: "auth" }) { additionalProperties: true }, ), }) - .resolve(async ({ headers: { authorization }, error }) => { + .resolve(async ({ headers: { authorization }, status }) => { const bearer = authorization?.slice(7); if (!bearer) { - return error(500, { + return status(500, { status: 500, message: "No jwt, auth server configuration error.", }); @@ -63,7 +63,7 @@ export const auth = new Elysia({ name: "auth" }) return { jwt }; } catch (err) { - return error(403, { + return status(403, { status: 403, message: "Invalid jwt. Verification vailed", details: err, @@ -73,10 +73,10 @@ export const auth = new Elysia({ name: "auth" }) .macro({ permissions(perms: string[]) { return { - beforeHandle: ({ jwt, error }) => { + beforeHandle: ({ jwt, status }) => { for (const perm of perms) { if (!jwt!.permissions.includes(perm)) { - return error(403, { + return status(403, { status: 403, message: `Missing permission: '${perm}'.`, details: { current: jwt!.permissions, required: perms }, @@ -87,7 +87,7 @@ export const auth = new Elysia({ name: "auth" }) }; }, }) - .as("plugin"); + .as("scoped"); const User = t.Object({ id: t.String({ format: "uuid" }), diff --git a/api/src/base.ts b/api/src/base.ts index 5a24d0e4..0f15ea3d 100644 --- a/api/src/base.ts +++ b/api/src/base.ts @@ -52,7 +52,7 @@ export const base = new Elysia({ name: "base" }) detail: { description: "Check if the api is healthy." }, response: { 200: t.Object({ status: t.Literal("healthy") }) }, }) - .as("plugin"); + .as("scoped"); export const prefix = process.env.KYOO_PREFIX ?? ""; export const handlers = new Elysia({ prefix }) diff --git a/api/src/controllers/entries.ts b/api/src/controllers/entries.ts index dce5edae..b34fd1a4 100644 --- a/api/src/controllers/entries.ts +++ b/api/src/controllers/entries.ts @@ -255,7 +255,7 @@ export const entriesH = new Elysia({ tags: ["series"] }) headers: { "accept-language": languages }, request: { url }, jwt: { sub }, - error, + status, }) => { const [serie] = await db .select({ pk: shows.pk }) @@ -269,7 +269,7 @@ export const entriesH = new Elysia({ tags: ["series"] }) .limit(1); if (!serie) { - return error(404, { + return status(404, { status: 404, message: `No serie with the id or slug: '${id}'.`, }); @@ -335,7 +335,7 @@ export const entriesH = new Elysia({ tags: ["series"] }) query: { limit, after, query, sort, filter }, request: { url }, jwt: { sub }, - error, + status, }) => { const [serie] = await db .select({ pk: shows.pk }) @@ -349,7 +349,7 @@ export const entriesH = new Elysia({ tags: ["series"] }) .limit(1); if (!serie) { - return error(404, { + return status(404, { status: 404, message: `No serie with the id or slug: '${id}'.`, }); diff --git a/api/src/controllers/images.ts b/api/src/controllers/images.ts index df04e794..2056592f 100644 --- a/api/src/controllers/images.ts +++ b/api/src/controllers/images.ts @@ -28,14 +28,14 @@ function getRedirectToImageHandler({ headers: { "accept-language": languages }, query: { quality }, set, - error, + status, redirect, }: { params: { id: string; image: "poster" | "thumbnail" | "banner" | "logo" }; headers: { "accept-language": string }; query: { quality: "high" | "medium" | "low" }; set: Context["set"]; - error: Context["error"]; + status: Context["status"]; redirect: Context["redirect"]; }) { id ??= "random"; @@ -76,13 +76,13 @@ function getRedirectToImageHandler({ .limit(1); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No item found with id or slug: '${id}'.`, }); } if (!ret.language) { - return error(422, { + return status(422, { status: 422, message: "Accept-Language header could not be satisfied.", }); @@ -162,7 +162,7 @@ export const imagesH = new Elysia({ tags: ["images"] }) }) .get( "/staff/:id/image", - async ({ params: { id }, query: { quality }, error, redirect }) => { + async ({ params: { id }, query: { quality }, status, redirect }) => { const [ret] = await db .select({ image: staff.image }) .from(staff) @@ -177,7 +177,7 @@ export const imagesH = new Elysia({ tags: ["images"] }) .limit(1); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No staff member found with id or slug: '${id}'.`, }); @@ -211,7 +211,7 @@ export const imagesH = new Elysia({ tags: ["images"] }) headers: { "accept-language": languages }, query: { quality }, set, - error, + status, redirect, }) => { const lang = processLanguages(languages); @@ -248,13 +248,13 @@ export const imagesH = new Elysia({ tags: ["images"] }) .limit(1); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No studio found with id or slug: '${id}'.`, }); } if (!ret.language) { - return error(422, { + return status(422, { status: 422, message: "Accept-Language header could not be satisfied.", }); diff --git a/api/src/controllers/profiles/history.ts b/api/src/controllers/profiles/history.ts index fdf239c2..a2d9c32b 100644 --- a/api/src/controllers/profiles/history.ts +++ b/api/src/controllers/profiles/history.ts @@ -111,10 +111,10 @@ export const historyH = new Elysia({ tags: ["profiles"] }) query: { sort, filter, query, limit, after }, headers: { "accept-language": languages, authorization }, request: { url }, - error, + status, }) => { const uInfo = await getUserInfo(id, { authorization }); - if ("status" in uInfo) return error(uInfo.status as 404, uInfo); + if ("status" in uInfo) return status(uInfo.status as 404, uInfo); const langs = processLanguages(languages); const items = (await getEntries({ @@ -163,7 +163,7 @@ export const historyH = new Elysia({ tags: ["profiles"] }) ) .post( "/profiles/me/history", - async ({ body, jwt: { sub }, error }) => { + async ({ body, jwt: { sub }, status }) => { const profilePk = await getOrCreateProfile(sub); const hist = values( @@ -321,7 +321,7 @@ export const historyH = new Elysia({ tags: ["profiles"] }) }, }); - return error(201, { status: 201, inserted: rows.length }); + return status(201, { status: 201, inserted: rows.length }); }, { detail: { description: "Bulk add entries/movies to your watch history." }, diff --git a/api/src/controllers/profiles/watchlist.ts b/api/src/controllers/profiles/watchlist.ts index 3e6df843..5adf5f16 100644 --- a/api/src/controllers/profiles/watchlist.ts +++ b/api/src/controllers/profiles/watchlist.ts @@ -197,10 +197,10 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) jwt: { settings }, headers: { "accept-language": languages, authorization }, request: { url }, - error, + status, }) => { const uInfo = await getUserInfo(id, { authorization }); - if ("status" in uInfo) return error(uInfo.status as 404, uInfo); + if ("status" in uInfo) return status(uInfo.status as 404, uInfo); const langs = processLanguages(languages); const items = await getShows({ @@ -261,7 +261,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) ) .post( "/series/:id/watchstatus", - async ({ params: { id }, body, jwt: { sub }, error }) => { + async ({ params: { id }, body, jwt: { sub }, status }) => { const [show] = await db .select({ pk: shows.pk, entriesCount: shows.entriesCount }) .from(shows) @@ -273,7 +273,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) ); if (!show) { - return error(404, { + return status(404, { status: 404, message: `No serie found for the id/slug: '${id}'.`, }); @@ -302,7 +302,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) ) .post( "/movies/:id/watchstatus", - async ({ params: { id }, body, jwt: { sub }, error }) => { + async ({ params: { id }, body, jwt: { sub }, status }) => { const [show] = await db .select({ pk: shows.pk }) .from(shows) @@ -314,7 +314,7 @@ export const watchlistH = new Elysia({ tags: ["profiles"] }) ); if (!show) { - return error(404, { + return status(404, { status: 404, message: `No movie found for the id/slug: '${id}'.`, }); diff --git a/api/src/controllers/seasons.ts b/api/src/controllers/seasons.ts index 1a28683b..82b61462 100644 --- a/api/src/controllers/seasons.ts +++ b/api/src/controllers/seasons.ts @@ -51,7 +51,7 @@ export const seasonsH = new Elysia({ tags: ["series"] }) query: { limit, after, query, sort, filter }, headers: { "accept-language": languages }, request: { url }, - error, + status, }) => { const langs = processLanguages(languages); @@ -67,7 +67,7 @@ export const seasonsH = new Elysia({ tags: ["series"] }) .limit(1); if (!serie) { - return error(404, { + return status(404, { status: 404, message: `No serie with the id or slug: '${id}'.`, }); diff --git a/api/src/controllers/seed/index.ts b/api/src/controllers/seed/index.ts index 341b1302..a68f8d5e 100644 --- a/api/src/controllers/seed/index.ts +++ b/api/src/controllers/seed/index.ts @@ -16,10 +16,10 @@ export const seed = new Elysia() }) .post( "/movies", - async ({ body, error }) => { + async ({ body, status }) => { const ret = await seedMovie(body); - if ("status" in ret) return error(ret.status, ret as any); - return error(ret.updated ? 200 : 201, ret); + if ("status" in ret) return status(ret.status, ret as any); + return status(ret.updated ? 200 : 201, ret); }, { detail: { @@ -47,10 +47,10 @@ export const seed = new Elysia() ) .post( "/series", - async ({ body, error }) => { + async ({ body, status }) => { const ret = await seedSerie(body); - if ("status" in ret) return error(ret.status, ret as any); - return error(ret.updated ? 200 : 201, ret); + if ("status" in ret) return status(ret.status, ret as any); + return status(ret.updated ? 200 : 201, ret); }, { detail: { diff --git a/api/src/controllers/shows/collections.ts b/api/src/controllers/shows/collections.ts index 75bc5dcb..780cd9fb 100644 --- a/api/src/controllers/shows/collections.ts +++ b/api/src/controllers/shows/collections.ts @@ -41,7 +41,7 @@ export const collections = new Elysia({ headers: { "accept-language": languages }, query: { preferOriginal, with: relations }, jwt: { sub, settings }, - error, + status, set, }) => { const langs = processLanguages(languages); @@ -58,13 +58,13 @@ export const collections = new Elysia({ userId: sub, }); if (!ret) { - return error(404, { + return status(404, { status: 404, message: "Collection not found", }); } if (!ret.language) { - return error(422, { + return status(422, { status: 422, message: "Accept-Language header could not be satisfied.", }); @@ -109,7 +109,7 @@ export const collections = new Elysia({ ) .get( "random", - async ({ error, redirect }) => { + async ({ status, redirect }) => { const [serie] = await db .select({ slug: shows.slug }) .from(shows) @@ -117,7 +117,7 @@ export const collections = new Elysia({ .orderBy(sql`random()`) .limit(1); if (!serie) - return error(404, { + return status(404, { status: 404, message: "No collection in the database.", }); @@ -230,7 +230,7 @@ export const collections = new Elysia({ headers: { "accept-language": languages }, jwt: { sub, settings }, request: { url }, - error, + status, }) => { const [collection] = await db .select({ pk: shows.pk }) @@ -244,7 +244,7 @@ export const collections = new Elysia({ .limit(1); if (!collection) { - return error(404, { + return status(404, { status: 404, message: `No collection with the id or slug: '${id}'.`, }); @@ -287,7 +287,7 @@ export const collections = new Elysia({ headers: { "accept-language": languages }, jwt: { sub, settings }, request: { url }, - error, + status, }) => { const [collection] = await db .select({ pk: shows.pk }) @@ -301,7 +301,7 @@ export const collections = new Elysia({ .limit(1); if (!collection) { - return error(404, { + return status(404, { status: 404, message: `No collection with the id or slug: '${id}'.`, }); @@ -344,7 +344,7 @@ export const collections = new Elysia({ headers: { "accept-language": languages }, jwt: { sub, settings }, request: { url }, - error, + status, }) => { const [collection] = await db .select({ pk: shows.pk }) @@ -358,7 +358,7 @@ export const collections = new Elysia({ .limit(1); if (!collection) { - return error(404, { + return status(404, { status: 404, message: `No collection with the id or slug: '${id}'.`, }); diff --git a/api/src/controllers/shows/movies.ts b/api/src/controllers/shows/movies.ts index 3fadc317..059ffad4 100644 --- a/api/src/controllers/shows/movies.ts +++ b/api/src/controllers/shows/movies.ts @@ -31,7 +31,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) headers: { "accept-language": languages }, query: { preferOriginal, with: relations }, jwt: { sub, settings }, - error, + status, set, }) => { const langs = processLanguages(languages); @@ -48,13 +48,13 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) userId: sub, }); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No movie found with id or slug: '${id}'.`, }); } if (!ret.language) { - return error(422, { + return status(422, { status: 422, message: "Accept-Language header could not be satisfied.", }); @@ -99,7 +99,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) ) .get( "random", - async ({ error, redirect }) => { + async ({ status, redirect }) => { const [movie] = await db .select({ slug: shows.slug }) .from(shows) @@ -107,7 +107,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] }) .orderBy(sql`random()`) .limit(1); if (!movie) - return error(404, { + return status(404, { status: 404, message: "No movies in the database.", }); diff --git a/api/src/controllers/shows/series.ts b/api/src/controllers/shows/series.ts index e3d1dbb6..e1a63c82 100644 --- a/api/src/controllers/shows/series.ts +++ b/api/src/controllers/shows/series.ts @@ -31,7 +31,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] }) headers: { "accept-language": languages }, query: { preferOriginal, with: relations }, jwt: { sub, settings }, - error, + status, set, }) => { const langs = processLanguages(languages); @@ -48,13 +48,13 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] }) userId: sub, }); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No serie found with the id or slug: '${id}'.`, }); } if (!ret.language) { - return error(422, { + return status(422, { status: 422, message: "Accept-Language header could not be satisfied.", }); @@ -102,7 +102,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] }) ) .get( "random", - async ({ error, redirect }) => { + async ({ status, redirect }) => { const [serie] = await db .select({ slug: shows.slug }) .from(shows) @@ -110,7 +110,7 @@ export const series = new Elysia({ prefix: "/series", tags: ["series"] }) .orderBy(sql`random()`) .limit(1); if (!serie) - return error(404, { + return status(404, { status: 404, message: "No series in the database.", }); diff --git a/api/src/controllers/shows/shows.ts b/api/src/controllers/shows/shows.ts index 85002465..c100bc6a 100644 --- a/api/src/controllers/shows/shows.ts +++ b/api/src/controllers/shows/shows.ts @@ -23,14 +23,14 @@ export const showsH = new Elysia({ prefix: "/shows", tags: ["shows"] }) .use(auth) .get( "random", - async ({ error, redirect }) => { + async ({ status, redirect }) => { const [show] = await db .select({ kind: shows.kind, slug: shows.slug }) .from(shows) .orderBy(sql`random()`) .limit(1); if (!show) - return error(404, { + return status(404, { status: 404, message: "No shows in the database.", }); diff --git a/api/src/controllers/staff.ts b/api/src/controllers/staff.ts index 3ee9321a..ee8266aa 100644 --- a/api/src/controllers/staff.ts +++ b/api/src/controllers/staff.ts @@ -120,14 +120,14 @@ export const staffH = new Elysia({ tags: ["staff"] }) .use(auth) .get( "/staff/:id", - async ({ params: { id }, error }) => { + async ({ params: { id }, status }) => { const [ret] = await db .select() .from(staff) .where(isUuid(id) ? eq(staff.id, id) : eq(staff.slug, id)) .limit(1); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No staff found with the id or slug: '${id}'`, }); @@ -155,14 +155,14 @@ export const staffH = new Elysia({ tags: ["staff"] }) ) .get( "/staff/random", - async ({ error, redirect }) => { + async ({ status, redirect }) => { const [member] = await db .select({ slug: staff.slug }) .from(staff) .orderBy(sql`random()`) .limit(1); if (!member) - return error(404, { + return status(404, { status: 404, message: "No staff in the database.", }); @@ -192,7 +192,7 @@ export const staffH = new Elysia({ tags: ["staff"] }) headers: { "accept-language": languages }, request: { url }, jwt: { sub, settings }, - error, + status, }) => { const [member] = await db .select({ pk: staff.pk }) @@ -201,7 +201,7 @@ export const staffH = new Elysia({ tags: ["staff"] }) .limit(1); if (!member) { - return error(404, { + return status(404, { status: 404, message: `No staff member with the id or slug: '${id}'.`, }); @@ -363,7 +363,7 @@ export const staffH = new Elysia({ tags: ["staff"] }) params: { id }, query: { limit, after, query, sort, filter }, request: { url }, - error, + status, }) => { const [movie] = await db .select({ pk: shows.pk }) @@ -377,7 +377,7 @@ export const staffH = new Elysia({ tags: ["staff"] }) .limit(1); if (!movie) { - return error(404, { + return status(404, { status: 404, message: `No movie with the id or slug: '${id}'.`, }); @@ -430,7 +430,7 @@ export const staffH = new Elysia({ tags: ["staff"] }) params: { id }, query: { limit, after, query, sort, filter }, request: { url }, - error, + status, }) => { const [serie] = await db .select({ pk: shows.pk }) @@ -444,7 +444,7 @@ export const staffH = new Elysia({ tags: ["staff"] }) .limit(1); if (!serie) { - return error(404, { + return status(404, { status: 404, message: `No serie with the id or slug: '${id}'.`, }); diff --git a/api/src/controllers/studios.ts b/api/src/controllers/studios.ts index 373df884..09fd4f84 100644 --- a/api/src/controllers/studios.ts +++ b/api/src/controllers/studios.ts @@ -135,7 +135,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) params: { id }, headers: { "accept-language": languages }, query: { with: relations }, - error, + status, set, }) => { const langs = processLanguages(languages); @@ -147,13 +147,13 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) relations, }); if (!ret) { - return error(404, { + return status(404, { status: 404, message: `No studio found with the id or slug: '${id}'`, }); } if (!ret.language) { - return error(422, { + return status(422, { status: 422, message: "Accept-Language header could not be satisfied.", }); @@ -195,14 +195,14 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) ) .get( "random", - async ({ error, redirect }) => { + async ({ status, redirect }) => { const [studio] = await db .select({ slug: studios.slug }) .from(studios) .orderBy(sql`random()`) .limit(1); if (!studio) - return error(404, { + return status(404, { status: 404, message: "No studios in the database.", }); @@ -305,7 +305,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) headers: { "accept-language": languages }, jwt: { sub, settings }, request: { url }, - error, + status, }) => { const [studio] = await db .select({ pk: studios.pk }) @@ -314,7 +314,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) .limit(1); if (!studio) { - return error(404, { + return status(404, { status: 404, message: `No studios with the id or slug: '${id}'.`, }); @@ -366,7 +366,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) headers: { "accept-language": languages }, jwt: { sub, settings }, request: { url }, - error, + status, }) => { const [studio] = await db .select({ pk: studios.pk }) @@ -375,7 +375,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) .limit(1); if (!studio) { - return error(404, { + return status(404, { status: 404, message: `No studios with the id or slug: '${id}'.`, }); @@ -428,7 +428,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) headers: { "accept-language": languages }, jwt: { sub, settings }, request: { url }, - error, + status, }) => { const [studio] = await db .select({ pk: studios.pk }) @@ -437,7 +437,7 @@ export const studiosH = new Elysia({ prefix: "/studios", tags: ["studios"] }) .limit(1); if (!studio) { - return error(404, { + return status(404, { status: 404, message: `No studios with the id or slug: '${id}'.`, }); diff --git a/api/src/controllers/videos.ts b/api/src/controllers/videos.ts index 0fe22fc5..ecba48ed 100644 --- a/api/src/controllers/videos.ts +++ b/api/src/controllers/videos.ts @@ -1,5 +1,4 @@ -import { and, eq, exists, inArray, not, notExists, or, sql } from "drizzle-orm"; -import { alias } from "drizzle-orm/pg-core"; +import { and, eq, notExists, or, sql } from "drizzle-orm"; import { Elysia, t } from "elysia"; import { db } from "~/db"; import { entries, entryVideoJoin, shows, videos } from "~/db/schema"; @@ -60,7 +59,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] }) }) .from(videos) .leftJoin( - sql`jsonb_array_elements_text(${videos.guess}->'year') as year`, + sql`jsonb_array_elements_text(${videos.guess}->'years') as year`, sql`true`, ) .innerJoin(entryVideoJoin, eq(entryVideoJoin.videoPk, videos.pk)) @@ -169,7 +168,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] }) ) .post( "", - async ({ body, error }) => { + async ({ body, status }) => { return await db.transaction(async (tx) => { let vids: { pk: number; id: string; path: string }[] = []; try { @@ -187,7 +186,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] }) }); } catch (e) { if (!isUniqueConstraint(e)) throw e; - return error(409, { + return status(409, { status: 409, message: comment` Invalid rendering. A video with the same (rendering, part, version) combo @@ -222,7 +221,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] }) }); if (!vidEntries.length) { - return error( + return status( 201, vids.map((x) => ({ id: x.id, path: x.path, entries: [] })), ); @@ -358,7 +357,7 @@ export const videosH = new Elysia({ prefix: "/videos", tags: ["videos"] }) ); await updateAvailableSince(tx, entriesPk); - return error( + return status( 201, vids.map((x) => ({ id: x.id, diff --git a/api/src/models/examples/bubble.ts b/api/src/models/examples/bubble.ts index 573c0cf4..fef87862 100644 --- a/api/src/models/examples/bubble.ts +++ b/api/src/models/examples/bubble.ts @@ -10,7 +10,7 @@ export const bubbleVideo: Video = { guess: { kind: "movie", title: "bubble", - year: [2022], + years: [2022], from: "guessit", }, createdAt: "2024-11-23T15:01:24.968Z", diff --git a/api/src/models/examples/dune-1984.ts b/api/src/models/examples/dune-1984.ts index b417ed7e..e43656d7 100644 --- a/api/src/models/examples/dune-1984.ts +++ b/api/src/models/examples/dune-1984.ts @@ -10,7 +10,7 @@ export const dune1984Video: Video = { guess: { kind: "movie", title: "dune", - year: [1984], + years: [1984], from: "guessit", }, createdAt: "2024-12-02T11:45:12.968Z", diff --git a/api/src/models/examples/dune-2021.ts b/api/src/models/examples/dune-2021.ts index 1c6b9427..6287491d 100644 --- a/api/src/models/examples/dune-2021.ts +++ b/api/src/models/examples/dune-2021.ts @@ -10,7 +10,7 @@ export const duneVideo: Video = { guess: { kind: "movie", title: "dune", - year: [2021], + years: [2021], from: "guessit", }, createdAt: "2024-12-02T10:10:24.968Z", diff --git a/api/src/models/examples/made-in-abyss.ts b/api/src/models/examples/made-in-abyss.ts index 58d1dfcf..886466ac 100644 --- a/api/src/models/examples/made-in-abyss.ts +++ b/api/src/models/examples/made-in-abyss.ts @@ -9,8 +9,7 @@ export const madeInAbyssVideo: Video = { version: 1, guess: { title: "Made in abyss", - season: [1], - episode: [13], + episodes: [{ season: 1, episode: 13 }], kind: "episode", from: "guessit", }, diff --git a/api/tests/helpers/movies-helper.ts b/api/tests/helpers/movies-helper.ts index f0b1711f..e812486c 100644 --- a/api/tests/helpers/movies-helper.ts +++ b/api/tests/helpers/movies-helper.ts @@ -1,5 +1,5 @@ import { buildUrl } from "tests/utils"; -import { app } from "~/base"; +import { handlers } from "~/base"; import type { SeedMovie } from "~/models/movie"; import type { MovieWatchStatus } from "~/models/watchlist"; import { getJwtHeaders } from "./jwt"; @@ -11,7 +11,7 @@ export const getMovie = async ( ...query }: { langs?: string; preferOriginal?: boolean; with?: string[] }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`movies/${id}`, query), { method: "GET", headers: langs @@ -38,7 +38,7 @@ export const getMovies = async ({ langs?: string; preferOriginal?: boolean; }) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("movies", query), { method: "GET", headers: langs @@ -54,7 +54,7 @@ export const getMovies = async ({ }; export const createMovie = async (movie: SeedMovie) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("movies"), { method: "POST", body: JSON.stringify(movie), @@ -72,7 +72,7 @@ export const setMovieStatus = async ( id: string, status: Omit, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`movies/${id}/watchstatus`), { method: "POST", body: JSON.stringify(status), diff --git a/api/tests/helpers/series-helper.ts b/api/tests/helpers/series-helper.ts index 836fce43..090d2a85 100644 --- a/api/tests/helpers/series-helper.ts +++ b/api/tests/helpers/series-helper.ts @@ -1,12 +1,12 @@ import { buildUrl } from "tests/utils"; -import { app } from "~/base"; +import { handlers } from "~/base"; import type { SeedHistory } from "~/models/history"; import type { SeedSerie } from "~/models/serie"; import type { SerieWatchStatus } from "~/models/watchlist"; import { getJwtHeaders } from "./jwt"; export const createSerie = async (serie: SeedSerie) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("series"), { method: "POST", body: JSON.stringify(serie), @@ -27,7 +27,7 @@ export const getSerie = async ( ...query }: { langs?: string; preferOriginal?: boolean; with?: string[] }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`series/${id}`, query), { method: "GET", headers: langs @@ -46,7 +46,7 @@ export const getSeries = async ({ langs, ...query }: { langs?: string; preferOriginal?: boolean; with?: string[] }) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("series", query), { method: "GET", headers: langs @@ -76,7 +76,7 @@ export const getSeasons = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`series/${serie}/seasons`, opts), { method: "GET", headers: langs @@ -106,7 +106,7 @@ export const getEntries = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`series/${serie}/entries`, opts), { method: "GET", headers: langs @@ -131,7 +131,7 @@ export const getExtras = async ( query?: string; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`series/${serie}/extras`, opts), { method: "GET", headers: await getJwtHeaders(), @@ -148,7 +148,7 @@ export const getUnknowns = async (opts: { sort?: string | string[]; query?: string; }) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("unknowns", opts), { method: "GET", headers: await getJwtHeaders(), @@ -169,7 +169,7 @@ export const getNews = async ({ langs?: string; preferOriginal?: boolean; }) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("news", opts), { method: "GET", headers: langs @@ -188,7 +188,7 @@ export const setSerieStatus = async ( id: string, status: Omit, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`series/${id}/watchstatus`), { method: "POST", body: JSON.stringify(status), @@ -216,7 +216,7 @@ export const getHistory = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`profiles/${profile}/history`, opts), { method: "GET", headers: langs @@ -232,7 +232,7 @@ export const getHistory = async ( }; export const addToHistory = async (profile: string, seed: SeedHistory[]) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`profiles/${profile}/history`), { method: "POST", body: JSON.stringify(seed), diff --git a/api/tests/helpers/shows-helper.ts b/api/tests/helpers/shows-helper.ts index 80073a54..9507a92d 100644 --- a/api/tests/helpers/shows-helper.ts +++ b/api/tests/helpers/shows-helper.ts @@ -1,5 +1,5 @@ import { buildUrl } from "tests/utils"; -import { app } from "~/base"; +import { handlers } from "~/base"; import { getJwtHeaders } from "./jwt"; export const getShows = async ({ @@ -14,7 +14,7 @@ export const getShows = async ({ langs?: string; preferOriginal?: boolean; }) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("shows", query), { method: "GET", headers: langs @@ -44,7 +44,7 @@ export const getWatchlist = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`profiles/${id}/watchlist`, query), { method: "GET", headers: langs @@ -74,7 +74,7 @@ export const getNextup = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`profiles/${id}/nextup`, query), { method: "GET", headers: langs diff --git a/api/tests/helpers/staff-helper.ts b/api/tests/helpers/staff-helper.ts index dbb2a613..98378cf1 100644 --- a/api/tests/helpers/staff-helper.ts +++ b/api/tests/helpers/staff-helper.ts @@ -1,9 +1,9 @@ import { buildUrl } from "tests/utils"; -import { app } from "~/base"; +import { handlers } from "~/base"; import { getJwtHeaders } from "./jwt"; export const getStaff = async (id: string, query: {}) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`staff/${id}`, query), { method: "GET", headers: await getJwtHeaders(), @@ -28,7 +28,7 @@ export const getStaffRoles = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`staff/${staff}/roles`, opts), { method: "GET", headers: langs @@ -52,7 +52,7 @@ export const getSerieStaff = async ( sort?: string | string[]; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`series/${serie}/staff`, opts), { method: "GET", headers: await getJwtHeaders(), @@ -71,7 +71,7 @@ export const getMovieStaff = async ( sort?: string | string[]; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`movies/${movie}/staff`, opts), { method: "GET", headers: await getJwtHeaders(), diff --git a/api/tests/helpers/studio-helper.ts b/api/tests/helpers/studio-helper.ts index 0ea8ea21..dfcc64bb 100644 --- a/api/tests/helpers/studio-helper.ts +++ b/api/tests/helpers/studio-helper.ts @@ -1,12 +1,12 @@ import { buildUrl } from "tests/utils"; -import { app } from "~/base"; +import { handlers } from "~/base"; import { getJwtHeaders } from "./jwt"; export const getStudio = async ( id: string, { langs, ...query }: { langs?: string; preferOriginal?: boolean }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`studios/${id}`, query), { method: "GET", headers: langs @@ -36,7 +36,7 @@ export const getShowsByStudio = async ( preferOriginal?: boolean; }, ) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl(`studios/${studio}/shows`, opts), { method: "GET", headers: langs diff --git a/api/tests/helpers/videos-helper.ts b/api/tests/helpers/videos-helper.ts index cc750a1a..de1a6a54 100644 --- a/api/tests/helpers/videos-helper.ts +++ b/api/tests/helpers/videos-helper.ts @@ -1,10 +1,10 @@ import { buildUrl } from "tests/utils"; -import { app } from "~/base"; +import { handlers } from "~/base"; import type { SeedVideo } from "~/models/video"; import { getJwtHeaders } from "./jwt"; export const createVideo = async (video: SeedVideo | SeedVideo[]) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("videos"), { method: "POST", body: JSON.stringify(Array.isArray(video) ? video : [video]), @@ -19,7 +19,7 @@ export const createVideo = async (video: SeedVideo | SeedVideo[]) => { }; export const getVideos = async () => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("videos"), { method: "GET", headers: await getJwtHeaders(), @@ -30,7 +30,7 @@ export const getVideos = async () => { }; export const deleteVideo = async (paths: string[]) => { - const resp = await app.handle( + const resp = await handlers.handle( new Request(buildUrl("videos"), { method: "DELETE", body: JSON.stringify(paths), diff --git a/api/tests/manual.ts b/api/tests/manual.ts index c038486b..98353b76 100644 --- a/api/tests/manual.ts +++ b/api/tests/manual.ts @@ -16,7 +16,11 @@ const [_, ser] = await createSerie(madeInAbyss); const [__, mov] = await createMovie(bubble); const [resp, body] = await createVideo([ { - guess: { title: "mia", season: [1], episode: [13], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 1, episode: 13 }], + from: "test", + }, part: null, path: "/video/mia s1e13.mkv", rendering: "sha2", @@ -26,9 +30,8 @@ const [resp, body] = await createVideo([ { guess: { title: "mia", - season: [2], - episode: [1], - year: [2017], + episodes: [{ season: 2, episode: 1 }], + years: [2017], from: "test", }, part: null, diff --git a/api/tests/movies/get-all-movies-with-null.test.ts b/api/tests/movies/get-all-movies-with-null.test.ts index 2cba7fb6..b595e9c9 100644 --- a/api/tests/movies/get-all-movies-with-null.test.ts +++ b/api/tests/movies/get-all-movies-with-null.test.ts @@ -6,7 +6,7 @@ import { shows } from "~/db/schema"; import { bubble } from "~/models/examples"; import { dune1984 } from "~/models/examples/dune-1984"; import { dune } from "~/models/examples/dune-2021"; -import { app, createMovie, getMovies } from "../helpers"; +import { handlers, createMovie, getMovies } from "../helpers"; beforeAll(async () => { await db.delete(shows); @@ -74,7 +74,7 @@ describe("with a null value", () => { ), }); - resp = await app.handle( + resp = await handlers.handle( new Request(next, { headers: await getJwtHeaders() }), ); body = await resp.json(); @@ -123,7 +123,7 @@ describe("with a null value", () => { ), }); - resp = await app.handle( + resp = await handlers.handle( new Request(next, { headers: await getJwtHeaders() }), ); body = await resp.json(); diff --git a/api/tests/movies/get-all-movies.test.ts b/api/tests/movies/get-all-movies.test.ts index 94fef089..fce1222b 100644 --- a/api/tests/movies/get-all-movies.test.ts +++ b/api/tests/movies/get-all-movies.test.ts @@ -7,7 +7,7 @@ import { bubble } from "~/models/examples"; import { dune1984 } from "~/models/examples/dune-1984"; import { dune } from "~/models/examples/dune-2021"; import type { Movie } from "~/models/movie"; -import { app, createMovie, getMovies } from "../helpers"; +import { handlers, createMovie, getMovies } from "../helpers"; beforeAll(async () => { await db.delete(shows); @@ -72,7 +72,7 @@ describe("Get all movies", () => { }); expectStatus(resp, body).toBe(200); - resp = await app.handle( + resp = await handlers.handle( new Request(body.next, { headers: await getJwtHeaders() }), ); body = await resp.json(); @@ -107,7 +107,7 @@ describe("Get all movies", () => { ), }); - resp = await app.handle( + resp = await handlers.handle( new Request(next, { headers: await getJwtHeaders() }), ); body = await resp.json(); @@ -165,7 +165,7 @@ describe("Get all movies", () => { expect(items.length).toBe(1); expect(items[0].id).toBe(expectedIds[0]); // Get Second Page - resp = await app.handle( + resp = await handlers.handle( new Request(body.next, { headers: await getJwtHeaders() }), ); body = await resp.json(); @@ -182,7 +182,7 @@ describe("Get all movies", () => { }); expectStatus(resp, body).toBe(200); - const resp2 = await app.handle( + const resp2 = await handlers.handle( new Request(body.next, { headers: await getJwtHeaders() }), ); const body2 = await resp2.json(); @@ -195,7 +195,7 @@ describe("Get all movies", () => { }); it("Get /random", async () => { - const resp = await app.handle( + const resp = await handlers.handle( new Request("http://localhost/movies/random", { headers: await getJwtHeaders(), }), diff --git a/api/tests/videos/getdel.test.ts b/api/tests/videos/getdel.test.ts index 9f5b8aea..64a6b78a 100644 --- a/api/tests/videos/getdel.test.ts +++ b/api/tests/videos/getdel.test.ts @@ -23,7 +23,11 @@ beforeAll(async () => { [ret, body] = await createVideo([ { - guess: { title: "mia", season: [1], episode: [13], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 1, episode: 13 }], + from: "test", + }, part: null, path: "/video/mia s1e13.mkv", rendering: "sha2", @@ -33,9 +37,8 @@ beforeAll(async () => { { guess: { title: "mia", - season: [2], - episode: [1], - year: [2017], + episodes: [{ season: 2, episode: 1 }], + years: [2017], from: "test", }, part: null, @@ -103,7 +106,11 @@ describe("Video get/deletion", () => { it("With unknown", async () => { let [resp, body] = await createVideo({ - guess: { title: "mia", season: [1], episode: [13], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 1, episode: 13 }], + from: "test", + }, part: null, path: "/video/mia s1e13 unknown test.mkv", rendering: "shanthnth", @@ -137,7 +144,11 @@ describe("Video get/deletion", () => { it("Mismatch title guess", async () => { let [resp, body] = await createVideo({ - guess: { title: "mia", season: [1], episode: [13], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 1, episode: 13 }], + from: "test", + }, part: null, path: "/video/mia s1e13 mismatch.mkv", rendering: "mismatch", diff --git a/api/tests/videos/scanner.test.ts b/api/tests/videos/scanner.test.ts index 011c2094..0cb4832e 100644 --- a/api/tests/videos/scanner.test.ts +++ b/api/tests/videos/scanner.test.ts @@ -46,7 +46,11 @@ describe("Video seeding", () => { it("With slug", async () => { const [resp, body] = await createVideo({ - guess: { title: "mia", season: [1], episode: [13], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 1, episode: 13 }], + from: "test", + }, part: null, path: "/video/mia s1e13.mkv", rendering: "sha2", @@ -142,7 +146,11 @@ describe("Video seeding", () => { it("With season/episode", async () => { const [resp, body] = await createVideo({ - guess: { title: "mia", season: [2], episode: [1], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 2, episode: 1 }], + from: "test", + }, part: null, path: "/video/mia s2e1.mkv", rendering: "renderingsha", @@ -180,7 +188,11 @@ describe("Video seeding", () => { it("With special", async () => { const [resp, body] = await createVideo({ - guess: { title: "mia", season: [0], episode: [3], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 0, episode: 3 }], + from: "test", + }, part: null, path: "/video/mia sp3.mkv", rendering: "notehu", @@ -217,7 +229,11 @@ describe("Video seeding", () => { it("With order", async () => { const [resp, body] = await createVideo({ - guess: { title: "mia", season: [0], episode: [3], from: "test" }, + guess: { + title: "mia", + episodes: [{ season: 0, episode: 3 }], + from: "test", + }, part: null, path: "/video/mia 13.5.mkv", rendering: "notehu2", @@ -256,8 +272,7 @@ describe("Video seeding", () => { const [resp, body] = await createVideo({ guess: { title: "mia", - season: [0], - episode: [3], + episodes: [{ season: 1, episode: 13 }], from: "test", externalId: { themoviedatabase: { serieId: "72636", season: 1, episode: 13 }, @@ -521,8 +536,10 @@ describe("Video seeding", () => { const [resp, body] = await createVideo({ guess: { title: "mia", - season: [1, 2], - episode: [13, 1], + episodes: [ + { season: 1, episode: 13 }, + { season: 2, episode: 1 }, + ], from: "test", }, part: null,