api.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return res.json({ private: config.private })
  7. })
  8. routes.get ('/verify', (req, res, next) => {
  9. let type = req.headers.type
  10. let token = req.headers.token
  11. if(type === undefined) return res.json({ success: false, description: 'No type provided.' })
  12. if(token === undefined) return res.json({ success: false, description: 'No token provided.' })
  13. if(type !== 'client' && type !== 'admin') return res.json({ success: false, description: 'Wrong type provided.' })
  14. if(type === 'client'){
  15. if(token !== config.clientToken) return res.json({ success: false, description: 'Token mismatch.' })
  16. return res.json({ success: true })
  17. }
  18. if(type === 'admin'){
  19. if(token !== config.adminToken) return res.json({ success: false, description: 'Token mismatch.' })
  20. return res.json({ success: true })
  21. }
  22. return res.json({ success: false, description: '(╯°□°)╯︵ ┻━┻' })
  23. })
  24. routes.get('/info', (req, res, next) => {
  25. if(config.private === true)
  26. if(req.headers.auth !== config.clientToken)
  27. return res.status(401).send('not-authorized')
  28. return res.json({
  29. maxFileSize: config.uploads.maxsize.slice(0, -2)
  30. })
  31. })
  32. routes.get ('/uploads', (req, res, next) => uploadController.list(req, res))
  33. routes.post ('/upload', (req, res, next) => uploadController.upload(req, res, next))
  34. routes.get ('/gallery', (req, res, next) => galleryController.list(req, res, next))
  35. routes.get ('/gallery/test', (req, res, next) => galleryController.test(req, res, next))
  36. module.exports = routes