0f25ebc26d
* plex integration * The big one - Full Music Source page rework + Playlist importing + Full Plex Integration + Discovery Options + More Like This/Surprise Me/Instant Mix + More... * Music source track page - Play all / shuffle fixes * lint * format * fix type checks * format
82 lines
1.8 KiB
TypeScript
82 lines
1.8 KiB
TypeScript
import { get, writable } from 'svelte/store';
|
|
import { API } from '$lib/constants';
|
|
import { api } from '$lib/api/client';
|
|
|
|
interface IntegrationStatus {
|
|
lidarr: boolean;
|
|
jellyfin: boolean;
|
|
navidrome: boolean;
|
|
plex: boolean;
|
|
listenbrainz: boolean;
|
|
youtube: boolean;
|
|
youtube_api: boolean;
|
|
localfiles: boolean;
|
|
lastfm: boolean;
|
|
loaded: boolean;
|
|
}
|
|
|
|
function createIntegrationStore() {
|
|
const { subscribe, set, update } = writable<IntegrationStatus>({
|
|
lidarr: false,
|
|
jellyfin: false,
|
|
navidrome: false,
|
|
plex: false,
|
|
listenbrainz: false,
|
|
youtube: false,
|
|
youtube_api: false,
|
|
localfiles: false,
|
|
lastfm: false,
|
|
loaded: false
|
|
});
|
|
let loadPromise: Promise<void> | null = null;
|
|
|
|
return {
|
|
subscribe,
|
|
setStatus: (status: Partial<IntegrationStatus>) => {
|
|
update((current) => ({ ...current, ...status, loaded: true }));
|
|
},
|
|
setLidarrConfigured: (configured: boolean) => {
|
|
update((current) => ({ ...current, lidarr: configured }));
|
|
},
|
|
reset: () => {
|
|
set({
|
|
lidarr: false,
|
|
jellyfin: false,
|
|
navidrome: false,
|
|
plex: false,
|
|
listenbrainz: false,
|
|
youtube: false,
|
|
youtube_api: false,
|
|
localfiles: false,
|
|
lastfm: false,
|
|
loaded: false
|
|
});
|
|
},
|
|
ensureLoaded: async () => {
|
|
const current = get({ subscribe });
|
|
if (current.loaded) return;
|
|
if (loadPromise) return loadPromise;
|
|
|
|
loadPromise = (async () => {
|
|
try {
|
|
const status = await api.global.get<Partial<IntegrationStatus>>(
|
|
API.homeIntegrationStatus()
|
|
);
|
|
update((state) => ({ ...state, ...status, loaded: true }));
|
|
return;
|
|
} catch {
|
|
// Ignore error
|
|
}
|
|
|
|
update((state) => ({ ...state, loaded: true }));
|
|
})().finally(() => {
|
|
loadPromise = null;
|
|
});
|
|
|
|
return loadPromise;
|
|
}
|
|
};
|
|
}
|
|
|
|
export const integrationStore = createIntegrationStore();
|