mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-12-26 04:13:05 +00:00
2411dffa2c
This refactors the configs a bit to now use camel case everywhere. This change should help to clean up the config interface and make it better understandable. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
'use strict'
|
|
|
|
const Router = require('express').Router
|
|
const formidable = require('formidable')
|
|
|
|
const config = require('../../config')
|
|
const logger = require('../../logger')
|
|
const response = require('../../response')
|
|
|
|
const imageRouter = module.exports = Router()
|
|
|
|
// upload image
|
|
imageRouter.post('/uploadimage', function (req, res) {
|
|
var form = new formidable.IncomingForm()
|
|
|
|
form.keepExtensions = true
|
|
|
|
if (config.imageUploadType === 'filesystem') {
|
|
form.uploadDir = 'public/uploads'
|
|
}
|
|
|
|
form.parse(req, function (err, fields, files) {
|
|
if (err || !files.image || !files.image.path) {
|
|
response.errorForbidden(res)
|
|
} else {
|
|
if (config.debug) {
|
|
logger.info('SERVER received uploadimage: ' + JSON.stringify(files.image))
|
|
}
|
|
|
|
const uploadProvider = require('./' + config.imageUploadType)
|
|
uploadProvider.uploadImage(files.image.path, function (err, url) {
|
|
if (err !== null) {
|
|
logger.error(err)
|
|
return res.status(500).end('upload image error')
|
|
}
|
|
res.send({
|
|
link: url
|
|
})
|
|
})
|
|
}
|
|
})
|
|
})
|