We have various places with overly simple if statements that could be handled by our logging library. Also a lot of those logs are not marked as debug logs but as info logs, which can cause confusion during debugging. This patch removed unneeded if clauses around debug logging statements, reworks debug log messages towards ECMA templates and add some new logging statements which might be helpful in order to debug things like image uploads. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 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 = config.uploadsPath
 | 
						|
  }
 | 
						|
 | 
						|
  form.parse(req, function (err, fields, files) {
 | 
						|
    if (err || !files.image || !files.image.path) {
 | 
						|
      logger.error(`formidable error: ${err}`)
 | 
						|
      response.errorForbidden(res)
 | 
						|
    } else {
 | 
						|
      logger.debug(`SERVER received uploadimage: ${JSON.stringify(files.image)}`)
 | 
						|
 | 
						|
      const uploadProvider = require('./' + config.imageUploadType)
 | 
						|
      logger.debug(`imageRouter: Uploading ${files.image.path} using ${config.imageUploadType}`)
 | 
						|
      uploadProvider.uploadImage(files.image.path, function (err, url) {
 | 
						|
        if (err !== null) {
 | 
						|
          logger.error(err)
 | 
						|
          return res.status(500).end('upload image error')
 | 
						|
        }
 | 
						|
        logger.debug(`SERVER sending ${url} to client`)
 | 
						|
        res.send({
 | 
						|
          link: url
 | 
						|
        })
 | 
						|
      })
 | 
						|
    }
 | 
						|
  })
 | 
						|
})
 |