From 2c33595507fd09699207787f924402e6d193f79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 9 Jul 2019 22:23:10 -0400 Subject: [PATCH] feat: #7743 user/admin.js --- src/user/admin.js | 52 +++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/src/user/admin.js b/src/user/admin.js index 7c170016c3..356e8b0ce1 100644 --- a/src/user/admin.js +++ b/src/user/admin.js @@ -1,7 +1,6 @@ 'use strict'; -var async = require('async'); var winston = require('winston'); var validator = require('validator'); @@ -9,9 +8,9 @@ var db = require('../database'); var plugins = require('../plugins'); module.exports = function (User) { - User.logIP = function (uid, ip, callback) { + User.logIP = async function (uid, ip) { if (!(parseInt(uid, 10) > 0)) { - return setImmediate(callback); + return; } var now = Date.now(); const bulk = [ @@ -20,44 +19,25 @@ module.exports = function (User) { if (ip) { bulk.push(['ip:' + ip + ':uid', now, uid]); } - db.sortedSetAddBulk(bulk, callback); + await db.sortedSetAddBulk(bulk); }; - User.getIPs = function (uid, stop, callback) { - async.waterfall([ - function (next) { - db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop, next); - }, - function (ips, next) { - next(null, ips.map(ip => validator.escape(String(ip)))); - }, - ], callback); + User.getIPs = async function (uid, stop) { + const ips = await db.getSortedSetRevRange('uid:' + uid + ':ip', 0, stop); + return ips.map(ip => validator.escape(String(ip))); }; - User.getUsersCSV = function (callback) { + User.getUsersCSV = async function () { winston.verbose('[user/getUsersCSV] Compiling User CSV data'); var csvContent = ''; - var uids; - async.waterfall([ - function (next) { - db.getSortedSetRange('users:joindate', 0, -1, next); - }, - function (_uids, next) { - uids = _uids; - plugins.fireHook('filter:user.csvFields', { fields: ['uid', 'email', 'username'] }, next); - }, - function (data, next) { - User.getUsersFields(uids, data.fields, next); - }, - function (usersData, next) { - usersData.forEach(function (user) { - if (user) { - csvContent += user.email + ',' + user.username + ',' + user.uid + '\n'; - } - }); - - next(null, csvContent); - }, - ], callback); + var uids = await db.getSortedSetRange('users:joindate', 0, -1); + const data = await plugins.fireHook('filter:user.csvFields', { fields: ['uid', 'email', 'username'] }); + const usersData = await User.getUsersFields(uids, data.fields); + usersData.forEach(function (user) { + if (user) { + csvContent += user.email + ',' + user.username + ',' + user.uid + '\n'; + } + }); + return csvContent; }; };