diff --git a/index.ts b/index.ts index b5e0841..b7388d3 100644 --- a/index.ts +++ b/index.ts @@ -1,26 +1,21 @@ import { ExtendedClient } from "./server/structures/client" -export const client = new ExtendedClient() - -import { AuthenticateUserByNameRequest, CreateUserByNameRequest } from "./jellyfin/api" -import { UserApi } from "./jellyfin/api/userApi" +import { JellyfinHandler } from "./jellyfin/handler" import { config } from "./server/configuration" -client.start() +import { logger } from "./server/logger" +const requestId = 'startup' -async function start() { - const jfUserAPI: UserApi = new UserApi(config.jellyfin_url) - const options = { - headers: { - "X-MediaBrowser-Token": config.jellfin_token - } +const jellyfinHandler = new JellyfinHandler(config) + +export const client = new ExtendedClient(jellyfinHandler) + +async function init() { + try { + const users = await jellyfinHandler.getCurrentUsers("", requestId) + logger.info(`Fetched ${users.map(x => x.name).join(', ')} from JF`, { requestId }) + } catch (error) { + logger.error(`Error fetching existing users from Jellyfin`, { requestId }) } - let u = (await jfUserAPI.getUsers(false, false, options)).body - console.log(JSON.stringify(u.map(x => x.name), null, 2)) - const user: CreateUserByNameRequest = { - name: "Testuser1", - password: "1234" - } - const a = await jfUserAPI.createUserByName(user, options) - console.log(JSON.stringify(a, null, 2)) - u = (await jfUserAPI.getUsers(undefined, undefined, options)).body - console.log(JSON.stringify(u.map(x => x.name), null, 2)) + logger.info(`Starting client`, { requestId }) + client.start() } +init()