Merge remote-tracking branch 'origin/main' into feat/adc/search-view-v2
This commit is contained in:
+47
-19
@@ -4,8 +4,8 @@ import Chapter from './models/Chapter';
|
||||
import Lesson from './models/Lesson';
|
||||
import Genre, { GenreHandler } from './models/Genre';
|
||||
import LessonHistory from './models/LessonHistory';
|
||||
import likedSong, { LikedSongHandler } from './models/LikedSong';
|
||||
import Song, { SongHandler } from './models/Song';
|
||||
import { LikedSong, LikedSongHandler } from './models/LikedSong';
|
||||
import Song, { SongHandler, SongInclude } from './models/Song';
|
||||
import { SongHistoryHandler, SongHistoryItem, SongHistoryItemHandler } from './models/SongHistory';
|
||||
import User, { UserHandler } from './models/User';
|
||||
import store from './state/Store';
|
||||
@@ -139,6 +139,7 @@ export default class API {
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
if (!handler.transformer) return handler.validator.cast(validated);
|
||||
return handler.transformer(handler.validator.cast(validated));
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) throw new Error("Error while parsing Server's response");
|
||||
@@ -275,13 +276,14 @@ export default class API {
|
||||
};
|
||||
}
|
||||
|
||||
public static getAllSongs(): Query<Song[]> {
|
||||
public static getAllSongs(include?: SongInclude[]): Query<Song[]> {
|
||||
include ??= [];
|
||||
return {
|
||||
key: 'songs',
|
||||
key: ['songs', include],
|
||||
exec: () =>
|
||||
API.fetch(
|
||||
{
|
||||
route: '/song',
|
||||
route: `/song?include=${include!.join(',')}`,
|
||||
},
|
||||
{
|
||||
handler: PlageHandler(SongHandler),
|
||||
@@ -294,13 +296,14 @@ export default class API {
|
||||
* Retrieve a song
|
||||
* @param songId the id to find the song
|
||||
*/
|
||||
public static getSong(songId: number): Query<Song> {
|
||||
public static getSong(songId: number, include?: SongInclude[]): Query<Song> {
|
||||
include ??= [];
|
||||
return {
|
||||
key: ['song', songId],
|
||||
key: ['song', songId, include],
|
||||
exec: async () =>
|
||||
API.fetch(
|
||||
{
|
||||
route: `/song/${songId}`,
|
||||
route: `/song/${songId}?include=${include!.join(',')}`,
|
||||
},
|
||||
{ handler: SongHandler }
|
||||
),
|
||||
@@ -330,13 +333,15 @@ export default class API {
|
||||
* @param genreId the id of the genre we're aiming
|
||||
* @returns a promise of an array of Songs
|
||||
*/
|
||||
public static getSongsByGenre(genreId: number): Query<Song[]> {
|
||||
public static getSongsByGenre(genreId: number, includes?: SongInclude[]): Query<Song[]> {
|
||||
includes ??= [];
|
||||
|
||||
return {
|
||||
key: ['genre', genreId, 'songs'],
|
||||
key: ['genre', genreId, 'songs', includes],
|
||||
exec: () =>
|
||||
API.fetch(
|
||||
{
|
||||
route: `/song?genreId=${genreId}`,
|
||||
route: `/song?genreId=${genreId}&includes=${includes!.join(',')}`,
|
||||
},
|
||||
{ handler: PlageHandler(SongHandler) }
|
||||
).then(({ data }) => data),
|
||||
@@ -629,21 +634,22 @@ export default class API {
|
||||
* Retrieve the authenticated user's recommendations
|
||||
* @returns an array of songs
|
||||
*/
|
||||
public static getSongSuggestions(): Query<Song[]> {
|
||||
return API.getAllSongs();
|
||||
public static getSongSuggestions(include?: SongInclude[]): Query<Song[]> {
|
||||
return API.getAllSongs(include);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the authenticated user's play history
|
||||
* * @returns an array of songs
|
||||
*/
|
||||
public static getUserPlayHistory(): Query<SongHistoryItem[]> {
|
||||
public static getUserPlayHistory(include?: SongInclude[]): Query<SongHistoryItem[]> {
|
||||
include ??= [];
|
||||
return {
|
||||
key: ['history'],
|
||||
key: ['history', include],
|
||||
exec: () =>
|
||||
API.fetch(
|
||||
{
|
||||
route: '/history',
|
||||
route: `/history?include=${include!.join(',')}`,
|
||||
},
|
||||
{ handler: ListHandler(SongHistoryItemHandler) }
|
||||
),
|
||||
@@ -722,13 +728,14 @@ export default class API {
|
||||
});
|
||||
}
|
||||
|
||||
public static getLikedSongs(): Query<likedSong[]> {
|
||||
public static getLikedSongs(include?: SongInclude[]): Query<LikedSong[]> {
|
||||
include ??= [];
|
||||
return {
|
||||
key: ['liked songs'],
|
||||
key: ['liked songs', include],
|
||||
exec: () =>
|
||||
API.fetch(
|
||||
{
|
||||
route: '/auth/me/likes',
|
||||
route: `/auth/me/likes?include=${include!.join(',')}`,
|
||||
},
|
||||
{ handler: ListHandler(LikedSongHandler) }
|
||||
),
|
||||
@@ -772,4 +779,25 @@ export default class API {
|
||||
public static getPartitionSvgUrl(songId: number): string {
|
||||
return `${API.baseUrl}/song/${songId}/assets/partition`;
|
||||
}
|
||||
|
||||
public static async updateUserTotalScore(score: number): Promise<void> {
|
||||
await API.fetch({
|
||||
route: `/auth/me/score/${score}`,
|
||||
method: 'PATCH',
|
||||
});
|
||||
}
|
||||
|
||||
public static getTopTwentyPlayers(): Query<User[]> {
|
||||
return {
|
||||
key: ['score'],
|
||||
exec: () =>
|
||||
API.fetch(
|
||||
{
|
||||
route: '/scores/top/20',
|
||||
method: 'GET',
|
||||
},
|
||||
{ handler: ListHandler(UserHandler) }
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user