api.js 882 B

123456789101112131415161718192021222324252627
  1. const config = require('../config.js')
  2. const routes = require('express').Router()
  3. const uploadController = require('../controllers/uploadController')
  4. const galleryController = require('../controllers/galleryController')
  5. routes.get ('/check', (req, res, next) => {
  6. if(config.TOKEN === '')
  7. return res.json({token: false})
  8. return res.json({token: true})
  9. })
  10. routes.get ('/info', (req, res, next) => {
  11. if(config.TOKEN !== '')
  12. if(req.headers.auth !== config.TOKEN)
  13. return res.status(401).send('not-authorized')
  14. return res.json({
  15. maxFileSize: config.uploads.maxsize.slice(0, -2)
  16. })
  17. })
  18. routes.post ('/upload', (req, res, next) => uploadController.upload(req, res, next))
  19. routes.get ('/gallery', (req, res, next) => galleryController.list(req, res, next))
  20. routes.get ('/gallery/test', (req, res, next) => galleryController.test(req, res, next))
  21. module.exports = routes