handle sanitized sort and filter post-fact

This commit is contained in:
Kendall Garner 2024-09-18 18:00:25 -07:00
parent b628b684ae
commit 6eecc3c0fd
No known key found for this signature in database
GPG key ID: 18D2767419676C87
2 changed files with 35 additions and 6 deletions

View file

@ -229,15 +229,15 @@ export type NDAlbumListParams = {
NDOrder; NDOrder;
export enum NDSongListSort { export enum NDSongListSort {
ALBUM = 'album, order_album_artist_name, disc_number, track_number, title', ALBUM = 'album',
ALBUM_ARTIST = 'order_album_artist_name, album, disc_number, track_number, title', ALBUM_ARTIST = 'order_album_artist_name',
ALBUM_SONGS = 'album, discNumber, trackNumber', ALBUM_SONGS = 'album',
ARTIST = 'artist', ARTIST = 'artist',
BPM = 'bpm', BPM = 'bpm',
CHANNELS = 'channels', CHANNELS = 'channels',
COMMENT = 'comment', COMMENT = 'comment',
DURATION = 'duration', DURATION = 'duration',
FAVORITED = 'starred ASC, starredAt ASC', FAVORITED = 'starred',
GENRE = 'genre', GENRE = 'genre',
ID = 'id', ID = 'id',
PLAY_COUNT = 'playCount', PLAY_COUNT = 'playCount',
@ -247,7 +247,7 @@ export enum NDSongListSort {
RECENTLY_ADDED = 'createdAt', RECENTLY_ADDED = 'createdAt',
TITLE = 'title', TITLE = 'title',
TRACK = 'track', TRACK = 'track',
YEAR = 'year, album, discNumber, trackNumber', YEAR = 'year',
} }
export type NDSongListParams = { export type NDSongListParams = {
@ -261,7 +261,7 @@ export type NDSongListParams = {
export enum NDAlbumArtistListSort { export enum NDAlbumArtistListSort {
ALBUM_COUNT = 'albumCount', ALBUM_COUNT = 'albumCount',
FAVORITED = 'starred ASC, starredAt ASC', FAVORITED = 'starred',
NAME = 'name', NAME = 'name',
PLAY_COUNT = 'playCount', PLAY_COUNT = 'playCount',
RATING = 'rating', RATING = 'rating',

View file

@ -50,6 +50,7 @@ import {
SimilarSongsArgs, SimilarSongsArgs,
Song, Song,
MoveItemArgs, MoveItemArgs,
SongListSort,
} from '../types'; } from '../types';
import { VersionInfo, getFeatures, hasFeature } from '/@/renderer/api/utils'; import { VersionInfo, getFeatures, hasFeature } from '/@/renderer/api/utils';
import { ServerFeature, ServerFeatures } from '/@/renderer/api/features-types'; import { ServerFeature, ServerFeatures } from '/@/renderer/api/features-types';
@ -285,6 +286,34 @@ const getSongList = async (args: SongListArgs): Promise<SongListResponse> => {
throw new Error('Failed to get song list'); throw new Error('Failed to get song list');
} }
if (
(query.sortBy === SongListSort.ALBUM || query.sortBy === SongListSort.ALBUM_ARTIST) &&
!query.limit
) {
const isAlbumArtist = query.sortBy === SongListSort.ALBUM_ARTIST;
res.body.data.sort((a, b) => {
if (isAlbumArtist) {
const albumDiff = a.album.localeCompare(b.album);
if (albumDiff !== 0) {
return albumDiff;
}
}
const discDiff = a.discNumber - b.discNumber;
if (discDiff !== 0) {
return discDiff;
}
const trackDiff = a.trackNumber - b.trackNumber;
if (trackDiff !== 0) {
return trackDiff;
}
return a.title.localeCompare(b.title);
});
}
return { return {
items: res.body.data.map((song) => items: res.body.data.map((song) =>
ndNormalize.song(song, apiClientProps.server, '', query.imageSize), ndNormalize.song(song, apiClientProps.server, '', query.imageSize),