mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
change upload storage
This commit is contained in:
@@ -7,10 +7,10 @@ define('forum/account/uploads', ['forum/account/header'], function (header) {
|
||||
header.init();
|
||||
|
||||
$('[data-action="delete"]').on('click', function () {
|
||||
var el = $(this).parents('[data-url]');
|
||||
var url = el.attr('data-url');
|
||||
var el = $(this).parents('[data-name]');
|
||||
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) {
|
||||
return app.alertError(err.message);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
|
||||
var async = require('async');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var db = require('../../database');
|
||||
var helpers = require('../helpers');
|
||||
@@ -33,15 +34,16 @@ uploadsController.get = function (req, res, callback) {
|
||||
itemCount: function (next) {
|
||||
db.sortedSetCard('uid:' + userData.uid + ':uploads', next);
|
||||
},
|
||||
uploadUrls: function (next) {
|
||||
uploadNames: function (next) {
|
||||
db.getSortedSetRevRange('uid:' + userData.uid + ':uploads', start, stop, next);
|
||||
},
|
||||
}, next);
|
||||
},
|
||||
function (results) {
|
||||
userData.uploads = results.uploadUrls.map(function (url) {
|
||||
userData.uploads = results.uploadNames.map(function (uploadName) {
|
||||
return {
|
||||
url: url,
|
||||
name: uploadName,
|
||||
url: nconf.get('upload_url') + uploadName,
|
||||
};
|
||||
});
|
||||
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
|
||||
|
||||
@@ -241,7 +241,8 @@ function saveFileToLocal(uid, uploadedFile, callback) {
|
||||
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) {
|
||||
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) {
|
||||
var buffer = Buffer.from(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
|
||||
uploadPath = path.join(nconf.get('upload_path'), uploadPath);
|
||||
|
||||
@@ -342,10 +342,10 @@ SocketUser.setModerationNote = 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]]'));
|
||||
}
|
||||
user.deleteUpload(socket.uid, data.uid, data.url, callback);
|
||||
user.deleteUpload(socket.uid, data.uid, data.name, callback);
|
||||
};
|
||||
|
||||
SocketUser.gdpr = {};
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
var async = require('async');
|
||||
var _ = require('lodash');
|
||||
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var db = require('../database');
|
||||
var posts = require('../posts');
|
||||
@@ -52,15 +53,15 @@ module.exports = function (User) {
|
||||
}
|
||||
|
||||
function deleteUploads(uid, callback) {
|
||||
batch.processSortedSet('uid:' + uid + ':uploads', function (urls, next) {
|
||||
batch.processSortedSet('uid:' + uid + ':uploads', function (uploadNames, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.each(urls, function (url, next) {
|
||||
file.delete(file.uploadUrlToPath(url), next);
|
||||
async.each(uploadNames, function (uploadName, next) {
|
||||
file.delete(path.join(nconf.get('upload_path'), uploadName), next);
|
||||
}, next);
|
||||
},
|
||||
function (next) {
|
||||
db.sortedSetRemove('uid:' + uid + ':uploads', urls, next);
|
||||
db.sortedSetRemove('uid:' + uid + ':uploads', uploadNames, next);
|
||||
},
|
||||
], next);
|
||||
}, { alwaysStartAt: 0 }, callback);
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var path = require('path');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var db = require('../database');
|
||||
var file = require('../file');
|
||||
|
||||
module.exports = function (User) {
|
||||
User.deleteUpload = function (callerUid, uid, url, callback) {
|
||||
User.deleteUpload = function (callerUid, uid, uploadName, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
isUsersUpload: function (next) {
|
||||
db.isSortedSetMember('uid:' + callerUid + ':uploads', url, next);
|
||||
db.isSortedSetMember('uid:' + callerUid + ':uploads', uploadName, next);
|
||||
},
|
||||
isAdminOrGlobalMod: function (next) {
|
||||
User.isAdminOrGlobalMod(callerUid, next);
|
||||
@@ -23,10 +25,10 @@ module.exports = function (User) {
|
||||
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) {
|
||||
db.sortedSetRemove('uid:' + uid + ':uploads', url, next);
|
||||
db.sortedSetRemove('uid:' + uid + ':uploads', uploadName, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user