Files
tunarr/server/src/api/debug/debugJellyfinApi.ts
Christian Benincasa f52df44ef0 feat!: add support for Jellyfin media (#633)
This commit includes a huge amount of changes, including support for
adding Jellyfin servers as media sources and streaming content from
them.

These are breaking changes and touch almost every corner of the code,
but also pave the way for a lot more flexibility on the backend for
addinng different sources.

The commit also includes performance improvements to the inline modal,
lots of code cleanup, and a few bug fixes I found along the way.

Fixes #24
2024-08-22 07:41:33 -04:00

66 lines
1.8 KiB
TypeScript

import { isNil } from 'lodash-es';
import { JellyfinApiClient } from '../../external/jellyfin/JellyfinApiClient';
import { RouterPluginAsyncCallback } from '../../types/serverType';
import { z } from 'zod';
import { Nilable } from '../../types/util';
export const DebugJellyfinApiRouter: RouterPluginAsyncCallback = async (
fastify,
// eslint-disable-next-line @typescript-eslint/require-await
) => {
fastify.get(
'/jellyfin/libraries',
{
schema: {
querystring: z.object({
userId: z.string(),
uri: z.string().url(),
apiKey: z.string(),
}),
},
},
async (req, res) => {
const client = new JellyfinApiClient({
url: req.query.uri,
apiKey: req.query.apiKey,
});
await res.send(await client.getUserLibraries(req.query.userId));
},
);
fastify.get(
'/jellyfin/library/items',
{
schema: {
querystring: z
.object({
uri: z.string().url(),
parentId: z.string().nullable().optional(),
offset: z.coerce.number().nonnegative().optional(),
limit: z.coerce.number().positive().optional(),
apiKey: z.string(),
})
.refine(({ offset, limit }) => {
return isNil(offset) === isNil(limit);
}, 'offset/limit must either both be defined, or neither'),
},
},
async (req, res) => {
const client = new JellyfinApiClient({
url: req.query.uri,
apiKey: req.query.apiKey,
});
let pageParams: Nilable<{ offset: number; limit: number }> = null;
if (!isNil(req.query.limit) && !isNil(req.query.offset)) {
pageParams = { offset: req.query.offset, limit: req.query.limit };
}
await res.send(
await client.getItems(null, req.query.parentId, [], [], pageParams),
);
},
);
};