mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-03-21 11:03:15 +00:00
refactor(util): 简化文件帮助工具函数
- 移除未使用的 path 模块引入 - 将 getFileExtension 函数从异步改为同步 - 优化 sanitizeFilename 函数逻辑,移除冗余扩展名处理
This commit is contained in:
parent
92df6e13a0
commit
755489546b
@ -1,6 +1,5 @@
|
||||
const fs = require('fs')
|
||||
const crypto = require('crypto')
|
||||
const path = require('path')
|
||||
const logger = require('./logger')
|
||||
|
||||
function isTempFile(file) {
|
||||
@ -61,7 +60,7 @@ async function readFileChunk(filePath, offset, length) {
|
||||
return buffer
|
||||
}
|
||||
|
||||
async function getFileExtension(filename) {
|
||||
function getFileExtension(filename) {
|
||||
if (!filename) return 'mp3'
|
||||
if (filename.includes('.')) {
|
||||
return filename.split('.').pop().toLowerCase()
|
||||
@ -71,7 +70,6 @@ async function getFileExtension(filename) {
|
||||
|
||||
function sanitizeFilename(filename) {
|
||||
if (!filename) return 'unknown'
|
||||
const ext = getFileExtension(filename)
|
||||
return filename
|
||||
.replace(/\.[^.]+$/, '')
|
||||
.replace(/\s/g, '')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user