summaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorYukai Huang2016-11-14 17:07:07 +0800
committerYukai Huang2016-11-14 17:07:07 +0800
commita5dad2930037b466542f1e77d3cbb0d0cbf184aa (patch)
tree9a987f37d91b11fc36898d9e6c75767bfd7255b9 /app.js
parent81b368c11c81c7c759d4abcdff455121f2e87d9a (diff)
support filesystem image upload
Diffstat (limited to 'app.js')
-rw-r--r--app.js38
1 files changed, 26 insertions, 12 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');