ability to delete uploads from account page #6431

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 8e822c7772
commit b35bfb81ce

@ -0,0 +1,24 @@
'use strict';
define('forum/account/uploads', ['forum/account/header'], function (header) {
var AccountUploads = {};
AccountUploads.init = function () {
header.init();
$('[data-action="delete"]').on('click', function () {
var el = $(this).parents('[data-url]');
var url = el.attr('data-url');
socket.emit('user.deleteUpload', url, function (err) {
if (err) {
return app.alertError(err.message);
}
el.remove();
});
return false;
});
};
return AccountUploads;
});

@ -88,6 +88,13 @@ file.saveFileToLocal = function (filename, folder, tempPath, callback) {
});
};
file.uploadUrlToPath = function (url) {
if (typeof url !== 'string') {
return '';
}
return path.join(nconf.get('upload_path'), url.replace(nconf.get('upload_url'), ''));
};
file.base64ToLocal = function (imageData, uploadPath, callback) {
var buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
uploadPath = path.join(nconf.get('upload_path'), uploadPath);

@ -341,6 +341,13 @@ SocketUser.setModerationNote = function (socket, data, callback) {
], callback);
};
SocketUser.deleteUpload = function (socket, url, callback) {
if (!url) {
return callback(new Error('[[error:invalid-data]]'));
}
user.deleteUpload(socket.uid, url, callback);
};
SocketUser.gdpr = {};
SocketUser.gdpr.consent = function (socket, data, callback) {

@ -36,6 +36,7 @@ require('./user/invite')(User);
require('./user/password')(User);
require('./user/info')(User);
require('./user/online')(User);
require('./user/uploads')(User);
User.getUidsFromSet = function (set, start, stop, callback) {
if (set === 'users:online') {

@ -2,8 +2,7 @@
var async = require('async');
var _ = require('lodash');
var path = require('path');
var nconf = require('nconf');
var db = require('../database');
var posts = require('../posts');
@ -57,8 +56,7 @@ module.exports = function (User) {
async.waterfall([
function (next) {
async.each(urls, function (url, next) {
var filePath = path.join(nconf.get('upload_path'), url.replace(nconf.get('upload_url'), ''));
file.delete(filePath, next);
file.delete(file.uploadUrlToPath(url), next);
}, next);
},
function (next) {

@ -0,0 +1,30 @@
'use strict';
var async = require('async');
var db = require('../database');
var file = require('../file');
module.exports = function (User) {
User.deleteUpload = function (uid, url, callback) {
async.waterfall([
function (next) {
async.parallel({
isUsersUpload: function (next) {
db.isSortedSetMember('uid:' + uid + ':uploads', url, next);
},
isAdminOrGlobalMod: function (next) {
User.isAdminOrGlobalMod(uid, next);
},
}, next);
},
function (results, next) {
if (!results.isAdminOrGlobalMod && !results.isUsersUpload) {
return next(new Error('[[error:no-privileges]]'));
}
file.delete(file.uploadUrlToPath(url), next);
},
], callback);
};
};
Loading…
Cancel
Save