sprites.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import fs from "fs";
  2. import express from "express";
  3. const router = express.Router();
  4. import { extractFrames } from "../../src/app";
  5. router.get("/", async (req: any, res: any, next: any) => {
  6. // return list of sprites
  7. try {
  8. res.json({ sprites: [1] });
  9. } catch (err) {
  10. next(err);
  11. }
  12. });
  13. router.get("/:id", async (req: any, res: any, next: any) => {
  14. // return requested sprites
  15. try {
  16. const files = ["./public/sprites/sprite-0.jpeg"]
  17. res.json({ sprites: files.map(file=> fs.readFileSync(file, 'utf8'))
  18. });
  19. } catch (err) {
  20. next(err);
  21. }
  22. });
  23. router.post("/", async (req: any, res: any, next: any) => {
  24. // generate sprites
  25. const { videoId } = req.body;
  26. if (!videoId)
  27. res.json({ error: "Post `{ videoId: number; }` to generate a sprite." });
  28. res.json({ error: "Not implemented" });
  29. try {
  30. extractFrames("./frames.mp4", videoId);
  31. } catch (err) {
  32. next(err);
  33. }
  34. });
  35. router.put("/:id", async (req: any, res: any, next: any) => {
  36. // update submitted sprite
  37. try {
  38. res.json({ error: "Not implemented" });
  39. } catch (err) {
  40. next(err);
  41. }
  42. });
  43. router.post("/:id/delete", async (req: any, res: any, next: any) => {
  44. // trash sprite
  45. try {
  46. res.json({ error: "Not implemented" });
  47. } catch (err) {
  48. next(err);
  49. }
  50. });
  51. module.exports = router;