From b9edee143e26797ebeeb8b2afab220aece2c8566 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 11 Feb 2022 11:21:54 -0500 Subject: [PATCH] fix: local deleteUploads() method in `src/user/delete.js` to call `User.deleteUpload()` --- src/user/delete.js | 13 ++++--------- test/uploads.js | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/user/delete.js b/src/user/delete.js index d9d9011f32..47cc3b2742 100644 --- a/src/user/delete.js +++ b/src/user/delete.js @@ -15,7 +15,6 @@ const groups = require('../groups'); const messaging = require('../messaging'); const plugins = require('../plugins'); const batch = require('../batch'); -const file = require('../file'); module.exports = function (User) { const deletesInProgress = {}; @@ -35,7 +34,7 @@ module.exports = function (User) { deletesInProgress[uid] = 'user.delete'; await deletePosts(callerUid, uid); await deleteTopics(callerUid, uid); - await deleteUploads(uid); + await deleteUploads(callerUid, uid); await deleteQueued(uid); delete deletesInProgress[uid]; }; @@ -56,13 +55,9 @@ module.exports = function (User) { }, { alwaysStartAt: 0 }); } - async function deleteUploads(uid) { - await batch.processSortedSet(`uid:${uid}:uploads`, async (uploadNames) => { - await async.each(uploadNames, async (uploadName) => { - await file.delete(path.join(nconf.get('upload_path'), uploadName)); - }); - await db.sortedSetRemove(`uid:${uid}:uploads`, uploadNames); - }, { alwaysStartAt: 0 }); + async function deleteUploads(callerUid, uid) { + const uploads = await db.getSortedSetMembers(`uid:${uid}:uploads`); + await User.deleteUpload(callerUid, uid, uploads); } async function deleteQueued(uid) { diff --git a/test/uploads.js b/test/uploads.js index 09b56fe64a..f299cba39e 100644 --- a/test/uploads.js +++ b/test/uploads.js @@ -130,7 +130,7 @@ describe('Upload Controllers', () => { assert(body && body.status && body.response && body.response.images); assert(Array.isArray(body.response.images)); assert(body.response.images[0].url); - const name = body.response.images[0].url.replace(nconf.get('relative_path') + nconf.get('upload_url'), ''); + const name = body.response.images[0].url.replace(`${nconf.get('relative_path') + nconf.get('upload_url')}/`, ''); socketUser.deleteUpload({ uid: regularUid }, { uid: regularUid, name: name }, (err) => { assert.ifError(err); db.getSortedSetRange(`uid:${regularUid}:uploads`, 0, -1, (err, uploads) => {