Skip to content

Commit

Permalink
Make client param on SS/ND queries consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffvli committed Dec 20, 2024
1 parent be0ebac commit ca58551
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
7 changes: 3 additions & 4 deletions src/renderer/api/navidrome/navidrome-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getCoverArtUrl = (args: {
`?id=${args.coverArtId}` +
`&${args.credential}` +
'&v=1.13.0' +
'&c=feishin' +
'&c=Feishin' +
`&size=${size}`
);
};
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
29 changes: 14 additions & 15 deletions src/renderer/api/subsonic/subsonic-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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;
Expand All @@ -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 = [];
Expand All @@ -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,
Expand All @@ -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,
};
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
),
};
},
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/api/subsonic/subsonic-normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ const getCoverArtUrl = (args: {
`?id=${args.coverArtId}` +
`&${args.credential}` +
'&v=1.13.0' +
'&c=feishin' +
'&c=Feishin' +
`&size=${size}`
);
};

const normalizeSong = (
item: z.infer<typeof ssType._response.song>,
server: ServerListItem | null,
deviceId: string,
size?: number,
): QueueSong => {
const imageUrl =
Expand All @@ -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 || '',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ca58551

Please sign in to comment.