v1.18.x
barisusakli 9 years ago
parent 81910530fe
commit aac0313f2e

@ -121,7 +121,7 @@ function start() {
nconf.set('use_port', !!urlObject.port); nconf.set('use_port', !!urlObject.port);
nconf.set('relative_path', relativePath); nconf.set('relative_path', relativePath);
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567); 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') { if (nconf.get('isPrimary') === 'true') {
winston.info('Time: %s', (new Date()).toString()); winston.info('Time: %s', (new Date()).toString());

@ -96,24 +96,21 @@ function uploadAsFile(req, uploadedFile, callback) {
} }
function resizeImage(fileObj, callback) { function resizeImage(fileObj, callback) {
var fullPath;
async.waterfall([ async.waterfall([
function(next) { function(next) {
fullPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), '..', fileObj.url); image.size(fileObj.path, next);
image.size(fullPath, next);
}, },
function (imageData, next) { function (imageData, next) {
if (imageData.width < (parseInt(meta.config.maximumImageWidth, 10) || 760)) { if (imageData.width < (parseInt(meta.config.maximumImageWidth, 10) || 760)) {
return callback(null, fileObj); return callback(null, fileObj);
} }
var dirname = path.dirname(fullPath); var dirname = path.dirname(fileObj.path);
var extname = path.extname(fullPath); var extname = path.extname(fileObj.path);
var basename = path.basename(fullPath, extname); var basename = path.basename(fileObj.path, extname);
image.resizeImage({ image.resizeImage({
path: fullPath, path: fileObj.path,
target: path.join(dirname, basename + '-resized' + extname), target: path.join(dirname, basename + '-resized' + extname),
extension: extname, extension: extname,
width: parseInt(meta.config.maximumImageWidth, 10) || 760 width: parseInt(meta.config.maximumImageWidth, 10) || 760
@ -223,6 +220,7 @@ function saveFileToLocal(uploadedFile, callback) {
var filename = uploadedFile.name || 'upload'; var filename = uploadedFile.name || 'upload';
filename = Date.now() + '-' + validator.escape(filename.replace(extension, '')).substr(0, 255) + extension; filename = Date.now() + '-' + validator.escape(filename.replace(extension, '')).substr(0, 255) + extension;
file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) { file.saveFileToLocal(filename, 'files', uploadedFile.path, function(err, upload) {
if (err) { if (err) {
return callback(err); return callback(err);
@ -230,6 +228,7 @@ function saveFileToLocal(uploadedFile, callback) {
callback(null, { callback(null, {
url: nconf.get('relative_path') + upload.url, url: nconf.get('relative_path') + upload.url,
path: upload.path,
name: uploadedFile.name name: uploadedFile.name
}); });
}); });

@ -1,12 +1,12 @@
"use strict"; "use strict";
var fs = require('fs'), var fs = require('fs');
nconf = require('nconf'), var nconf = require('nconf');
path = require('path'), var path = require('path');
winston = require('winston'), var winston = require('winston');
jimp = require('jimp'), var jimp = require('jimp');
utils = require('../public/src/utils'); var utils = require('../public/src/utils');
var file = {}; var file = {};
@ -29,7 +29,8 @@ file.saveFileToLocal = function(filename, folder, tempPath, callback) {
is.on('end', function () { is.on('end', function () {
callback(null, { callback(null, {
url: nconf.get('upload_url') + folder + '/' + filename url: path.join(nconf.get('upload_url'), folder, filename),
path: uploadPath
}); });
}); });

Loading…
Cancel
Save