mirror of https://github.com/status-im/codimd.git
support filesystem image upload
This commit is contained in:
parent
81b368c11c
commit
a5dad29300
16
app.js
16
app.js
|
@ -405,6 +405,7 @@ app.get('/me', function (req, res) {
|
||||||
//upload to imgur
|
//upload to imgur
|
||||||
app.post('/uploadimage', function (req, res) {
|
app.post('/uploadimage', function (req, res) {
|
||||||
var form = new formidable.IncomingForm();
|
var form = new formidable.IncomingForm();
|
||||||
|
|
||||||
form.uploadDir = "public/uploads";
|
form.uploadDir = "public/uploads";
|
||||||
form.keepExtensions = true;
|
form.keepExtensions = true;
|
||||||
|
|
||||||
|
@ -414,8 +415,19 @@ app.post('/uploadimage', function (req, res) {
|
||||||
} else {
|
} else {
|
||||||
if (config.debug)
|
if (config.debug)
|
||||||
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image));
|
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image));
|
||||||
imgur.setClientId(config.imgur.clientID);
|
|
||||||
try {
|
try {
|
||||||
|
switch (config.imageUploadType) {
|
||||||
|
case 'filesystem':
|
||||||
|
res.send({
|
||||||
|
link: files.image.path.match(/^public(.+$)/)[1]
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'imgur':
|
||||||
|
default:
|
||||||
|
imgur.setClientId(config.imgur.clientID);
|
||||||
imgur.uploadFile(files.image.path)
|
imgur.uploadFile(files.image.path)
|
||||||
.then(function (json) {
|
.then(function (json) {
|
||||||
if (config.debug)
|
if (config.debug)
|
||||||
|
@ -428,6 +440,8 @@ app.post('/uploadimage', function (req, res) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return res.status(500).end('upload image error');
|
return res.status(500).end('upload image error');
|
||||||
});
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return res.status(500).end('upload image error');
|
return res.status(500).end('upload image error');
|
||||||
|
|
|
@ -56,6 +56,9 @@ var heartbeattimeout = config.heartbeattimeout || 10000;
|
||||||
// document
|
// document
|
||||||
var documentmaxlength = config.documentmaxlength || 100000;
|
var documentmaxlength = config.documentmaxlength || 100000;
|
||||||
|
|
||||||
|
// image upload setting, available options are imgur/s3/filesystem
|
||||||
|
var imageUploadType = config.imageUploadType || 'imgur';
|
||||||
|
|
||||||
// auth
|
// auth
|
||||||
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? {
|
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? {
|
||||||
clientID: process.env.HMD_FACEBOOK_CLIENTID,
|
clientID: process.env.HMD_FACEBOOK_CLIENTID,
|
||||||
|
@ -139,5 +142,6 @@ module.exports = {
|
||||||
gitlab: gitlab,
|
gitlab: gitlab,
|
||||||
dropbox: dropbox,
|
dropbox: dropbox,
|
||||||
google: google,
|
google: google,
|
||||||
imgur: imgur
|
imgur: imgur,
|
||||||
|
imageUploadType: imageUploadType
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue