fix: 修复请求失败, 适配SPlayer

This commit is contained in:
IamFurina 2025-07-04 19:21:35 +08:00 committed by ImFurina
parent 76d8e662f7
commit fb2eb82a86
2 changed files with 36 additions and 19 deletions

View File

@ -6,52 +6,69 @@ const createOption = require('../util/option.js')
module.exports = async (query, request) => { module.exports = async (query, request) => {
try { try {
const { id, br } = query const { id, br = "320" } = query;
if (!id) { if (!id) {
return { return {
status: 400, status: 400,
body: { body: {
code: 400, code: 400,
msg: 'Missing song ID', message: "缺少必要参数 id",
data: [], data: [],
}, },
} };
} }
const vaildbr = ["128", "192", "320", "740", "999"] const validBR = ["128", "192", "320", "740", "999"];
if (br && !vaildbr.includes(br)) { // const covertBR = ["128000", "192000", "320000","740000", "999000"];
if (!validBR.includes(br)) {
return { return {
status: 400, status: 400,
body: { body: {
code: 400, code: 400,
msg: 'Invalid bitrate', message: "无效音质参数",
allowed_values: validBR,
data: [], data: [],
}, },
} };
} }
const apiUrl = new URL("https://music.gdstudio.xyz/api.php")
const apiUrl = new URL("https://music-api.gdstudio.xyz/api.php");
apiUrl.searchParams.append("types", "url"); apiUrl.searchParams.append("types", "url");
apiUrl.searchParams.append("id", id); apiUrl.searchParams.append("id", id);
apiUrl.searchParams.append("br", br || "320"); apiUrl.searchParams.append("br", br);
const response = await fetch(apiUrl.toString()); const response = await fetch(apiUrl.toString());
if (!response.ok) throw new Error(`API 响应状态: ${response.status}`); if (!response.ok) throw new Error(`API 响应状态: ${response.status}`);
const result = await response.json(); const result = await response.json();
// 代理逻辑
const proxy = process.env.PROXY_URL;
if (proxy && result.url && result.url.includes("kuwo")) {
result.proxyUrl = proxy + result.url.replace(/^http:\/\//, "http/");
}
return { return {
status: 200, status: 200,
body: { body: {
code: 200, code: 200,
msg: 'Success', message: "请求成功",
data: result.data || [], data: {
}, id,
} br,
} catch (err) { url: result.url,
return { ...(proxy && result.proxyUrl ? { proxyUrl: result.proxyUrl } : {})
}
}
};
} catch (error) {
console.error("Error in song_url_ncmget:", error);
return {
status: 500, status: 500,
body: { body: {
code: 500, code: 500,
msg: err.message || 'Internal Server Error', message: "服务器处理请求失败",
...(process.env.NODE_ENV === "development" ? { error: error.message } : {}),
data: [], data: [],
}, },
} };
} }
} }

View File

@ -1570,9 +1570,9 @@ tags: 歌单标签
**必选参数 :** `id` : 音乐 id **必选参数 :** `id` : 音乐 id
**接口地址 :** `/song/url/unblock` **接口地址 :** `/song/url/unblock` 或者 `/song/url/match` (为了适配SPlayer)
**调用例子 :** `/song/url/unblock?id=1969519579` **调用例子 :** `/song/url/unblock?id=1969519579` 或者 `/song/url/match?id=1969519579`
### 搜索 ### 搜索