summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js38
-rw-r--r--lib/config.js6
2 files changed, 31 insertions, 13 deletions
diff --git a/app.js b/app.js
index 30baf1ca..f5f8a3a5 100644
--- a/app.js
+++ b/app.js
@@ -405,6 +405,7 @@ app.get('/me', function (req, res) {
//upload to imgur
app.post('/uploadimage', function (req, res) {
var form = new formidable.IncomingForm();
+
form.uploadDir = "public/uploads";
form.keepExtensions = true;
@@ -414,20 +415,33 @@ app.post('/uploadimage', function (req, res) {
} else {
if (config.debug)
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image));
- imgur.setClientId(config.imgur.clientID);
+
try {
- imgur.uploadFile(files.image.path)
- .then(function (json) {
- if (config.debug)
- logger.info('SERVER uploadimage success: ' + JSON.stringify(json));
- res.send({
- link: json.data.link.replace(/^http:\/\//i, 'https://')
- });
- })
- .catch(function (err) {
- logger.error(err);
- return res.status(500).end('upload image error');
+ 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)
+ .then(function (json) {
+ if (config.debug)
+ logger.info('SERVER uploadimage success: ' + JSON.stringify(json));
+ res.send({
+ link: json.data.link.replace(/^http:\/\//i, 'https://')
+ });
+ })
+ .catch(function (err) {
+ logger.error(err);
+ return res.status(500).end('upload image error');
+ });
+ break;
+ }
} catch (err) {
logger.error(err);
return res.status(500).end('upload image error');
diff --git a/lib/config.js b/lib/config.js
index 76b21f0d..001cc8fa 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -56,6 +56,9 @@ var heartbeattimeout = config.heartbeattimeout || 10000;
// document
var documentmaxlength = config.documentmaxlength || 100000;
+// image upload setting, available options are imgur/s3/filesystem
+var imageUploadType = config.imageUploadType || 'imgur';
+
// auth
var facebook = (process.env.HMD_FACEBOOK_CLIENTID && process.env.HMD_FACEBOOK_CLIENTSECRET) ? {
clientID: process.env.HMD_FACEBOOK_CLIENTID,
@@ -139,5 +142,6 @@ module.exports = {
gitlab: gitlab,
dropbox: dropbox,
google: google,
- imgur: imgur
+ imgur: imgur,
+ imageUploadType: imageUploadType
};