mirror of
https://github.com/Jellify-Music/App.git
synced 2026-05-04 18:00:05 -05:00
lots of backend changes to slim up the app provider and to beef up the login provider
This commit is contained in:
@@ -2,21 +2,32 @@ import { Api } from "@jellyfin/sdk";
|
||||
import { fetchCredentials } from "./storage";
|
||||
import { client } from "../../client";
|
||||
import _ from "lodash";
|
||||
import { QueryFunctionContext, QueryKey } from "@tanstack/react-query";
|
||||
|
||||
/**
|
||||
* 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> = () => new Promise(async (resolve, reject) => {
|
||||
let credentials = await fetchCredentials();
|
||||
export function createApi(): Promise<Api> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let credentials = await fetchCredentials();
|
||||
|
||||
if (_.isUndefined(credentials))
|
||||
reject("No credentials exist for the current user")
|
||||
|
||||
console.log("Signing into Jellyfin")
|
||||
resolve(client.createApi(credentials!.server, credentials!.password));
|
||||
});
|
||||
if (_.isUndefined(credentials)) {
|
||||
console.warn("No credentials exist for user, launching login flow");
|
||||
return reject("No credentials exist for the current user");
|
||||
}
|
||||
|
||||
console.log("Signing into Jellyfin")
|
||||
return resolve(client.createApi(credentials!.server, credentials!.password));
|
||||
});
|
||||
}
|
||||
|
||||
export const createPublicApi: (serverUrl: string) => Api = (serverUrl) => {
|
||||
return client.createApi(serverUrl);
|
||||
export function createPublicApi({ queryKey }: QueryFunctionContext): Promise<Api> {
|
||||
return new Promise((resolve) => {
|
||||
|
||||
///@ts-ignore
|
||||
const [_key, { serverUrl } ] = queryKey;
|
||||
|
||||
resolve(client.createApi(serverUrl));
|
||||
});
|
||||
}
|
||||
@@ -4,20 +4,21 @@ import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import _ from "lodash";
|
||||
|
||||
|
||||
export const fetchMusicLibraries : (api: Api) => Promise<BaseItemDto[]> = (api: Api) => new Promise( async (resolve) => {
|
||||
export function fetchMusicLibraries(api: Api): Promise<BaseItemDto[]> {
|
||||
return new Promise( async (resolve) => {
|
||||
console.log("Fetching music libraries from Jellyfin");
|
||||
|
||||
let libraries = await getItemsApi(api).getItems();
|
||||
|
||||
console.log("Fetching music libraries from Jellyfin");
|
||||
|
||||
let libraries = await getItemsApi(api).getItems();
|
||||
if (_.isUndefined(libraries.data.Items)) {
|
||||
console.log("No libraries found on Jellyfin");
|
||||
return Promise.reject("No libraries found on Jellyfin");
|
||||
}
|
||||
|
||||
if (_.isUndefined(libraries.data.Items)) {
|
||||
console.log("No libraries found on Jellyfin");
|
||||
return Promise.reject("No libraries found on Jellyfin");
|
||||
}
|
||||
let musicLibraries = libraries.data.Items!.filter(library => library.CollectionType == 'music');
|
||||
|
||||
let musicLibraries = libraries.data.Items!.filter(library => library.CollectionType == 'music');
|
||||
|
||||
console.log(`Found ${musicLibraries.length} music libraries`);
|
||||
|
||||
resolve(musicLibraries);
|
||||
});
|
||||
console.log(`Found ${musicLibraries.length} music libraries`);
|
||||
|
||||
resolve(musicLibraries);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user