mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat: add top tracks report
This commit is contained in:
parent
60dc25f15e
commit
51fd78f6d9
11 changed files with 230 additions and 0 deletions
|
|
@ -9,6 +9,8 @@ import { TopAlbumsItem } from "./entities/top-albums-item";
|
|||
import { TopAlbumsOptions } from "./entities/top-albums-options";
|
||||
import { TopArtistsItem } from "./entities/top-artists-item";
|
||||
import { TopArtistsOptions } from "./entities/top-artists-options";
|
||||
import { TopTracksItem } from "./entities/top-tracks-item";
|
||||
import { TopTracksOptions } from "./entities/top-tracks-options";
|
||||
|
||||
export class UnauthenticatedError extends Error {}
|
||||
|
||||
|
|
@ -149,3 +151,40 @@ export const getTopAlbums = async (
|
|||
} = res;
|
||||
return items;
|
||||
};
|
||||
|
||||
export const getTopTracks = async (
|
||||
options: TopTracksOptions,
|
||||
client: AxiosInstance
|
||||
): Promise<TopTracksItem[]> => {
|
||||
const {
|
||||
time: { timePreset, customTimeStart, customTimeEnd },
|
||||
} = options;
|
||||
|
||||
const res = await client.get<{ items: TopTracksItem[] }>(
|
||||
`/api/v1/reports/top-tracks`,
|
||||
{
|
||||
params: {
|
||||
timePreset,
|
||||
customTimeStart: formatISO(customTimeStart),
|
||||
customTimeEnd: formatISO(customTimeEnd),
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
switch (res.status) {
|
||||
case 200: {
|
||||
break;
|
||||
}
|
||||
case 401: {
|
||||
throw new UnauthenticatedError(`No token or token expired`);
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unable to getTopTracks: ${res.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
data: { items },
|
||||
} = res;
|
||||
return items;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue