refactor: Less nesting, easier to read
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
23ce666847
commit
0982cb002c
22
lib/nrk.ts
22
lib/nrk.ts
|
|
@ -47,8 +47,7 @@ async function withDownloadLink(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const nrkRadio = {
|
async function search(query: string): Promise<SearchResultList | null> {
|
||||||
search: async (query: string): Promise<SearchResultList | null> => {
|
|
||||||
if (query === "") {
|
if (query === "") {
|
||||||
console.error("Empty search query.");
|
console.error("Empty search query.");
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -62,10 +61,11 @@ export const nrkRadio = {
|
||||||
|
|
||||||
console.error(`Something went wrong with ${query} - got status ${status}`);
|
console.error(`Something went wrong with ${query} - got status ${status}`);
|
||||||
return null;
|
return null;
|
||||||
},
|
}
|
||||||
getSerieData: async (
|
|
||||||
|
async function getSerieData(
|
||||||
seriesId: string,
|
seriesId: string,
|
||||||
): Promise<{ episodes: OriginalEpisode[] } & (RadioSeries["series"] | Podcast["series"]) | null> => {
|
): Promise<{ episodes: OriginalEpisode[] } & (RadioSeries["series"] | Podcast["series"]) | null> {
|
||||||
let [
|
let [
|
||||||
{ status: episodeStatus, body: episodeResponse },
|
{ status: episodeStatus, body: episodeResponse },
|
||||||
{ status: seriesStatus, body: serieResponse },
|
{ status: seriesStatus, body: serieResponse },
|
||||||
|
|
@ -108,8 +108,9 @@ export const nrkRadio = {
|
||||||
`Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`,
|
`Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`,
|
||||||
);
|
);
|
||||||
return null;
|
return null;
|
||||||
},
|
}
|
||||||
getEpisode: async (seriesId: string, episodeId: string): Promise<PodcastEpisode | null> => {
|
|
||||||
|
async function getEpisode(seriesId: string, episodeId: string): Promise<PodcastEpisode | null> {
|
||||||
const url = `${nrkAPI}/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
|
const url = `${nrkAPI}/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
|
||||||
const { status, body: episode } = await get<PodcastEpisode>(url);
|
const { status, body: episode } = await get<PodcastEpisode>(url);
|
||||||
if (status === STATUS_CODE.OK && episode) {
|
if (status === STATUS_CODE.OK && episode) {
|
||||||
|
|
@ -117,5 +118,10 @@ export const nrkRadio = {
|
||||||
}
|
}
|
||||||
console.error(`Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`);
|
console.error(`Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`);
|
||||||
return null;
|
return null;
|
||||||
},
|
}
|
||||||
|
|
||||||
|
export const nrkRadio = {
|
||||||
|
search,
|
||||||
|
getSerieData,
|
||||||
|
getEpisode,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue