chore: fix typescript with optional return from api call
This commit is contained in:
@@ -18,7 +18,7 @@ const albumParams = new URLSearchParams(albumOptions).toString();
|
||||
*/
|
||||
export async function retrieveAllAlbums() {
|
||||
return fetchApi<{ Items: Album[] }>(({ user_id }) => `/Users/${user_id}/Items?${albumParams}`)
|
||||
.then((data) => data.Items);
|
||||
.then((data) => data!.Items);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,10 +26,10 @@ export async function retrieveAllAlbums() {
|
||||
*/
|
||||
export async function retrieveAlbum(id: string): Promise<Album> {
|
||||
const Similar = await fetchApi<{ Items: SimilarAlbum[] }>(({ user_id }) => `/Items/${id}/Similar?userId=${user_id}&limit=12`)
|
||||
.then((albums) => albums.Items.map((a) => a.Id));
|
||||
.then((albums) => albums!.Items.map((a) => a.Id));
|
||||
|
||||
return fetchApi<Album>(({ user_id }) => `/Users/${user_id}/Items/${id}`)
|
||||
.then(album => ({ ...album, Similar }));
|
||||
.then(album => ({ ...album!, Similar }));
|
||||
}
|
||||
|
||||
const latestAlbumsOptions = {
|
||||
@@ -64,5 +64,5 @@ export async function retrieveAlbumTracks(ItemId: string) {
|
||||
const singleAlbumParams = new URLSearchParams(singleAlbumOptions).toString();
|
||||
|
||||
return fetchApi<{ Items: AlbumTrack[] }>(({ user_id }) => `/Users/${user_id}/Items?${singleAlbumParams}`)
|
||||
.then((data) => data.Items);
|
||||
.then((data) => data!.Items);
|
||||
}
|
||||
@@ -52,8 +52,9 @@ export async function fetchApi<T>(
|
||||
// Actually perform the request
|
||||
const response = await fetch(url, config);
|
||||
|
||||
if (__DEV__) {
|
||||
console.log(`[HTTP][${response.status}]`, url, config);
|
||||
if (__DEV__) {
|
||||
console.log(`%c[HTTP] → [${response.status}] ${url}`, 'font-weight:bold;');
|
||||
console.log('\t', config);
|
||||
}
|
||||
|
||||
// GUARD: Check if the response is as expected
|
||||
@@ -88,7 +89,8 @@ export async function fetchApi<T>(
|
||||
*/
|
||||
export function getImage(ItemId: string): string {
|
||||
const credentials = asyncFetchStore().getState().settings.jellyfin;
|
||||
return encodeURI(`${credentials?.uri}/Items/${ItemId}/Images/Primary?format=jpeg`);
|
||||
const uri = encodeURI(`${credentials?.uri}/Items/${ItemId}/Images/Primary?format=jpeg`);
|
||||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function retrieveAllPlaylists() {
|
||||
const playlistParams = new URLSearchParams(playlistOptions).toString();
|
||||
|
||||
return fetchApi<{ Items: Playlist[] }>(({ user_id }) => `/Users/${user_id}/Items?${playlistParams}`)
|
||||
.then((d) => d.Items);
|
||||
.then((d) => d!.Items);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,5 +34,5 @@ export async function retrievePlaylistTracks(ItemId: string) {
|
||||
const singlePlaylistParams = new URLSearchParams(singlePlaylistOptions).toString();
|
||||
|
||||
return fetchApi<{ Items: AlbumTrack[] }>(`/Playlists/${ItemId}/Items?${singlePlaylistParams}`)
|
||||
.then((d) => d.Items);
|
||||
.then((d) => d!.Items);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export async function searchItem(
|
||||
|
||||
const results = await fetchApi<{ Items: (Album | AlbumTrack)[]}>(({ user_id }) => `/Users/${user_id}/Items?${params}`);
|
||||
|
||||
return results.Items
|
||||
return results!.Items
|
||||
.filter((item) => (
|
||||
// GUARD: Ensure that we're either dealing with an album or a track from an album.
|
||||
item.Type === 'MusicAlbum' || (item.Type === 'Audio' && item.AlbumId)
|
||||
|
||||
@@ -77,5 +77,5 @@ const trackParams = {
|
||||
*/
|
||||
export async function retrieveAllTracks() {
|
||||
return fetchApi<{ Items: AlbumTrack[] }>(({ user_id }) => `/Users/${user_id}/Items?${trackParams}`)
|
||||
.then((d) => d.Items);
|
||||
.then((d) => d!.Items);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user