diff --git a/controllers/uploadController.js b/controllers/uploadController.js index e95fac7..6412844 100644 --- a/controllers/uploadController.js +++ b/controllers/uploadController.js @@ -836,7 +836,7 @@ self.storeFilesToDb = async (req, res, user, infoMap) => { }) .where({ hash: info.data.hash, - size: info.data.size + size: String(info.data.size) }) // Select expirydate to display expiration date of existing files as well .select('name', 'expirydate') @@ -861,7 +861,7 @@ self.storeFilesToDb = async (req, res, user, infoMap) => { name: info.data.filename, original: info.data.originalname, type: info.data.mimetype, - size: info.data.size, + size: String(info.data.size), hash: info.data.hash, // Only disable if explicitly set to false in config ip: config.uploads.storeIP !== false ? req.ip : null, diff --git a/scripts/migrate.js b/scripts/migrate.js index 1e5b5e8..4f1a971 100644 --- a/scripts/migrate.js +++ b/scripts/migrate.js @@ -70,6 +70,19 @@ const map = { }) } + const files = await db.table('files') + .where('size', 'like', '%.0') + if (files.length) { + console.log(`Found ${files.length} files with outdated "size" field, converting\u2026`) + for (const file of files) { + const size = file.size.replace(/\.0$/, '') + await db.table('files') + .update('size', size) + .where('id', file.id) + done++ + } + } + let status = 'Database migration was not required.' if (done) { status = `Completed ${done} database migration task(s).`