From 916a595a63590e80b93f471a18de0cffa1b64ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Thu, 8 Jan 2026 15:24:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E9=9F=B3=E4=B9=90=E5=90=8C=E6=AD=A5):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=AD=8C=E6=9B=B2=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E4=BC=98=E5=85=88=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=9A=84songId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当songId存在时,跳过冗余的网易云匹配流程,直接使用songId进行精确匹配 如果精确匹配失败,再回退到基于名称的匹配方式 --- backend/src/handler/sync_jobs.js | 24 ++++------ .../sync_music/sync_single_song_with_url.js | 48 ++++++++++++++----- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/backend/src/handler/sync_jobs.js b/backend/src/handler/sync_jobs.js index e4c3b3d..41637fc 100644 --- a/backend/src/handler/sync_jobs.js +++ b/backend/src/handler/sync_jobs.js @@ -93,21 +93,15 @@ async function createJob(req, res) { } if (songId) { - const songFromWyCloud = await findTheBestMatchFromWyCloud(req.account.uid, { - songName: meta.songName, - artist: meta.artist, - album: meta.album, - musicPlatformSongId: songId, - }); - if (!songFromWyCloud) { - logger.error(`song not found in wycloud`); - res.status(412).send({ - status: 1, - message: "can not find song in wycloud with your songId", - }); - return; - } - meta.songFromWyCloud = songFromWyCloud; + // 直接传递songId给后续处理,避免冗余的网易云匹配 + // 如果后续需要,可以根据songId进行精确匹配 + meta.songFromWyCloud = { + songId: songId, + songName: meta.songName || "", + artist: meta.artist || "", + album: meta.album || "", + }; + logger.info(`[sync_jobs] Using provided songId: ${songId}, will handle matching later if needed`); } // create job diff --git a/backend/src/service/sync_music/sync_single_song_with_url.js b/backend/src/service/sync_music/sync_single_song_with_url.js index 90c2d42..77ca2a7 100644 --- a/backend/src/service/sync_music/sync_single_song_with_url.js +++ b/backend/src/service/sync_music/sync_single_song_with_url.js @@ -154,10 +154,29 @@ module.exports = async function syncSingleSongWithUrl(uid, url, { await updateJobIfNeed(uid, jobId, songInfo, jobType); // step 2. find the best match from wycloud - if (songFromWyCloud === null) { + if (songFromWyCloud && songFromWyCloud.songId) { + // 如果已经提供了songId,优先使用它进行精确匹配 + logger.info(`[syncSingleSongWithUrl] Using provided songId: ${songFromWyCloud.songId}`); + try { + const wySongInfo = await getWySongInfo(uid, songFromWyCloud.songId); + if (wySongInfo) { + songFromWyCloud = buildSongInfoFromWyCloud(wySongInfo); + logger.info(`[syncSingleSongWithUrl] Found exact match via songId: ${wySongInfo.songName} - ${wySongInfo.artists?.[0] || 'Unknown'}`); + } else { + logger.warn(`[syncSingleSongWithUrl] songId ${songFromWyCloud.songId} not found in WyCloud, will try name-based matching`); + songFromWyCloud = null; // 回退到基于名称的匹配 + } + } catch (error) { + logger.error(`[syncSingleSongWithUrl] Error matching songId: ${error.message}`); + songFromWyCloud = null; + } + } + + // 如果没有songId或精确匹配失败,进行基于名称的匹配 + if (!songFromWyCloud) { let findSongName, findArtist, findAlbum; if (songName !== "" && artist !== "") { - logger.info(`use the user input song name and artist, ${songName}, ${artist}, ${album}`); + logger.info(`[syncSingleSongWithUrl] use the user input song name and artist, ${songName}, ${artist}, ${album}`); findSongName = songName; findArtist = artist; findAlbum = album; @@ -165,17 +184,24 @@ module.exports = async function syncSingleSongWithUrl(uid, url, { findSongName = songInfo.songName; findArtist = songInfo.artist; findAlbum = songInfo.album; - } - songFromWyCloud = await findTheBestMatchFromWyCloud(uid, { - songName: findSongName, - artist: findArtist, - album: findAlbum, - }); - } else { - logger.info(`use the songFromWyCloud by params`); + } + if (findSongName && findArtist) { + songFromWyCloud = await findTheBestMatchFromWyCloud(uid, { + songName: findSongName, + artist: findArtist, + album: findAlbum, + }); + if (songFromWyCloud) { + logger.info(`[syncSingleSongWithUrl] Found match via name-based search: ${songFromWyCloud.songName}`); + } else { + logger.info(`[syncSingleSongWithUrl] No match found in WyCloud, will upload as new song`); + } + } else { + logger.info(`[syncSingleSongWithUrl] No song info available for matching`); + } } - logger.info('songFromWyCloud:', songFromWyCloud); + logger.info('[syncSingleSongWithUrl] songFromWyCloud:', songFromWyCloud); // step 3. download // should add meta tag if not matched song on wycloud