From ee77ce0789f43ffbc1a2e4a3a29a75bdb55a1a79 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 27 Sep 2022 11:57:10 -0400 Subject: [PATCH] chore: remove deprecated socket.io user export methods [breaking] --- src/socket.io/user/profile.js | 28 ---------------------------- test/api.js | 12 +++--------- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js index 20a869056c..eb3d88c303 100644 --- a/src/socket.io/user/profile.js +++ b/src/socket.io/user/profile.js @@ -48,32 +48,4 @@ module.exports = function (SocketUser) { await user.blocks[isBlocked ? 'remove' : 'add'](data.blockeeUid, data.blockerUid); return !isBlocked; }; - - SocketUser.exportProfile = async function (socket, data) { - await doExport(socket, data, 'profile'); - }; - - SocketUser.exportPosts = async function (socket, data) { - await doExport(socket, data, 'posts'); - }; - - SocketUser.exportUploads = async function (socket, data) { - await doExport(socket, data, 'uploads'); - }; - - async function doExport(socket, data, type) { - sockets.warnDeprecated(socket, 'POST /api/v3/users/:uid/exports/:type'); - - if (!socket.uid) { - throw new Error('[[error:invalid-uid]]'); - } - - if (!data || parseInt(data.uid, 10) <= 0) { - throw new Error('[[error:invalid-data]]'); - } - - await user.isAdminOrSelf(socket.uid, data.uid); - - api.users.generateExport(socket, { type, ...data }); - } }; diff --git a/test/api.js b/test/api.js index ab8094cc76..f418d76c71 100644 --- a/test/api.js +++ b/test/api.js @@ -24,6 +24,7 @@ const plugins = require('../src/plugins'); const flags = require('../src/flags'); const messaging = require('../src/messaging'); const utils = require('../src/utils'); +const api = require('../src/api'); describe('API', async () => { let readApi = false; @@ -190,17 +191,10 @@ describe('API', async () => { path: 'files/test.png', }); - const socketUser = require('../src/socket.io/user'); const socketAdmin = require('../src/socket.io/admin'); - // export data for admin user - await socketUser.exportProfile({ uid: adminUid }, { uid: adminUid }); - await wait(2000); - await socketUser.exportPosts({ uid: adminUid }, { uid: adminUid }); - await wait(2000); - await socketUser.exportUploads({ uid: adminUid }, { uid: adminUid }); - await wait(2000); + await Promise.all(['profile', 'posts', 'uploads'].map(async type => api.users.generateExport({ uid: adminUid }, { uid: adminUid, type }))); await socketAdmin.user.exportUsersCSV({ uid: adminUid }, {}); - // wait for export child process to complete + // wait for export child processes to complete await wait(5000); // Attach a search hook so /api/search is enabled