|
@@ -3,30 +3,21 @@
|
|
import express from 'express'
|
|
import express from 'express'
|
|
import _fs, { promises as fs } from 'fs'
|
|
import _fs, { promises as fs } from 'fs'
|
|
import boom from 'boom'
|
|
import boom from 'boom'
|
|
-import { imagesPath } from '../config'
|
|
|
|
|
|
+import { imagesPath } from '../../config'
|
|
import { asyncMiddleware } from '../functions'
|
|
import { asyncMiddleware } from '../functions'
|
|
|
|
|
|
const router = express.Router()
|
|
const router = express.Router()
|
|
|
|
|
|
// Route which returns a list of all available scenes in the `imagesPath` directory
|
|
// Route which returns a list of all available scenes in the `imagesPath` directory
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Get a list of all available scenes
|
|
|
|
- *
|
|
|
|
- * @returns {string[]} the available scenes
|
|
|
|
- */
|
|
|
|
-const getAvailableScenes = async () => {
|
|
|
|
|
|
+router.get('/', asyncMiddleware(async (req, res) => {
|
|
try {
|
|
try {
|
|
- // Check if the directory which contains images exists
|
|
|
|
- await fs.access(imagesPath, _fs.constants.R_OK)
|
|
|
|
|
|
+ // Return the list of all files in the images directory
|
|
|
|
+ res.json(await fs.readdir(imagesPath))
|
|
}
|
|
}
|
|
catch (err) {
|
|
catch (err) {
|
|
// The images directory does not exist or is not accessible
|
|
// The images directory does not exist or is not accessible
|
|
throw boom.badRequest(`Can't access the "${imagesPath}" directory. Check it exists and you have read permission on it.`)
|
|
throw boom.badRequest(`Can't access the "${imagesPath}" directory. Check it exists and you have read permission on it.`)
|
|
}
|
|
}
|
|
- return fs.readdir(imagesPath)
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-router.get('/', asyncMiddleware(async (req, res) => res.json(await getAvailableScenes())))
|
|
|
|
|
|
+}))
|
|
|
|
|
|
export default router
|
|
export default router
|