Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ class Player {
} else return null;
}
// 返回歌曲地址
// 客户端直接返回,网页端转 https
const url = isElectron ? songData.url : songData.url.replace(/^http:/, "https:");
// 客户端直接返回,网页端转 https, 并转换url以便解决音乐链接cors问题
const url = isElectron ? songData.url : songData.url.replace(/^http:/, "https:").replace(/m804\.music\.126\.net/g, 'm801.music.126.net').replace(/m704\.music\.126\.net/g, 'm701.music.126.net');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接通过字符串替换来解决CORS问题虽然能快速生效,但不够灵活和稳定。建议使用更通用的代理方式或配置CORS策略,以提高代码的健壮性和可维护性。

Suggested change
const url = isElectron ? songData.url : songData.url.replace(/^http:/, "https:").replace(/m804\.music\.126\.net/g, 'm801.music.126.net').replace(/m704\.music\.126\.net/g, 'm701.music.126.net');
// 客户端直接返回,网页端转 https, 并通过代理解决音乐链接cors问题
const url = isElectron
? songData.url
: songData.url
.replace(/^http:/, "https:")
.replace(/m\d+\.music\.126\.net/g, 'proxy.music.126.net'); // 使用更通用的正则表达式和代理域名

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接通过字符串替换来解决CORS问题虽然能快速生效,但不够灵活和稳定。建议使用更通用的代理方式或配置CORS策略,以提高代码的健壮性和可维护性。

Suggested change
const url = isElectron ? songData.url : songData.url.replace(/^http:/, "https:").replace(/m804\.music\.126\.net/g, 'm801.music.126.net').replace(/m704\.music\.126\.net/g, 'm701.music.126.net');
// 客户端直接返回,网页端转 https, 并通过代理解决音乐链接cors问题
const url = isElectron
? songData.url
: songData.url
.replace(/^http:/, "https:")
.replace(/m\d+\.music\.126\.net/g, 'proxy.music.126.net'); // 使用更通用的正则表达式和代理域名

console.log(`🎧 ${id} music url:`, url);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在生产环境中,应避免打印敏感信息(如完整的音乐URL)到控制台,以防止潜在的安全风险。

Suggested change
console.log(`🎧 ${id} music url:`, url);
// 可以考虑仅在开发模式下打印详细日志
if (process.env.NODE_ENV === 'development') {
console.log(`🎧 ${id} music url:`, url);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在生产环境中,应避免打印敏感信息(如完整的音乐URL)到控制台,以防止潜在的安全风险。

Suggested change
console.log(`🎧 ${id} music url:`, url);
// 可以考虑仅在开发模式下打印详细日志
if (process.env.NODE_ENV === 'development') {
console.log(`🎧 ${id} music url:`, url);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处添加的 console.log 会在生产环境中输出调试信息,可能会暴露敏感数据或影响性能。

Suggested change
console.log(`🎧 ${id} music url:`, url);
// 🎧 ${id} music url: ${url}

return url;
}
/**
Expand Down