From f368e1790ead782e7e7b4fb216b07b7395f322d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Thu, 8 Jan 2026 17:02:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor(playlists):=20=E7=A7=BB=E9=99=A4=20Tun?= =?UTF-8?q?ehub=20=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81=E5=B9=B6=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E4=BD=BF=E7=94=A8=E7=BD=91=E6=98=93=E4=BA=91=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除不再使用的 Tunehub 歌单处理逻辑,统一使用网易云音乐 API 获取歌单详情。修改 listSongsFromPlaylist 方法直接调用 getSongsFromPlaylist 接口,简化代码结构并确保版权信息正确。 --- backend/src/handler/playlists.js | 53 ++++++++------------------------ 1 file changed, 13 insertions(+), 40 deletions(-) diff --git a/backend/src/handler/playlists.js b/backend/src/handler/playlists.js index 0b8e018..04a8e09 100644 --- a/backend/src/handler/playlists.js +++ b/backend/src/handler/playlists.js @@ -1,6 +1,5 @@ const logger = require('consola'); -const { getUserAllPlaylist } = require('../service/music_platform/wycloud'); -const { getPlaylistDetail } = require('../service/music_platform/tunehub'); +const { getUserAllPlaylist, getSongsFromPlaylist } = require('../service/music_platform/wycloud'); const Source = require('../consts/source').consts; function splitArtists(artist) { @@ -13,38 +12,6 @@ function splitArtists(artist) { .filter(Boolean); } -function normalizeTunehubPlaylist(playlistId, detail) { - const info = detail && detail.info ? detail.info : {}; - const list = detail && Array.isArray(detail.list) ? detail.list : []; - - const songs = list.map(item => { - const artists = splitArtists(item.artist); - const primaryArtist = artists[0] || item.artist || ''; - const cover = item.pic || info.pic || ''; - const isBlocked = !item.types || item.types.length === 0; - return { - songId: item.id, - songName: item.name || '', - artists, - artist: primaryArtist, - duration: 0, - album: item.album || '', - cover, - pageUrl: `https://music.163.com/song?id=${item.id}`, - playUrl: item.url || '', - isBlocked, - isCloud: false, - }; - }); - - return { - id: playlistId, - name: info.name || '', - cover: info.pic || '', - songs, - }; -} - async function listAllPlaylists(req, res) { const uid = req.account.uid; const playlists = await getUserAllPlaylist(uid); @@ -72,16 +39,22 @@ async function listSongsFromPlaylist(req, res) { }); return; } - const detail = await getPlaylistDetail(source, playlistId); - if (detail === false) { - logger.error(`get playlist detail failed, uid: ${uid}`); + + // 使用网易云 API 获取歌单详情(包含正确的版权信息) + const playlist = await getSongsFromPlaylist(uid, source, playlistId); + if (playlist === false) { + logger.error(`get playlist detail failed, uid: ${uid}, playlistId: ${playlistId}`); + res.send({ + status: 1, + message: "获取歌单详情失败", + }); + return; } - const playlists = detail ? normalizeTunehubPlaylist(playlistId, detail) : false; res.send({ - status: playlists ? 0 : 1, + status: 0, data: { - playlists: playlists ? playlists : [], + playlists: playlist, } }); }