mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
closes #4917
This commit is contained in:
2
app.js
2
app.js
@@ -121,7 +121,7 @@ function start() {
|
||||
nconf.set('use_port', !!urlObject.port);
|
||||
nconf.set('relative_path', relativePath);
|
||||
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567);
|
||||
nconf.set('upload_url', '/uploads/');
|
||||
nconf.set('upload_url', nconf.get('upload_path').replace(/^\/public/, ''));
|
||||
|
||||
if (nconf.get('isPrimary') === 'true') {
|
||||
winston.info('Time: %s', (new Date()).toString());
|
||||
|
||||
@@ -96,24 +96,21 @@ function uploadAsFile(req, uploadedFile, callback) {
|
||||
}
|
||||
|
||||
function resizeImage(fileObj, callback) {
|
||||
var fullPath;
|
||||
async.waterfall([
|
||||
function(next) {
|
||||
fullPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), '..', fileObj.url);
|
||||
|
||||
image.size(fullPath, next);
|
||||
image.size(fileObj.path, next);
|
||||
},
|
||||
function (imageData, next) {
|
||||
if (imageData.width < (parseInt(meta.config.maximumImageWidth, 10) || 760)) {
|
||||
return callback(null, fileObj);
|
||||
}
|
||||
|
||||
var dirname = path.dirname(fullPath);
|
||||
var extname = path.extname(fullPath);
|
||||
var basename = path.basename(fullPath, extname);
|
||||
var dirname = path.dirname(fileObj.path);
|
||||
var extname = path.extname(fileObj.path);
|
||||
var basename = path.basename(fileObj.path, extname);
|
||||
|
||||
image.resizeImage({
|
||||
path: fullPath,
|
||||
path: fileObj.path,
|
||||
target: path.join(dirname, basename + '-resized' + extname),
|
||||
extension: extname,
|
||||
width: parseInt(meta.config.maximumImageWidth, 10) || 760
|
||||
@@ -223,6 +220,7 @@ function saveFileToLocal(uploadedFile, callback) {
|
||||
var filename = uploadedFile.name || 'upload';
|
||||
|
||||
filename = Date.now() + '-' + validator.escape(filename.replace(extension, '')).substr(0, 255) + extension;
|
||||
|
||||
file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -230,6 +228,7 @@ function saveFileToLocal(uploadedFile, callback) {
|
||||
|
||||
callback(null, {
|
||||
url: nconf.get('relative_path') + upload.url,
|
||||
path: upload.path,
|
||||
name: uploadedFile.name
|
||||
});
|
||||
});
|
||||
|
||||
15
src/file.js
15
src/file.js
@@ -1,12 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
var fs = require('fs'),
|
||||
nconf = require('nconf'),
|
||||
path = require('path'),
|
||||
winston = require('winston'),
|
||||
jimp = require('jimp'),
|
||||
var fs = require('fs');
|
||||
var nconf = require('nconf');
|
||||
var path = require('path');
|
||||
var winston = require('winston');
|
||||
var jimp = require('jimp');
|
||||
|
||||
utils = require('../public/src/utils');
|
||||
var utils = require('../public/src/utils');
|
||||
|
||||
var file = {};
|
||||
|
||||
@@ -29,7 +29,8 @@ file.saveFileToLocal = function(filename, folder, tempPath, callback) {
|
||||
|
||||
is.on('end', function () {
|
||||
callback(null, {
|
||||
url: nconf.get('upload_url') + folder + '/' + filename
|
||||
url: path.join(nconf.get('upload_url'), folder, filename),
|
||||
path: uploadPath
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user