2022-05-13 12:17:51 +02:00
|
|
|
const { URL, 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
|
|
|
|
2022-05-13 14:04:26 +02:00
|
|
|
function generateEmbedUrl(claimName, claimId, startTime, referralLink, newestType) {
|
2020-10-05 22:30:44 +02:00
|
|
|
let urlParams = new URLSearchParams();
|
2022-01-31 16:24:38 +01:00
|
|
|
|
|
|
|
if (startTime) {
|
2022-01-31 19:29:43 +01:00
|
|
|
urlParams.append('t', escapeHtmlProperty(startTime));
|
2020-10-05 22:30:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (referralLink) {
|
2022-01-31 19:29:43 +01:00
|
|
|
urlParams.append('r', escapeHtmlProperty(referralLink));
|
2020-10-05 22:30:44 +02:00
|
|
|
}
|
|
|
|
|
2022-01-31 16:24:38 +01:00
|
|
|
const encodedUriName = encodeURIComponent(claimName).replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29');
|
2019-12-16 18:44:31 +01:00
|
|
|
|
2022-05-13 14:04:26 +02:00
|
|
|
let embedUrl;
|
|
|
|
if (newestType) {
|
|
|
|
embedUrl = `${URL}/$/embed/${escapeHtmlProperty(encodedUriName)}?feature=${newestType}`;
|
|
|
|
} else {
|
|
|
|
embedUrl = `${URL}/$/embed/${escapeHtmlProperty(encodedUriName)}/${escapeHtmlProperty(claimId)}`;
|
|
|
|
}
|
2022-01-31 16:24:38 +01:00
|
|
|
const embedUrlParams = urlParams.toString() ? `?${urlParams.toString()}` : '';
|
2022-01-29 21:24:35 +01:00
|
|
|
|
2022-01-31 16:24:38 +01:00
|
|
|
return `${embedUrl}${embedUrlParams}`;
|
|
|
|
}
|
2022-01-29 21:24:35 +01:00
|
|
|
|
2022-01-31 16:24:38 +01:00
|
|
|
function generateEmbedUrlEncoded(claimName, claimId, startTime, referralLink) {
|
|
|
|
return generateEmbedUrl(claimName, claimId, startTime, referralLink).replace(/\$/g, '%24');
|
2022-01-29 21:24:35 +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}`;
|
|
|
|
}
|
|
|
|
|
2022-05-13 14:04:26 +02:00
|
|
|
function generateNewestUrl(channelName, newestType) {
|
|
|
|
return `${URL}/$/${newestType}/${channelName}`;
|
|
|
|
}
|
|
|
|
|
2022-06-24 00:09:48 +02:00
|
|
|
function getThumbnailCardCdnUrl(url) {
|
2021-12-01 16:36:52 +01:00
|
|
|
if (
|
|
|
|
!THUMBNAIL_CARDS_CDN_URL ||
|
|
|
|
!url ||
|
2022-06-24 00:09:48 +02:00
|
|
|
(url && (url.includes('https://twitter-card') || url.includes('https://cards.odycdn.com')))
|
2021-12-01 16:36:52 +01:00
|
|
|
) {
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2021-12-22 15:18:14 +01:00
|
|
|
if (url && !url.startsWith('data:image')) {
|
2022-06-24 00:09:48 +02:00
|
|
|
return `${THUMBNAIL_CARDS_CDN_URL}${url}`;
|
2021-12-01 16:36:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getParameterByName(name, url) {
|
|
|
|
var match = RegExp('[?&]' + name + '=([^&]*)').exec(url);
|
|
|
|
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
|
|
|
|
}
|
|
|
|
|
2022-01-04 23:15:30 +01:00
|
|
|
function escapeHtmlProperty(property) {
|
|
|
|
return property
|
|
|
|
? String(property)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''')
|
|
|
|
: '';
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:45:19 +01:00
|
|
|
function unscapeHtmlProperty(property) {
|
|
|
|
return property
|
|
|
|
? String(property)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.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,
|
2022-01-29 21:24:35 +01:00
|
|
|
generateEmbedUrlEncoded,
|
2021-12-01 16:36:52 +01:00
|
|
|
getParameterByName,
|
2022-06-24 00:09:48 +02:00
|
|
|
getThumbnailCardCdnUrl,
|
2022-01-04 23:15:30 +01:00
|
|
|
escapeHtmlProperty,
|
2022-02-08 18:45:19 +01:00
|
|
|
unscapeHtmlProperty,
|
2022-05-13 14:04:26 +02:00
|
|
|
generateNewestUrl,
|
2021-12-01 16:36:52 +01:00
|
|
|
};
|