mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-07-05 05:18:56 +08:00
feat: 播客分段上传
This commit is contained in:
parent
dfcdc04fbb
commit
18ca74214e
@ -65,18 +65,42 @@ module.exports = async (query, request) => {
|
|||||||
// return xml
|
// return xml
|
||||||
const res2 = await parser.parseStringPromise(res.data)
|
const res2 = await parser.parseStringPromise(res.data)
|
||||||
|
|
||||||
|
const fileSize = query.songFile.data.length
|
||||||
|
const blockSize = 10 * 1024 * 1024 // 10MB
|
||||||
|
let offset = 0
|
||||||
|
let blockIndex = 1
|
||||||
|
|
||||||
|
let etags = []
|
||||||
|
|
||||||
|
while (offset < fileSize) {
|
||||||
|
const chunk = query.songFile.data.slice(
|
||||||
|
offset,
|
||||||
|
Math.min(offset + blockSize, fileSize),
|
||||||
|
)
|
||||||
|
|
||||||
const res3 = await axios({
|
const res3 = await axios({
|
||||||
method: 'put',
|
method: 'put',
|
||||||
url: `https://ymusic.nos-hz.163yun.com/${objectKey}?partNumber=1&uploadId=${res2.InitiateMultipartUploadResult.UploadId[0]}`,
|
url: `https://ymusic.nos-hz.163yun.com/${objectKey}?partNumber=${blockIndex}&uploadId=${res2.InitiateMultipartUploadResult.UploadId[0]}`,
|
||||||
headers: {
|
headers: {
|
||||||
'x-nos-token': tokenRes.body.result.token,
|
'x-nos-token': tokenRes.body.result.token,
|
||||||
'Content-Type': 'audio/mpeg',
|
'Content-Type': 'audio/mpeg',
|
||||||
},
|
},
|
||||||
data: query.songFile.data,
|
data: chunk,
|
||||||
})
|
})
|
||||||
|
|
||||||
// get etag
|
// get etag
|
||||||
const etag = res3.headers.etag
|
const etag = res3.headers.etag
|
||||||
|
etags.push(etag)
|
||||||
|
offset += blockSize
|
||||||
|
blockIndex++
|
||||||
|
}
|
||||||
|
|
||||||
|
let completeStr = '<CompleteMultipartUpload>'
|
||||||
|
for (let i = 0; i < etags.length; i++) {
|
||||||
|
completeStr += `<Part><PartNumber>${i + 1}</PartNumber><ETag>${
|
||||||
|
etags[i]
|
||||||
|
}</ETag></Part>`
|
||||||
|
}
|
||||||
|
completeStr += '</CompleteMultipartUpload>'
|
||||||
|
|
||||||
// 文件处理
|
// 文件处理
|
||||||
await axios({
|
await axios({
|
||||||
@ -87,9 +111,7 @@ module.exports = async (query, request) => {
|
|||||||
'X-Nos-Meta-Content-Type': 'audio/mpeg',
|
'X-Nos-Meta-Content-Type': 'audio/mpeg',
|
||||||
'x-nos-token': tokenRes.body.result.token,
|
'x-nos-token': tokenRes.body.result.token,
|
||||||
},
|
},
|
||||||
data: `<CompleteMultipartUpload>
|
data: completeStr,
|
||||||
<Part><PartNumber>1</PartNumber><ETag>${etag}</ETag></Part>
|
|
||||||
</CompleteMultipartUpload>`,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// preCheck
|
// preCheck
|
||||||
|
Loading…
x
Reference in New Issue
Block a user