Mirror of static site repo git.pfy.ch/pfych/static
Something went wrong. Try again.
12345678910111213141516171819202122232425262728import { err, ok, Result } from 'neverthrow';import { PlexNowListening } from 'web-shared/src/types/plex';import { ErrorWithCode, PlexErrors } from 'web-shared/src/types/errors';import { apiUrl } from 'web-shared/src/lib/api';import { safeFetch } from 'web-shared/src/lib/fetch';
export const getNowListening = async (): Promise< Result<PlexNowListening | undefined, ErrorWithCode<PlexErrors>>> => { const response = await safeFetch< { nowPlaying: PlexNowListening[] }, PlexErrors >(`${apiUrl}/plex/listening`, { method: 'GET', });
if (response.isErr()) { return err(response.error); }
const allSessions = response.value; return ok( allSessions.nowPlaying.find( (session) => session.user === 'pfych' && session.state === 'playing', ), );};