listScenes.js 721 B

1234567891011121314151617181920212223
  1. 'use strict'
  2. import express from 'express'
  3. import _fs, { promises as fs } from 'fs'
  4. import boom from 'boom'
  5. import { imagesPath } from '../../config'
  6. import { asyncMiddleware } from '../functions'
  7. const router = express.Router()
  8. // Route which returns a list of all available scenes in the `imagesPath` directory
  9. router.get('/', asyncMiddleware(async (req, res) => {
  10. try {
  11. // Return the list of all files in the images directory
  12. res.json(await fs.readdir(imagesPath))
  13. }
  14. catch (err) {
  15. // The images directory does not exist or is not accessible
  16. throw boom.badRequest(`Can't access the "${imagesPath}" directory. Check it exists and you have read permission on it.`)
  17. }
  18. }))
  19. export default router