Generate visual representations of the networks underlying video-gamebooks on YouTube
https://youtube-maze.delab.re/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
import express from 'express';
|
|
import { exploreVideos, toGraphviz } from '../lib/explore.mjs';
|
|
import { toSVG } from '../lib/graphviz.mjs';
|
|
|
|
const router = express.Router();
|
|
export default router;
|
|
|
|
const statusPending = Symbol('PENDING');
|
|
const statusError = Symbol('ERROR');
|
|
const cache = Object.create(null);
|
|
|
|
router.get('/:videoId', async (req, res) => {
|
|
const {videoId} = req.params;
|
|
|
|
if (videoId in cache)
|
|
{
|
|
if (cache[videoId] === statusPending)
|
|
{
|
|
res.header('Refresh', '5');
|
|
res.send('Exploration in progress… Please wait.');
|
|
}
|
|
else if (cache[videoId] === statusError)
|
|
{
|
|
res.status(500).send('Error');
|
|
}
|
|
else
|
|
{
|
|
res.send(cache[videoId]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
cache[videoId] = statusPending;
|
|
res.header('Refresh', '1');
|
|
res.send('Exploration in progress… Please wait.');
|
|
|
|
try
|
|
{
|
|
const graph = await exploreVideos(req.params.videoId);
|
|
const graphviz = toGraphviz(...graph);
|
|
const svg = await toSVG(graphviz);
|
|
cache[videoId] = svg;
|
|
}
|
|
catch (err)
|
|
{
|
|
console.error(err);
|
|
cache[videoId] = statusError;
|
|
}
|
|
}
|
|
});
|
|
|