fix: ipv6 support for chunked uploads

This commit is contained in:
Bobby 2023-04-09 04:13:29 +07:00
parent cf38c8ac50
commit 2a8901a903
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 8 additions and 2 deletions

View File

@ -372,7 +372,7 @@ self.actuallyUpload = async (req, res, data = {}) => {
const isChunk = typeof req.body.uuid === 'string' && Boolean(req.body.uuid)
if (isChunk) {
// Re-map UUID property to IP-specific UUID
const uuid = `${req.ip}_${req.body.uuid}`
const uuid = `${utils.pathSafeIp(req.ip)}_${req.body.uuid}`
// Calling initChunks() will also reset the chunked uploads' timeout
file.chunksData = await initChunks(uuid)
file.filename = file.chunksData.filename
@ -759,7 +759,7 @@ self.finishChunks = async (req, res) => {
// Re-map UUID property to IP-specific UUID
files.forEach(file => {
file.uuid = `${req.ip}_${file.uuid}`
file.uuid = `${utils.pathSafeIp(req.ip)}_${file.uuid}`
file.chunksData = chunksData[file.uuid]
})

View File

@ -364,6 +364,12 @@ self.mask = string => {
}
}
self.pathSafeIp = ip => {
// Mainly intended for IPv6 addresses
if (!ip) return ''
return ip.replace(/:/g, '-')
}
self.filterUniquifySqlArray = (value, index, array) => {
return value !== null &&
value !== undefined &&