fix(Subsonic API): 修复数组参数处理和播放列表更新日志
改进Subsonic API请求中数组参数的处理方式,避免空值 添加播放列表更新时的日志输出
This commit is contained in:
@@ -131,9 +131,19 @@ async function getSubsonicUrl(endpoint, params = {}) {
|
||||
...params
|
||||
};
|
||||
|
||||
const queryString = Object.entries(authParams)
|
||||
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
||||
.join('&');
|
||||
const queryParts = [];
|
||||
for (const [key, value] of Object.entries(authParams)) {
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
if (item !== undefined && item !== null && item !== '') {
|
||||
queryParts.push(`${key}=${encodeURIComponent(item)}`);
|
||||
}
|
||||
}
|
||||
} else if (value !== undefined && value !== null && value !== '') {
|
||||
queryParts.push(`${key}=${encodeURIComponent(value)}`);
|
||||
}
|
||||
}
|
||||
const queryString = queryParts.join('&');
|
||||
|
||||
return `${NAVIDROME_URL}/rest/${endpoint}?${queryString}`;
|
||||
}
|
||||
@@ -517,7 +527,7 @@ async function createNavidromePlaylist(name, songIds = []) {
|
||||
try {
|
||||
const result = await callSubsonicAPI('createPlaylist', {
|
||||
name: name,
|
||||
songId: songIds.join(',')
|
||||
songId: songIds
|
||||
});
|
||||
return result.playlist?.id;
|
||||
} catch (error) {
|
||||
@@ -528,9 +538,10 @@ async function createNavidromePlaylist(name, songIds = []) {
|
||||
|
||||
async function updateNavidromePlaylist(playlistId, songIdsToAdd) {
|
||||
try {
|
||||
console.log(`[Sync] Updating Navidrome playlist ${playlistId} with ${songIdsToAdd.length} songs`);
|
||||
await callSubsonicAPI('updatePlaylist', {
|
||||
playlistId: playlistId,
|
||||
songIdToAdd: songIdsToAdd.join(',')
|
||||
songIdToAdd: songIdsToAdd
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Update playlist error:', error.message);
|
||||
|
||||
Reference in New Issue
Block a user