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