mirror of
https://github.com/NeteaseCloudMusicApiEnhanced/api-enhanced.git
synced 2026-10-20 22:51:23 +08:00
fix(upload): 修复文件上传功能中的路径替换和临时文件支持
- 将单个斜杠替换改为全局正则替换以正确处理所有路径分隔符 - 移除未使用的 crypto 模块引入 - 添加对临时文件上传的支持,使用 fs 模块读取临时文件 - 动态设置 Content-Type 头部,优先使用文件的 mimetype 属性 - 重构多处文件上传逻辑以支持流式读取大文件 - 优化分片上传时的文件大小获取方式
This commit is contained in:
@@ -38,7 +38,7 @@ module.exports = async (query, request) => {
|
||||
}
|
||||
}
|
||||
|
||||
const objectKey = tokenRes.body.result.objectKey.replace('/', '%2F')
|
||||
const objectKey = tokenRes.body.result.objectKey.replace(/\//g, '%2F')
|
||||
let lbs
|
||||
try {
|
||||
lbs = (
|
||||
@@ -87,7 +87,7 @@ module.exports = async (query, request) => {
|
||||
headers: {
|
||||
'x-nos-token': tokenRes.body.result.token,
|
||||
'Content-MD5': query.songFile.md5,
|
||||
'Content-Type': 'audio/mpeg',
|
||||
'Content-Type': query.songFile.mimetype || 'audio/mpeg',
|
||||
'Content-Length': String(query.songFile.size),
|
||||
},
|
||||
data: uploadData,
|
||||
|
||||
+12
-2
@@ -1,5 +1,7 @@
|
||||
const { default: axios } = require('axios')
|
||||
const fs = require('fs')
|
||||
const createOption = require('../util/option.js')
|
||||
|
||||
module.exports = async (query, request) => {
|
||||
const data = {
|
||||
bucket: 'yyimgs',
|
||||
@@ -17,14 +19,22 @@ module.exports = async (query, request) => {
|
||||
createOption(query, 'weapi'),
|
||||
)
|
||||
// 上传图片
|
||||
const useTempFile = !!query.imgFile.tempFilePath
|
||||
let uploadData
|
||||
if (useTempFile) {
|
||||
uploadData = fs.createReadStream(query.imgFile.tempFilePath)
|
||||
} else {
|
||||
uploadData = query.imgFile.data
|
||||
}
|
||||
|
||||
const res2 = await axios({
|
||||
method: 'post',
|
||||
url: `https://nosup-hz1.127.net/yyimgs/${res.body.result.objectKey}?offset=0&complete=true&version=1.0`,
|
||||
headers: {
|
||||
'x-nos-token': res.body.result.token,
|
||||
'Content-Type': 'image/jpeg',
|
||||
'Content-Type': query.imgFile.mimetype || 'image/jpeg',
|
||||
},
|
||||
data: query.imgFile.data,
|
||||
data: uploadData,
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user