listSceneQualities.js 2.6 KB

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