From 50bea913ec616fcf81199055f2b08b13e3001e16 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 16 Dec 2019 12:44:31 -0500 Subject: [PATCH] use custom endpoint for lbry.tv embeds --- lbrytv/src/routes.js | 9 +++++---- ui/component/embedArea/view.jsx | 5 ++--- ui/util/lbrytv.js | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lbrytv/src/routes.js b/lbrytv/src/routes.js index 785701572..cd04ab6d6 100644 --- a/lbrytv/src/routes.js +++ b/lbrytv/src/routes.js @@ -6,10 +6,11 @@ const send = require('koa-send'); const router = new Router(); -// TODO -// router.get(`/embed/:claimName/:claimId`, async ctx => { -// Proxy request through lbrytv -// }); +router.get(`/embed/:claimName/:claimId`, async ctx => { + const { claimName, claimId } = ctx.params; + const streamUrl = generateStreamUrl(claimName, claimId, LBRY_TV_API); + ctx.redirect(streamUrl); +}); router.get('*', async ctx => { const html = await getHtml(ctx); diff --git a/ui/component/embedArea/view.jsx b/ui/component/embedArea/view.jsx index fca7b7493..d1be7fb74 100644 --- a/ui/component/embedArea/view.jsx +++ b/ui/component/embedArea/view.jsx @@ -3,8 +3,7 @@ import * as ICONS from 'constants/icons'; import { FormField } from 'component/common/form'; import Button from 'component/button'; import React, { useRef } from 'react'; -import { generateStreamUrl } from 'util/lbrytv'; -import { LBRY_TV_API } from 'config'; +import { generateEmbedUrl } from 'util/lbrytv'; type Props = { copyable: string, @@ -19,7 +18,7 @@ export default function EmbedArea(props: Props) { const { claim_id: claimId, name } = claim; const input = useRef(); - const streamUrl = generateStreamUrl(name, claimId, LBRY_TV_API); + const streamUrl = generateEmbedUrl(name, claimId); let embedText = ``; function copyToClipboard() { diff --git a/ui/util/lbrytv.js b/ui/util/lbrytv.js index 5f4152f50..2b75e84af 100644 --- a/ui/util/lbrytv.js +++ b/ui/util/lbrytv.js @@ -1,7 +1,13 @@ +const { URL } = require('../../config'); + function generateStreamUrl(claimName, claimId, apiUrl) { const prefix = process.env.SDK_API_URL || apiUrl; return `${prefix}/content/claims/${claimName}/${claimId}/stream`; } +function generateEmbedUrl(claimName, claimId) { + return `${URL}/embed/${claimName}/${claimId}`; +} + // module.exports needed since the web server imports this function -module.exports = { generateStreamUrl }; +module.exports = { generateStreamUrl, generateEmbedUrl };