mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-03-21 19:13:10 +00:00
refactor(server): 优化文件上传配置和MD5计算逻辑
- 移除cloud.js中的异步Promise包装,直接同步计算MD5哈希值 - 在server.js中提取上传大小限制为常量配置 - 统一使用字节单位常量管理文件上传大小限制 - 简化代码结构,提高可读性和维护性
This commit is contained in:
parent
33ccc83615
commit
8951e32a0e
@ -69,11 +69,7 @@ module.exports = async (query, request) => {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!fileMd5) {
|
if (!fileMd5) {
|
||||||
fileMd5 = await new Promise((resolve) => {
|
fileMd5 = crypto.createHash('md5').update(query.songFile.data).digest('hex')
|
||||||
setImmediate(() => {
|
|
||||||
resolve(crypto.createHash('md5').update(query.songFile.data).digest('hex'))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
fileSize = query.songFile.data.byteLength
|
fileSize = query.songFile.data.byteLength
|
||||||
}
|
}
|
||||||
|
|||||||
@ -178,12 +178,15 @@ async function consturctServer(moduleDefs) {
|
|||||||
/**
|
/**
|
||||||
* Body Parser and File Upload
|
* Body Parser and File Upload
|
||||||
*/
|
*/
|
||||||
app.use(express.json({ limit: '500mb' }))
|
const MAX_UPLOAD_SIZE_MB = 500
|
||||||
app.use(express.urlencoded({ extended: false, limit: '500mb' }))
|
const MAX_UPLOAD_SIZE_BYTES = MAX_UPLOAD_SIZE_MB * 1024 * 1024
|
||||||
|
|
||||||
|
app.use(express.json({ limit: `${MAX_UPLOAD_SIZE_MB}mb` }))
|
||||||
|
app.use(express.urlencoded({ extended: false, limit: `${MAX_UPLOAD_SIZE_MB}mb` }))
|
||||||
|
|
||||||
app.use(fileUpload({
|
app.use(fileUpload({
|
||||||
limits: {
|
limits: {
|
||||||
fileSize: 500 * 1024 * 1024
|
fileSize: MAX_UPLOAD_SIZE_BYTES
|
||||||
},
|
},
|
||||||
useTempFiles: true,
|
useTempFiles: true,
|
||||||
tempFileDir: require('os').tmpdir(),
|
tempFileDir: require('os').tmpdir(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user