api.js 961 B

12345678910111213141516171819202122232425262728
  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.get ('/uploads', (req, res, next) => uploadController.list(req, res))
  19. routes.post ('/upload', (req, res, next) => uploadController.upload(req, res, next))
  20. routes.get ('/gallery', (req, res, next) => galleryController.list(req, res, next))
  21. routes.get ('/gallery/test', (req, res, next) => galleryController.test(req, res, next))
  22. module.exports = routes