feat: migrate ChKSz API and support API key authentication

This commit is contained in:
Jocay
2026-10-10 20:22:49 +08:00
parent 480233f01b
commit 5bd62645ab
13 changed files with 82 additions and 49 deletions
+5 -5
View File
@@ -1,11 +1,11 @@
const { API } = require('./config');
const { API, buildApiUrl } = require('./config');
const { fetchJSON } = require('./network');
const { formatPersonNames } = require('./utils');
async function searchSongs(keyword, limit = 10) {
const res = await fetchJSON(`${API.search}?keyword=${encodeURIComponent(keyword)}&limit=${limit}`);
const res = await fetchJSON(buildApiUrl(API.search, { keyword, limit }));
if (res.code !== 200) {
console.log('❌ 搜索无结果');
console.log(`❌ 搜索失败: ${res.msg || '无结果'}`);
return [];
}
const songs = Array.isArray(res.data) ? res.data : (res.data?.songs || []);
@@ -40,9 +40,9 @@ async function interactiveSearch(rl, ask) {
}
async function fetchPlaylist(playlistId) {
const res = await fetchJSON(`${API.playlist}?id=${playlistId}`);
const res = await fetchJSON(buildApiUrl(API.playlist, { id: playlistId }));
if (!res.data?.tracks?.length) {
console.log('❌ 歌单获取失败或为空');
console.log(`❌ 歌单获取失败或为空${res.msg ? `: ${res.msg}` : ''}`);
return null;
}
return res.data;