galleryController.js 746 B

12345678910111213141516171819202122232425262728293031323334
  1. const config = require('../config.js')
  2. const db = require('knex')(config.database)
  3. let galleryController = {}
  4. galleryController.list = function(req, res, next){
  5. if(config.TOKEN !== '')
  6. if(req.headers.auth !== config.TOKEN)
  7. return res.status(401).send('not-authorized')
  8. db.table('gallery').select('id', 'name').then((data) => {
  9. res.json({ data })
  10. })
  11. }
  12. galleryController.test = function(req, res, next){
  13. if(config.TOKEN !== '')
  14. if(req.headers.auth !== config.TOKEN)
  15. return res.status(401).send('not-authorized')
  16. let testdata = [
  17. {name: 'Test 1'},
  18. {name: 'Test 2'},
  19. {name: 'Test 3'},
  20. {name: 'Test 4'},
  21. {name: 'Test 5'}
  22. ]
  23. db.table('gallery').insert(testdata).then(() => {})
  24. }
  25. module.exports = galleryController