Files
App/api/queries/functions/api.ts
Violet Caulfield 79bdb83a5c fix?
2024-10-20 10:23:13 -05:00

26 lines
840 B
TypeScript

import { Api } from "@jellyfin/sdk";
import { fetchCredentials } from "./storage";
import { client } from "../../client";
import _ from "lodash";
/**
* A promise to build an authenticated Jellyfin API client
* @returns A Promise of the authenticated Jellyfin API client or a rejection
*/
export const createApi: () => Promise<Api> = async () => {
return fetchCredentials()
.then(credentials => {
if (!_.isUndefined(credentials))
throw new Error("No credentials exist for the current user")
return client.createApi(credentials!.server, credentials!.password);
}).catch((rejection) => {
return Promise.reject(rejection)
})
}
export const createPublicApi: (serverUrl: string) => Api = (serverUrl) => {
return client.createApi(serverUrl);
}