feat: migrate ChKSz API and support API key authentication
This commit is contained in:
+5
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user