api.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. const Security = require('../src/security.js');
  2. module.exports = { register: app => {
  3. app.router.get("/api/access/list", (req, res) => {
  4. app.routerUtils.onApiRequest(req, res);
  5. app.routerUtils.jsonResponse(res, req.accessList);
  6. });
  7. app.router.post("/api/access/link", async (req, res) => { // /api/access/link, post: { linkId: string }
  8. app.routerUtils.onApiRequest(req, res);
  9. if (!req.post?.linkId?.length)
  10. return app.routerUtils.httpResponse(res, 400, "Missing argument");
  11. let access = Security.addLinkToSession(req, req.post.linkId);
  12. app.routerUtils.jsonResponse(res, access);
  13. });
  14. app.router.del("/api/access/:id", (req, res) => {
  15. app.routerUtils.onApiRequest(req, res);
  16. Security.removeFromSession(req, req.params.id);
  17. let access = Security.getAccessList(req.cookies);
  18. app.routerUtils.jsonResponse(res, access);
  19. });
  20. app.router.get("/api/media/list", async (req, res) => {
  21. app.routerUtils.onApiRequest(req, res);
  22. app.routerUtils.jsonResponse(res, {
  23. start: 0,
  24. end: 0,
  25. data: []
  26. });
  27. });
  28. }};