From 2a8901a903952f3f8712443a5ab4abbffdbdcb21 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sun, 9 Apr 2023 04:13:29 +0700 Subject: [PATCH] fix: ipv6 support for chunked uploads --- controllers/uploadController.js | 4 ++-- controllers/utilsController.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/controllers/uploadController.js b/controllers/uploadController.js index 929ab82..161c9ff 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -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] }) diff --git a/controllers/utilsController.js b/controllers/utilsController.js index b26c876..1e4d8f8 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -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 &&