posts export endpoint for GDPR, re: #6441

v1.18.x
Julian Lam 7 years ago
parent ef99ef86a4
commit 2e6e7f7484

@ -1,9 +1,12 @@
'use strict';
var async = require('async');
var converter = require('json-2-csv');
var user = require('../user');
var meta = require('../meta');
var posts = require('../posts');
var batch = require('../batch');
var accountHelpers = require('./accounts/helpers');
var userController = module.exports;
@ -97,3 +100,36 @@ userController.getUserDataByUID = function (callerUid, uid, callback) {
callback(null, results.userData);
});
};
userController.exportPosts = function (req, res, next) {
async.waterfall([
function (next) {
var payload = [];
batch.processSortedSet('uid:' + req.params.uid + ':posts', function (pids, next) {
async.map(pids, posts.getPostData, function (err, posts) {
if (err) {
return next(err);
}
// Convert newlines in content
posts = posts.map(function (post) {
post.content = '"' + post.content.replace(/\n/g, '\\n').replace(/"/g, '\\"') + '"';
return post;
});
payload = payload.concat(posts);
next();
});
}, function (err) {
next(err, payload);
});
},
async.apply(converter.json2csv),
], function (err, csv) {
if (err) {
return next(err);
}
res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="' + req.params.uid + '_posts.csv"').send(csv);
});
};

@ -15,6 +15,8 @@ module.exports = function (app, middleware, controllers) {
router.get('/user/username/:username', middleware.checkGlobalPrivacySettings, controllers.user.getUserByUsername);
router.get('/user/email/:email', middleware.checkGlobalPrivacySettings, controllers.user.getUserByEmail);
router.get('/user/uid/:uid/export/posts', middleware.checkAccountPermissions, controllers.user.exportPosts);
router.get('/:type/pid/:id', controllers.api.getObject);
router.get('/:type/tid/:id', controllers.api.getObject);
router.get('/:type/cid/:id', controllers.api.getObject);

Loading…
Cancel
Save