From baa73c732903f172f7578a5d499f3fed2b29c879 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 25 Mar 2020 17:49:14 -0400 Subject: [PATCH] fix download links on lbry.tv --- lbrytv/src/routes.js | 11 ++++++++--- ui/component/fileViewerInitiator/view.jsx | 3 ++- ui/util/lbrytv.js | 11 +++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lbrytv/src/routes.js b/lbrytv/src/routes.js index 6bf96dbb8..9ccacdecd 100644 --- a/lbrytv/src/routes.js +++ b/lbrytv/src/routes.js @@ -1,13 +1,18 @@ const { getHtml } = require('./html'); -const { generateDownloadUrl } = require('../../ui/util/lbrytv'); -const { LBRY_TV_API } = require('../../config'); +const { generateStreamUrl, CONTINENT_COOKIE } = require('../../ui/util/lbrytv'); const Router = require('@koa/router'); const router = new Router(); router.get(`/$/download/:claimName/:claimId`, async ctx => { const { claimName, claimId } = ctx.params; - const downloadUrl = generateDownloadUrl(claimName, claimId); + + // hack to get around how we managing the continent cookie + // defaulting to "NA" becasue saved-passwords.js assumes it's in the browser and won't work properly + // changes need to be made to that to better work with the server + const streamingContinentCookie = ctx.cookies.get(CONTINENT_COOKIE) || 'NA'; + const streamUrl = generateStreamUrl(claimName, claimId, undefined, streamingContinentCookie); + const downloadUrl = `${streamUrl}?download=1`; ctx.redirect(downloadUrl); }); diff --git a/ui/component/fileViewerInitiator/view.jsx b/ui/component/fileViewerInitiator/view.jsx index c8690b7fd..73393f12c 100644 --- a/ui/component/fileViewerInitiator/view.jsx +++ b/ui/component/fileViewerInitiator/view.jsx @@ -9,6 +9,7 @@ import Button from 'component/button'; import isUserTyping from 'util/detect-typing'; import Yrbl from 'component/yrbl'; import I18nMessage from 'component/i18nMessage'; +import { generateDownloadUrl } from 'util/lbrytv'; const SPACE_BAR_KEYCODE = 32; @@ -61,7 +62,7 @@ export default function FileViewerInitiator(props: Props) { const supported = IS_WEB ? (!cost && isStreamable) || webStreamOnly || forceVideo : true; const { name, claim_id: claimId, value } = claim; const fileName = value && value.source && value.source.name; - const downloadUrl = `/$/download/${name}/${claimId}`; + const downloadUrl = generateDownloadUrl(name, claimId); function getTitle() { let message = __('Unsupported File'); diff --git a/ui/util/lbrytv.js b/ui/util/lbrytv.js index 24ba80717..d5cae0aa0 100644 --- a/ui/util/lbrytv.js +++ b/ui/util/lbrytv.js @@ -4,9 +4,9 @@ const { getCookie, setCookie } = require('../../ui/util/saved-passwords'); const CONTINENT_COOKIE = 'continent'; -function generateStreamUrl(claimName, claimId, apiUrl) { +function generateStreamUrl(claimName, claimId, apiUrl, streamingContinent) { let prefix = LBRY_TV_STREAMING_API || apiUrl; - const continent = getCookie(CONTINENT_COOKIE); + const continent = streamingContinent || getCookie(CONTINENT_COOKIE); if (continent && prefix.split('//').length > 1) { prefix = prefix.replace('//', '//' + continent + '.'); @@ -34,10 +34,9 @@ function generateEmbedUrl(claimName, claimId) { return `${URL}/$/embed/${claimName}/${claimId}`; } -function generateDownloadUrl(claimName, claimId, apiUrl) { - const streamUrl = generateStreamUrl(claimName, claimId, apiUrl); - return `${streamUrl}?download=1`; +function generateDownloadUrl(claimName, claimId) { + return `/$/download/${claimName}/${claimId}`; } // module.exports needed since the web server imports this function -module.exports = { generateStreamUrl, generateEmbedUrl, generateDownloadUrl }; +module.exports = { generateStreamUrl, generateEmbedUrl, generateDownloadUrl, CONTINENT_COOKIE };