change upload storage

v1.18.x
Barış Soner Uşaklı 7 years ago
parent 3fb28e9246
commit 5d2a7106f6

@ -7,10 +7,10 @@ define('forum/account/uploads', ['forum/account/header'], function (header) {
header.init(); header.init();
$('[data-action="delete"]').on('click', function () { $('[data-action="delete"]').on('click', function () {
var el = $(this).parents('[data-url]'); var el = $(this).parents('[data-name]');
var url = el.attr('data-url'); var name = el.attr('data-name');
socket.emit('user.deleteUpload', { url: url, uid: ajaxify.data.uid }, function (err) { socket.emit('user.deleteUpload', { name: name, uid: ajaxify.data.uid }, function (err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }

@ -2,6 +2,7 @@
var async = require('async'); var async = require('async');
var nconf = require('nconf');
var db = require('../../database'); var db = require('../../database');
var helpers = require('../helpers'); var helpers = require('../helpers');
@ -33,15 +34,16 @@ uploadsController.get = function (req, res, callback) {
itemCount: function (next) { itemCount: function (next) {
db.sortedSetCard('uid:' + userData.uid + ':uploads', next); db.sortedSetCard('uid:' + userData.uid + ':uploads', next);
}, },
uploadUrls: function (next) { uploadNames: function (next) {
db.getSortedSetRevRange('uid:' + userData.uid + ':uploads', start, stop, next); db.getSortedSetRevRange('uid:' + userData.uid + ':uploads', start, stop, next);
}, },
}, next); }, next);
}, },
function (results) { function (results) {
userData.uploads = results.uploadUrls.map(function (url) { userData.uploads = results.uploadNames.map(function (uploadName) {
return { return {
url: url, name: uploadName,
url: nconf.get('upload_url') + uploadName,
}; };
}); });
var pageCount = Math.ceil(results.itemCount / itemsPerPage); var pageCount = Math.ceil(results.itemCount / itemsPerPage);

@ -241,7 +241,8 @@ function saveFileToLocal(uid, uploadedFile, callback) {
name: uploadedFile.name, name: uploadedFile.name,
}; };
db.sortedSetAdd('uid:' + uid + ':uploads', Date.now(), upload.url, next); var fileKey = upload.url.replace(nconf.get('upload_url'), '');
db.sortedSetAdd('uid:' + uid + ':uploads', Date.now(), fileKey, next);
}, },
function (next) { function (next) {
plugins.fireHook('filter:uploadStored', { uid: uid, uploadedFile: uploadedFile, storedFile: storedFile }, next); plugins.fireHook('filter:uploadStored', { uid: uid, uploadedFile: uploadedFile, storedFile: storedFile }, next);

@ -88,13 +88,6 @@ 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) { file.base64ToLocal = function (imageData, uploadPath, callback) {
var buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64'); var buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
uploadPath = path.join(nconf.get('upload_path'), uploadPath); uploadPath = path.join(nconf.get('upload_path'), uploadPath);

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

@ -2,7 +2,8 @@
var async = require('async'); var async = require('async');
var _ = require('lodash'); var _ = require('lodash');
var path = require('path');
var nconf = require('nconf');
var db = require('../database'); var db = require('../database');
var posts = require('../posts'); var posts = require('../posts');
@ -52,15 +53,15 @@ module.exports = function (User) {
} }
function deleteUploads(uid, callback) { function deleteUploads(uid, callback) {
batch.processSortedSet('uid:' + uid + ':uploads', function (urls, next) { batch.processSortedSet('uid:' + uid + ':uploads', function (uploadNames, next) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.each(urls, function (url, next) { async.each(uploadNames, function (uploadName, next) {
file.delete(file.uploadUrlToPath(url), next); file.delete(path.join(nconf.get('upload_path'), uploadName), next);
}, next); }, next);
}, },
function (next) { function (next) {
db.sortedSetRemove('uid:' + uid + ':uploads', urls, next); db.sortedSetRemove('uid:' + uid + ':uploads', uploadNames, next);
}, },
], next); ], next);
}, { alwaysStartAt: 0 }, callback); }, { alwaysStartAt: 0 }, callback);

@ -1,17 +1,19 @@
'use strict'; 'use strict';
var async = require('async'); var async = require('async');
var path = require('path');
var nconf = require('nconf');
var db = require('../database'); var db = require('../database');
var file = require('../file'); var file = require('../file');
module.exports = function (User) { module.exports = function (User) {
User.deleteUpload = function (callerUid, uid, url, callback) { User.deleteUpload = function (callerUid, uid, uploadName, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
async.parallel({ async.parallel({
isUsersUpload: function (next) { isUsersUpload: function (next) {
db.isSortedSetMember('uid:' + callerUid + ':uploads', url, next); db.isSortedSetMember('uid:' + callerUid + ':uploads', uploadName, next);
}, },
isAdminOrGlobalMod: function (next) { isAdminOrGlobalMod: function (next) {
User.isAdminOrGlobalMod(callerUid, next); User.isAdminOrGlobalMod(callerUid, next);
@ -23,10 +25,10 @@ module.exports = function (User) {
return next(new Error('[[error:no-privileges]]')); return next(new Error('[[error:no-privileges]]'));
} }
file.delete(file.uploadUrlToPath(url), next); file.delete(path.join(nconf.get('upload_path'), uploadName), next);
}, },
function (next) { function (next) {
db.sortedSetRemove('uid:' + uid + ':uploads', url, next); db.sortedSetRemove('uid:' + uid + ':uploads', uploadName, next);
}, },
], callback); ], callback);
}; };

Loading…
Cancel
Save