fix: size attribute of uploads with stripped tags

it'd previously always keep size attribute before the tags stripping
This commit is contained in:
Bobby 2022-10-04 05:42:00 +07:00
parent 0eb4c243c3
commit a49842a932
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 10 additions and 4 deletions

View File

@ -527,6 +527,7 @@ self.actuallyUpload = async (req, res, data = {}) => {
} }
} }
// Strip tags, then update their size attribute, if required
await self.stripTags(req, filesData) await self.stripTags(req, filesData)
const stored = await self.storeFilesToDb(req, res, filesData) const stored = await self.storeFilesToDb(req, res, filesData)
@ -862,6 +863,7 @@ self.actuallyFinishChunks = async (req, res, files) => {
} }
} }
// Strip tags, then update their size attribute, if required
await self.stripTags(req, filesData) await self.stripTags(req, filesData)
const stored = await self.storeFilesToDb(req, res, filesData) const stored = await self.storeFilesToDb(req, res, filesData)
@ -971,9 +973,13 @@ self.stripTags = async (req, filesData) => {
if (!self.parseStripTags(req.headers.striptags)) return if (!self.parseStripTags(req.headers.striptags)) return
try { try {
await Promise.all(filesData.map(async file => await Promise.all(filesData.map(async file => {
utils.stripTags(file.filename, file.extname) // Update size attribute if applicable
)) const stat = await utils.stripTags(file.filename, file.extname)
if (stat) {
file.size = stat.size
}
}))
} catch (error) { } catch (error) {
// Unlink temp files (do not wait) // Unlink temp files (do not wait)
Promise.all(filesData.map(async file => Promise.all(filesData.map(async file =>

View File

@ -613,7 +613,7 @@ self.stripTags = async (name, extname) => {
throw new ServerError('An error occurred while stripping tags. The format may not be supported.') throw new ServerError('An error occurred while stripping tags. The format may not be supported.')
} }
return true return jetpack.inspectAsync(fullPath)
} }
self.unlinkFile = async (filename, predb) => { self.unlinkFile = async (filename, predb) => {