2021-12-01 16:36:52 +01:00
|
|
|
const { URL, LBRY_WEB_STREAMING_API, THUMBNAIL_CARDS_CDN_URL } = require('../../config');
|
2020-03-17 19:58:34 +01:00
|
|
|
|
|
|
|
const CONTINENT_COOKIE = 'continent';
|
2019-12-16 18:44:31 +01:00
|
|
|
|
2020-05-07 16:52:55 +02:00
|
|
|
function generateStreamUrl(claimName, claimId) {
|
2021-08-06 22:53:01 +02:00
|
|
|
return `${LBRY_WEB_STREAMING_API}/content/claims/${encodeURIComponent(claimName)
|
|
|
|
.replace(/'/g, '%27')
|
|
|
|
.replace(/\(/g, '%28')
|
|
|
|
.replace(/\)/g, '%29')}/${claimId}/stream`;
|
2019-10-21 16:50:34 +02:00
|
|
|
}
|
2019-10-22 16:40:57 +02:00
|
|
|
|
2020-10-05 22:30:44 +02:00
|
|
|
function generateEmbedUrl(claimName, claimId, includeStartTime, startTime, referralLink) {
|
|
|
|
let urlParams = new URLSearchParams();
|
|
|
|
if (includeStartTime && startTime) {
|
|
|
|
urlParams.append('t', startTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (referralLink) {
|
|
|
|
urlParams.append('r', referralLink);
|
|
|
|
}
|
|
|
|
|
2021-08-06 22:53:01 +02:00
|
|
|
return `${URL}/$/embed/${encodeURIComponent(claimName)
|
|
|
|
.replace(/'/g, '%27')
|
|
|
|
.replace(/\(/g, '%28')
|
|
|
|
.replace(/\)/g, '%29')}/${claimId}?${urlParams.toString()}`;
|
2019-12-16 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
2021-12-01 16:36:52 +01:00
|
|
|
function generateEmbedIframeData(src) {
|
|
|
|
const width = '560';
|
|
|
|
const height = '315';
|
|
|
|
const html = `<iframe id="odysee-iframe" width="${width}" height="${height}" src="${src}" allowfullscreen></iframe>`;
|
|
|
|
|
|
|
|
return { html, width, height };
|
|
|
|
}
|
|
|
|
|
2020-03-25 22:49:14 +01:00
|
|
|
function generateDownloadUrl(claimName, claimId) {
|
2020-03-30 15:14:01 +02:00
|
|
|
return `${URL}/$/download/${claimName}/${claimId}`;
|
2020-01-07 19:17:43 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 19:57:03 +01:00
|
|
|
function generateDirectUrl(claimName, claimId) {
|
|
|
|
return `${URL}/$/stream/${claimName}/${claimId}`;
|
|
|
|
}
|
|
|
|
|
2021-12-01 16:36:52 +01:00
|
|
|
function getThumbnailCdnUrl(url) {
|
|
|
|
if (
|
|
|
|
!THUMBNAIL_CARDS_CDN_URL ||
|
|
|
|
!url ||
|
|
|
|
(url && (url.includes('https://twitter-card') || url.includes('https://cards.odysee.com')))
|
|
|
|
) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
const encodedURL = Buffer.from(url).toString('base64');
|
|
|
|
return `${THUMBNAIL_CARDS_CDN_URL}${encodedURL}.jpg`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getParameterByName(name, url) {
|
|
|
|
var match = RegExp('[?&]' + name + '=([^&]*)').exec(url);
|
|
|
|
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
// module.exports needed since the web server imports this function
|
2021-12-01 16:36:52 +01:00
|
|
|
module.exports = {
|
|
|
|
CONTINENT_COOKIE,
|
|
|
|
generateDirectUrl,
|
|
|
|
generateDownloadUrl,
|
|
|
|
generateEmbedIframeData,
|
|
|
|
generateEmbedUrl,
|
|
|
|
generateStreamUrl,
|
|
|
|
getParameterByName,
|
|
|
|
getThumbnailCdnUrl,
|
|
|
|
};
|