remove dynamic streaming url generation
This commit is contained in:
parent
654e4d38df
commit
c0b4fff5d5
4 changed files with 6 additions and 46 deletions
|
@ -6,7 +6,7 @@ const config = {
|
|||
URL: 'https://lbry.tv',
|
||||
SITE_TITLE: 'lbry.tv',
|
||||
LBRY_TV_API: 'https://api.lbry.tv',
|
||||
LBRY_TV_STREAMING_API: 'https://lbryplayer.xyz',
|
||||
LBRY_TV_STREAMING_API: 'https://cdn.lbryplayer.xyz',
|
||||
WELCOME_VERSION: 1.0,
|
||||
};
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ function buildClaimOgMetadata(uri, claim, overrideOptions = {}) {
|
|||
let imageThumbnail;
|
||||
|
||||
if (Number(claim.fee) <= 0 && claim.source_media_type && claim.source_media_type.startsWith('image/')) {
|
||||
imageThumbnail = generateStreamUrl(claim.name, claim.claim_id, undefined, undefined, true);
|
||||
imageThumbnail = generateStreamUrl(claim.name, claim.claim_id);
|
||||
}
|
||||
const claimThumbnail = escapeHtmlProperty(claim.thumbnail_url) || imageThumbnail || `${URL}/v2-og.png`;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const { getHtml } = require('./html');
|
||||
const { Lbryio } = require('lbryinc/dist/bundle.es.js');
|
||||
const { generateStreamUrl, CONTINENT_COOKIE } = require('../../ui/util/lbrytv');
|
||||
const { generateStreamUrl } = require('../../ui/util/lbrytv');
|
||||
const fetch = require('node-fetch');
|
||||
const Router = require('@koa/router');
|
||||
|
||||
|
@ -12,32 +11,10 @@ const router = new Router();
|
|||
function getStreamUrl(ctx) {
|
||||
const { claimName, claimId } = ctx.params;
|
||||
|
||||
// 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 streamUrl = generateStreamUrl(claimName, claimId);
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
function getSupportedCDN(continent) {
|
||||
switch (continent) {
|
||||
case 'NA':
|
||||
case 'AS':
|
||||
case 'EU':
|
||||
return continent;
|
||||
default:
|
||||
return 'NA';
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchContinentCookie(ip) {
|
||||
return Lbryio.call('locale', 'get', { ip }, 'post').then(result => {
|
||||
const userContinent = getSupportedCDN(result.continent);
|
||||
return userContinent;
|
||||
});
|
||||
}
|
||||
|
||||
router.get(`/$/download/:claimName/:claimId`, async ctx => {
|
||||
const streamUrl = getStreamUrl(ctx);
|
||||
const downloadUrl = `${streamUrl}?download=1`;
|
||||
|
@ -50,15 +27,6 @@ router.get(`/$/stream/:claimName/:claimId`, async ctx => {
|
|||
});
|
||||
|
||||
router.get('*', async ctx => {
|
||||
const hasContinentCookie = ctx.cookies.get(CONTINENT_COOKIE);
|
||||
const ip = ctx.ip;
|
||||
|
||||
if (!hasContinentCookie) {
|
||||
try {
|
||||
const continentValue = await fetchContinentCookie(ip);
|
||||
ctx.cookies.set(CONTINENT_COOKIE, continentValue, { httpOnly: false });
|
||||
} catch (e) {}
|
||||
}
|
||||
const html = await getHtml(ctx);
|
||||
ctx.body = html;
|
||||
});
|
||||
|
|
|
@ -1,17 +1,9 @@
|
|||
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
|
||||
const { getCookie } = require('../../ui/util/saved-passwords');
|
||||
|
||||
const CONTINENT_COOKIE = 'continent';
|
||||
|
||||
function generateStreamUrl(claimName, claimId, apiUrl, streamingContinent, useDefaultServer) {
|
||||
let prefix = LBRY_TV_STREAMING_API || apiUrl;
|
||||
const continent = useDefaultServer ? undefined : streamingContinent || getCookie(CONTINENT_COOKIE);
|
||||
|
||||
if (continent && prefix.split('//').length > 1) {
|
||||
prefix = prefix.replace('//', '//' + continent + '.');
|
||||
}
|
||||
|
||||
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
|
||||
function generateStreamUrl(claimName, claimId) {
|
||||
return `${LBRY_TV_STREAMING_API}/content/claims/${claimName}/${claimId}/stream`;
|
||||
}
|
||||
|
||||
function generateEmbedUrl(claimName, claimId) {
|
||||
|
|
Loading…
Add table
Reference in a new issue