mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 19:01:40 +00:00
actually actually fix album list count for subsonic artists
This commit is contained in:
parent
cd18e683bf
commit
b88671161a
1 changed files with 41 additions and 6 deletions
|
|
@ -1,12 +1,19 @@
|
||||||
|
import type { ServerInferResponses } from '@ts-rest/core';
|
||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import filter from 'lodash/filter';
|
import filter from 'lodash/filter';
|
||||||
import orderBy from 'lodash/orderBy';
|
import orderBy from 'lodash/orderBy';
|
||||||
import md5 from 'md5';
|
import md5 from 'md5';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { ssApiClient } from '/@/renderer/api/subsonic/subsonic-api';
|
import { contract, ssApiClient } from '/@/renderer/api/subsonic/subsonic-api';
|
||||||
import { randomString } from '/@/renderer/utils';
|
import { randomString } from '/@/renderer/utils';
|
||||||
import { ssNormalize } from '/@/shared/api/subsonic/subsonic-normalize';
|
import { ssNormalize } from '/@/shared/api/subsonic/subsonic-normalize';
|
||||||
import { AlbumListSortType, SubsonicExtensions } from '/@/shared/api/subsonic/subsonic-types';
|
import {
|
||||||
|
AlbumListSortType,
|
||||||
|
ssType,
|
||||||
|
SubsonicExtensions,
|
||||||
|
} from '/@/shared/api/subsonic/subsonic-types';
|
||||||
import {
|
import {
|
||||||
AlbumListSort,
|
AlbumListSort,
|
||||||
ControllerEndpoint,
|
ControllerEndpoint,
|
||||||
|
|
@ -287,7 +294,7 @@ export const SubsonicController: ControllerEndpoint = {
|
||||||
let type = ALBUM_LIST_SORT_MAPPING[query.sortBy] ?? AlbumListSortType.ALPHABETICAL_BY_NAME;
|
let type = ALBUM_LIST_SORT_MAPPING[query.sortBy] ?? AlbumListSortType.ALPHABETICAL_BY_NAME;
|
||||||
|
|
||||||
if (query.artistIds) {
|
if (query.artistIds) {
|
||||||
const promises: any[] = [];
|
const promises: Promise<ServerInferResponses<typeof contract.getArtist>>[] = [];
|
||||||
|
|
||||||
for (const artistId of query.artistIds) {
|
for (const artistId of query.artistIds) {
|
||||||
promises.push(
|
promises.push(
|
||||||
|
|
@ -435,6 +442,33 @@ export const SubsonicController: ControllerEndpoint = {
|
||||||
return totalRecordCount;
|
return totalRecordCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query.artistIds) {
|
||||||
|
const promises: Promise<ServerInferResponses<typeof contract.getArtist>>[] = [];
|
||||||
|
|
||||||
|
for (const artistId of query.artistIds) {
|
||||||
|
promises.push(
|
||||||
|
ssApiClient(apiClientProps).getArtist({
|
||||||
|
query: {
|
||||||
|
id: artistId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const artistResult = await Promise.all(promises);
|
||||||
|
|
||||||
|
const albums = artistResult.reduce((total: number, artist) => {
|
||||||
|
if (artist.status !== 200) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const length = artist.body.artist.album?.length ?? 0;
|
||||||
|
return length + total;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return albums;
|
||||||
|
}
|
||||||
|
|
||||||
if (query.favorite) {
|
if (query.favorite) {
|
||||||
const res = await ssApiClient(apiClientProps).getStarred({
|
const res = await ssApiClient(apiClientProps).getStarred({
|
||||||
query: {
|
query: {
|
||||||
|
|
@ -858,9 +892,8 @@ export const SubsonicController: ControllerEndpoint = {
|
||||||
return ssNormalize.song(res.body.song, apiClientProps.server);
|
return ssNormalize.song(res.body.song, apiClientProps.server);
|
||||||
},
|
},
|
||||||
getSongList: async ({ apiClientProps, query }) => {
|
getSongList: async ({ apiClientProps, query }) => {
|
||||||
const fromAlbumPromises: any[] = [];
|
const fromAlbumPromises: Promise<ServerInferResponses<typeof contract.getAlbum>>[] = [];
|
||||||
const artistDetailPromises: any[] = [];
|
const artistDetailPromises: Promise<ServerInferResponses<typeof contract.getArtist>>[] = [];
|
||||||
let results: any[] = [];
|
|
||||||
|
|
||||||
if (query.searchTerm) {
|
if (query.searchTerm) {
|
||||||
const res = await ssApiClient(apiClientProps).search3({
|
const res = await ssApiClient(apiClientProps).search3({
|
||||||
|
|
@ -984,6 +1017,8 @@ export const SubsonicController: ControllerEndpoint = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let results: z.infer<typeof ssType._response.song>[] = [];
|
||||||
|
|
||||||
if (fromAlbumPromises) {
|
if (fromAlbumPromises) {
|
||||||
const albumsResult = await Promise.all(fromAlbumPromises);
|
const albumsResult = await Promise.all(fromAlbumPromises);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue