mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 19:36:41 +02:00
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"upload-file": "Upload File",
|
||||
"filename": "Filename",
|
||||
"usage": "Post Usage",
|
||||
"size/filecount": "Size / Filecount",
|
||||
"confirm-delete": "Do you really want to delete this file?",
|
||||
"filecount": "%1 files"
|
||||
|
||||
@@ -8,6 +8,7 @@ var fs = require('fs');
|
||||
var jimp = require('jimp');
|
||||
|
||||
var meta = require('../../meta');
|
||||
var posts = require('../../posts');
|
||||
var file = require('../../file');
|
||||
var image = require('../../image');
|
||||
var plugins = require('../../plugins');
|
||||
@@ -41,7 +42,7 @@ uploadsController.get = function (req, res, next) {
|
||||
|
||||
filesToData(currentFolder, files, next);
|
||||
},
|
||||
function (files) {
|
||||
function (files, next) {
|
||||
files.sort(function (a, b) {
|
||||
if (a.isDirectory && !b.isDirectory) {
|
||||
return -1;
|
||||
@@ -50,14 +51,33 @@ uploadsController.get = function (req, res, next) {
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
res.render('admin/manage/uploads', {
|
||||
currentFolder: currentFolder.replace(nconf.get('upload_path'), ''),
|
||||
files: files,
|
||||
breadcrumbs: buildBreadcrumbs(currentFolder),
|
||||
pagination: pagination.create(page, Math.ceil(itemCount / itemsPerPage), req.query),
|
||||
});
|
||||
|
||||
// Add post usage info if in /files
|
||||
if (req.query.dir === '/files') {
|
||||
posts.uploads.getUsage(files, function (err, usage) {
|
||||
files.forEach(function (file, idx) {
|
||||
file.inPids = usage[idx].map(pid => parseInt(pid, 10));
|
||||
});
|
||||
|
||||
next(err, files);
|
||||
});
|
||||
} else {
|
||||
setImmediate(next, null, files);
|
||||
}
|
||||
},
|
||||
], next);
|
||||
], function (err, files) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
res.render('admin/manage/uploads', {
|
||||
currentFolder: currentFolder.replace(nconf.get('upload_path'), ''),
|
||||
showPids: files[0].hasOwnProperty('inPids'),
|
||||
files: files,
|
||||
breadcrumbs: buildBreadcrumbs(currentFolder),
|
||||
pagination: pagination.create(page, Math.ceil(itemCount / itemsPerPage), req.query),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function buildBreadcrumbs(currentFolder) {
|
||||
|
||||
@@ -26,7 +26,7 @@ module.exports = function (Posts) {
|
||||
let match = searchRegex.exec(data.content);
|
||||
const uploads = [];
|
||||
while (match) {
|
||||
uploads.push(match[1]);
|
||||
uploads.push(match[1].replace('-resized', ''));
|
||||
match = searchRegex.exec(data.content);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,18 @@ module.exports = function (Posts) {
|
||||
});
|
||||
};
|
||||
|
||||
Posts.uploads.getUsage = function (filePaths, callback) {
|
||||
// Given an array of file names, determines which pids they are used in
|
||||
if (!Array.isArray(filePaths)) {
|
||||
filePaths = [filePaths];
|
||||
}
|
||||
|
||||
const keys = filePaths.map(fileObj => 'upload:' + md5(fileObj.name.replace('-resized', '')) + ':pids');
|
||||
async.map(keys, function (key, next) {
|
||||
db.getSortedSetRange(key, 0, -1, next);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
Posts.uploads.associate = function (pid, filePaths, callback) {
|
||||
// Adds an upload to a post's sorted set of uploads
|
||||
const now = Date.now();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>[[admin/manage/uploads:filename]]</th>
|
||||
<!-- IF showPids --><th class="text-right">[[admin/manage/uploads:usage]]</th><!-- END -->
|
||||
<th class="text-right">[[admin/manage/uploads:size/filecount]]</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
@@ -16,17 +17,28 @@
|
||||
<!-- BEGIN files -->
|
||||
<tr data-path="{files.path}">
|
||||
<!-- IF files.isDirectory -->
|
||||
<td class="col-md-9" role="button">
|
||||
<td class="col-md-6" role="button">
|
||||
<i class="fa fa-fw fa-folder-o"></i> <a href="{config.relative_path}/admin/manage/uploads?dir={files.path}">{files.name}</a>
|
||||
</td>
|
||||
<!-- ENDIF files.isDirectory -->
|
||||
|
||||
<!-- IF files.isFile -->
|
||||
<td class="col-md-9">
|
||||
<td class="col-md-6">
|
||||
<i class="fa fa-fw fa-file-text-o"></i> <a href="{config.relative_path}{files.url}" target="_blank">{files.name}</a>
|
||||
</td>
|
||||
<!-- ENDIF files.isFile -->
|
||||
|
||||
<!-- IF showPids -->
|
||||
<td class="col-md-3 text-right">
|
||||
<!-- BEGIN ../inPids -->
|
||||
<a target="_blank" href="{config.relative_path}/post/@value"><span class="label label-default">@value</span></a>
|
||||
<!-- END -->
|
||||
<!-- IF !../inPids.length -->
|
||||
<span class="label label-danger">[[admin/manage/uploads:orphaned]]</span>
|
||||
<!-- END -->
|
||||
</td>
|
||||
<!-- END -->
|
||||
|
||||
<td class="col-md-2 text-right"><!-- IF files.isFile -->{files.sizeHumanReadable}<!-- ELSE -->[[admin/manage/uploads:filecount, {files.fileCount}]]<!-- ENDIF files.isFile --></td>
|
||||
|
||||
<td role="button" class="col-md-1 text-right"><i class="delete fa fa-fw fa-trash-o <!-- IF !files.isFile --> hidden<!-- ENDIF !files.isFile -->"></i></td>
|
||||
|
||||
Reference in New Issue
Block a user