mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
closes #4645
This commit is contained in:
@@ -198,7 +198,7 @@ function uploadFile(uid, uploadedFile, callback) {
|
|||||||
|
|
||||||
function saveFileToLocal(uploadedFile, callback) {
|
function saveFileToLocal(uploadedFile, callback) {
|
||||||
var extension = path.extname(uploadedFile.name);
|
var extension = path.extname(uploadedFile.name);
|
||||||
if (!extension) {
|
if (!extension && uploadedFile.type) {
|
||||||
extension = '.' + mime.extension(uploadedFile.type);
|
extension = '.' + mime.extension(uploadedFile.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ var path = require('path');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
var Jimp = require('jimp');
|
var Jimp = require('jimp');
|
||||||
|
var mime = require('mime');
|
||||||
|
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var file = require('../file');
|
var file = require('../file');
|
||||||
@@ -29,6 +30,7 @@ module.exports = function(Groups) {
|
|||||||
|
|
||||||
var tempPath = data.file ? data.file : '';
|
var tempPath = data.file ? data.file : '';
|
||||||
var url;
|
var url;
|
||||||
|
var type = data.file ? mime.lookup(data.file) : 'image/png';
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -41,7 +43,8 @@ module.exports = function(Groups) {
|
|||||||
tempPath = _tempPath;
|
tempPath = _tempPath;
|
||||||
uploadsController.uploadGroupCover(uid, {
|
uploadsController.uploadGroupCover(uid, {
|
||||||
name: 'groupCover',
|
name: 'groupCover',
|
||||||
path: tempPath
|
path: tempPath,
|
||||||
|
type: type
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (uploadData, next) {
|
function (uploadData, next) {
|
||||||
@@ -54,7 +57,8 @@ module.exports = function(Groups) {
|
|||||||
function (next) {
|
function (next) {
|
||||||
uploadsController.uploadGroupCover(uid, {
|
uploadsController.uploadGroupCover(uid, {
|
||||||
name: 'groupCoverThumb',
|
name: 'groupCoverThumb',
|
||||||
path: tempPath
|
path: tempPath,
|
||||||
|
type: type
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (uploadData, next) {
|
function (uploadData, next) {
|
||||||
@@ -104,7 +108,7 @@ module.exports = function(Groups) {
|
|||||||
md5sum = md5sum.digest('hex');
|
md5sum = md5sum.digest('hex');
|
||||||
|
|
||||||
// Save image
|
// Save image
|
||||||
var tempPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), md5sum);
|
var tempPath = path.join(nconf.get('base_dir'), nconf.get('upload_path'), md5sum) + '.png';
|
||||||
var buffer = new Buffer(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
|
var buffer = new Buffer(imageData.slice(imageData.indexOf('base64') + 7), 'base64');
|
||||||
|
|
||||||
fs.writeFile(tempPath, buffer, {
|
fs.writeFile(tempPath, buffer, {
|
||||||
|
|||||||
Reference in New Issue
Block a user