lbry-desktop/web/src/routes.js

35 lines
900 B
JavaScript
Raw Normal View History

2019-11-07 14:39:22 -05:00
const { getHtml } = require('./html');
const { generateStreamUrl } = require('../../ui/util/web');
const fetch = require('node-fetch');
2019-11-07 14:39:22 -05:00
const Router = require('@koa/router');
2019-11-11 13:19:31 -05:00
// So any code from 'lbry-redux'/'lbryinc' that uses `fetch` can be run on the server
global.fetch = fetch;
2019-11-07 14:39:22 -05:00
const router = new Router();
2020-03-27 14:57:03 -04:00
function getStreamUrl(ctx) {
const { claimName, claimId } = ctx.params;
2020-03-25 17:49:14 -04:00
const streamUrl = generateStreamUrl(claimName, claimId);
2020-03-27 14:57:03 -04:00
return streamUrl;
}
router.get(`/$/download/:claimName/:claimId`, async ctx => {
const streamUrl = getStreamUrl(ctx);
2020-03-25 17:49:14 -04:00
const downloadUrl = `${streamUrl}?download=1`;
ctx.redirect(downloadUrl);
});
2020-03-27 14:57:03 -04:00
router.get(`/$/stream/:claimName/:claimId`, async ctx => {
const streamUrl = getStreamUrl(ctx);
ctx.redirect(streamUrl);
});
2019-11-07 14:39:22 -05:00
router.get('*', async ctx => {
const html = await getHtml(ctx);
ctx.body = html;
});
module.exports = router;