fix download links on lbry.tv
This commit is contained in:
parent
e35fbdd86a
commit
baa73c7329
3 changed files with 15 additions and 10 deletions
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Reference in a new issue