Make client param on SS/ND queries consistent

This commit is contained in:
jeffvli 2024-12-19 17:15:07 -08:00
parent be0ebac362
commit ca58551b94
3 changed files with 20 additions and 23 deletions

View file

@ -41,7 +41,7 @@ const getCoverArtUrl = (args: {
`?id=${args.coverArtId}` +
`&${args.credential}` +
'&v=1.13.0' +
'&c=feishin' +
'&c=Feishin' +
`&size=${size}`
);
};
@ -57,7 +57,6 @@ const normalizePlayDate = (item: WithDate): string | null => {
const normalizeSong = (
item: z.infer<typeof ndType._response.song> | z.infer<typeof ndType._response.playlistSong>,
server: ServerListItem | null,
deviceId: string,
imageSize?: number,
): Song => {
let id;
@ -127,7 +126,7 @@ const normalizeSong = (
serverId: server?.id || 'unknown',
serverType: ServerType.NAVIDROME,
size: item.size,
streamUrl: `${server?.url}/rest/stream.view?id=${id}&v=1.13.0&c=feishin_${deviceId}&${server?.credential}`,
streamUrl: `${server?.url}/rest/stream.view?id=${id}&v=1.13.0&c=Feishin&${server?.credential}`,
trackNumber: item.trackNumber,
uniqueId: nanoid(),
updatedAt: item.updatedAt,
@ -191,7 +190,7 @@ const normalizeAlbum = (
serverType: ServerType.NAVIDROME,
size: item.size,
songCount: item.songCount,
songs: item.songs ? item.songs.map((song) => normalizeSong(song, server, '')) : undefined,
songs: item.songs ? item.songs.map((song) => normalizeSong(song, server)) : undefined,
uniqueId: nanoid(),
updatedAt: item.updatedAt,
userFavorite: item.starred,

View file

@ -73,6 +73,7 @@ export const SubsonicController: ControllerEndpoint = {
} else {
const salt = randomString(12);
const hash = md5(body.password + salt);
credential = `u=${encodeURIComponent(body.username)}&s=${encodeURIComponent(salt)}&t=${encodeURIComponent(hash)}`;
credentialParams = {
s: salt,
@ -522,7 +523,7 @@ export const SubsonicController: ControllerEndpoint = {
`?id=${query.id}` +
`&${apiClientProps.server?.credential}` +
'&v=1.13.0' +
'&c=feishin'
'&c=Feishin'
);
},
getGenreList: async ({ query, apiClientProps }) => {
@ -672,9 +673,8 @@ export const SubsonicController: ControllerEndpoint = {
}
let results =
res.body.playlist.entry?.map((song) =>
ssNormalize.song(song, apiClientProps.server, ''),
) || [];
res.body.playlist.entry?.map((song) => ssNormalize.song(song, apiClientProps.server)) ||
[];
if (query.sortBy && query.sortOrder) {
results = sortSongList(results, query.sortBy, query.sortOrder);
@ -706,7 +706,7 @@ export const SubsonicController: ControllerEndpoint = {
const results = res.body.randomSongs?.song || [];
return {
items: results.map((song) => ssNormalize.song(song, apiClientProps.server, '')),
items: results.map((song) => ssNormalize.song(song, apiClientProps.server)),
startIndex: 0,
totalRecordCount: res.body.randomSongs?.song?.length || 0,
};
@ -765,7 +765,7 @@ export const SubsonicController: ControllerEndpoint = {
return res.body.similarSongs.song.reduce<Song[]>((acc, song) => {
if (song.id !== query.songId) {
acc.push(ssNormalize.song(song, apiClientProps.server, ''));
acc.push(ssNormalize.song(song, apiClientProps.server));
}
return acc;
@ -784,7 +784,7 @@ export const SubsonicController: ControllerEndpoint = {
throw new Error('Failed to get song detail');
}
return ssNormalize.song(res.body.song, apiClientProps.server, '');
return ssNormalize.song(res.body.song, apiClientProps.server);
},
getSongList: async ({ query, apiClientProps }) => {
const fromAlbumPromises = [];
@ -811,7 +811,7 @@ export const SubsonicController: ControllerEndpoint = {
return {
items:
res.body.searchResult3?.song?.map((song) =>
ssNormalize.song(song, apiClientProps.server, ''),
ssNormalize.song(song, apiClientProps.server),
) || [],
startIndex: query.startIndex,
totalRecordCount: null,
@ -835,8 +835,7 @@ export const SubsonicController: ControllerEndpoint = {
const results = res.body.songsByGenre?.song || [];
return {
items:
results.map((song) => ssNormalize.song(song, apiClientProps.server, '')) || [],
items: results.map((song) => ssNormalize.song(song, apiClientProps.server)) || [],
startIndex: 0,
totalRecordCount: null,
};
@ -855,7 +854,7 @@ export const SubsonicController: ControllerEndpoint = {
const results =
(res.body.starred?.song || []).map((song) =>
ssNormalize.song(song, apiClientProps.server, ''),
ssNormalize.song(song, apiClientProps.server),
) || [];
return {
@ -925,7 +924,7 @@ export const SubsonicController: ControllerEndpoint = {
}
return {
items: results.map((song) => ssNormalize.song(song, apiClientProps.server, '')),
items: results.map((song) => ssNormalize.song(song, apiClientProps.server)),
startIndex: 0,
totalRecordCount: results.length,
};
@ -950,7 +949,7 @@ export const SubsonicController: ControllerEndpoint = {
return {
items:
res.body.searchResult3?.song?.map((song) =>
ssNormalize.song(song, apiClientProps.server, ''),
ssNormalize.song(song, apiClientProps.server),
) || [],
startIndex: 0,
totalRecordCount: null,
@ -1183,7 +1182,7 @@ export const SubsonicController: ControllerEndpoint = {
return {
items:
res.body.topSongs?.song?.map((song) =>
ssNormalize.song(song, apiClientProps.server, ''),
ssNormalize.song(song, apiClientProps.server),
) || [],
startIndex: 0,
totalRecordCount: res.body.topSongs?.song?.length || 0,
@ -1258,7 +1257,7 @@ export const SubsonicController: ControllerEndpoint = {
ssNormalize.album(album, apiClientProps.server),
),
songs: (res.body.searchResult3?.song || []).map((song) =>
ssNormalize.song(song, apiClientProps.server, ''),
ssNormalize.song(song, apiClientProps.server),
),
};
},

View file

@ -29,7 +29,7 @@ const getCoverArtUrl = (args: {
`?id=${args.coverArtId}` +
`&${args.credential}` +
'&v=1.13.0' +
'&c=feishin' +
'&c=Feishin' +
`&size=${size}`
);
};
@ -37,7 +37,6 @@ const getCoverArtUrl = (args: {
const normalizeSong = (
item: z.infer<typeof ssType._response.song>,
server: ServerListItem | null,
deviceId: string,
size?: number,
): QueueSong => {
const imageUrl =
@ -48,7 +47,7 @@ const normalizeSong = (
size: size || 300,
}) || null;
const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=feishin_${deviceId}&${server?.credential}`;
const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=Feishin&${server?.credential}`;
return {
album: item.album || '',
@ -215,7 +214,7 @@ const normalizeAlbum = (
songCount: item.songCount,
songs:
(item as z.infer<typeof ssType._response.album>).song?.map((song) =>
normalizeSong(song, server, ''),
normalizeSong(song, server),
) || [],
uniqueId: nanoid(),
updatedAt: item.created,