listSceneQualities.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict'
  2. import express from 'express'
  3. import { asyncMiddleware, checkRequiredParameters, getSceneFilesData } from '../functions'
  4. const router = express.Router()
  5. /**
  6. * @api {get} /listSceneQualities?sceneName=:sceneName Get a list of available qualities for a scene
  7. * @apiVersion 0.1.0
  8. * @apiName ListScenesQualities
  9. * @apiGroup API
  10. *
  11. * @apiDescription List all available qualities for a given scene
  12. *
  13. * @apiParam {String} sceneName The selected scene
  14. *
  15. * @apiExample Usage example
  16. * curl -i -L -X GET "http://diran.univ-littoral.fr/api/listSceneQualities?sceneName=bathroom"
  17. *
  18. * @apiSuccess {Number[]} data List of available qualities
  19. * @apiSuccessExample {json} Success response example
  20. * HTTP/1.1 200 OK /api/listSceneQualities?sceneName=bathroom
  21. * {
  22. * "data": [
  23. * 10,
  24. * 20,
  25. * 30
  26. * ]
  27. * }
  28. *
  29. * @apiError (Error 4xx) 400_[1] Missing parameter(s)
  30. * @apiErrorExample {json} Missing parameter
  31. * HTTP/1.1 400 Bad Request
  32. * {
  33. * "message": "Missing parameter(s). Required parameters : sceneName."
  34. * }
  35. *
  36. * @apiError (Error 4xx) 400_[2] The requested scene name is not valid
  37. * @apiErrorExample {json} Invalid scene name
  38. * HTTP/1.1 400 Bad Request
  39. * {
  40. * "message": "The requested scene name \"bathroom/../\" is not valid."
  41. * }
  42. *
  43. * @apiError (Error 5xx) 500_[1] Can't access the `IMAGES_PATH` directory
  44. * @apiErrorExample {json} Images directory not accessible
  45. * HTTP/1.1 500 Internal Server Error
  46. * {
  47. * "message": "Can't access the \"images\" directory. Check it exists and you have read permission on it"
  48. * }
  49. *
  50. * @apiError (Error 5xx) 500_[2] Failed to parse a file's name
  51. * @apiErrorExample {json} Failed to parse a file's name
  52. * HTTP/1.1 500 Internal Server Error
  53. * {
  54. * "message": "Failed to parse file names in the \"bathroom\"'s scene directory.",
  55. * "data": [
  56. * "The file name does not match convention (scene_000150.ext - /^(.*)?_([0-9]{2,})\\.(.*)$/) : \"bathroom_adz00020.png\".",
  57. * "The file name does not match convention (scene_000150.ext - /^(.*)?_([0-9]{2,})\\.(.*)$/) : \"bathroom_adz00020.png\"."
  58. * ]
  59. * }
  60. */
  61. // Route which returns a list of all available qualities for a scene
  62. router.get('/', asyncMiddleware(async (req, res) => {
  63. // Check the request contains all the required parameters
  64. checkRequiredParameters(['sceneName'], req.query)
  65. const { sceneName } = req.query
  66. const sceneData = await getSceneFilesData(sceneName)
  67. const data = Array.from(sceneData.values()).map(x => x.quality)
  68. res.json({ data })
  69. }))
  70. export default router