修复(服务器):增强文件名清理的健壮性
实施更严格的文件名清理措施,包括Unicode标准化处理(NFC)、控制字符移除以及200字符的长度限制,以防止歌曲下载过程中出现文件系统错误。
This commit is contained in:
@@ -127,9 +127,20 @@ async function tryDownloadSongs(data) {
|
|||||||
|
|
||||||
function processSong(song) {
|
function processSong(song) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
// Basic sanitization
|
// Sanitize filename with proper encoding handling
|
||||||
const safeName = (song.name || 'unknown').replace(/[\\/:*?"<>|]/g, '_');
|
const sanitizeFilename = (str) => {
|
||||||
const safeArtist = (song.artist || 'unknown').replace(/[\\/:*?"<>|]/g, '_');
|
if (!str) return 'unknown';
|
||||||
|
// Normalize Unicode (NFC) to ensure consistent encoding
|
||||||
|
const normalized = str.normalize('NFC');
|
||||||
|
// Replace Windows illegal characters and control characters
|
||||||
|
return normalized
|
||||||
|
.replace(/[\\/:*?"<>|\x00-\x1f\x7f]/g, '_')
|
||||||
|
.trim()
|
||||||
|
.substring(0, 200); // Limit length to avoid path too long errors
|
||||||
|
};
|
||||||
|
|
||||||
|
const safeName = sanitizeFilename(song.name);
|
||||||
|
const safeArtist = sanitizeFilename(song.artist);
|
||||||
const source = song.platform || song.source;
|
const source = song.platform || song.source;
|
||||||
// Filename: Artist - Name [source_id]
|
// Filename: Artist - Name [source_id]
|
||||||
const baseName = `${safeArtist} - ${safeName} [${source}_${song.id}]`;
|
const baseName = `${safeArtist} - ${safeName} [${source}_${song.id}]`;
|
||||||
|
|||||||
Reference in New Issue
Block a user