Take 2 encoding test

This commit is contained in:
Thomas Zarebczan 2022-01-29 15:24:35 -05:00
parent 185c2d8496
commit 5ee2f40608
No known key found for this signature in database
GPG key ID: D505010BDB4364BC
2 changed files with 19 additions and 2 deletions

View file

@ -25,6 +25,22 @@ function generateEmbedUrl(claimName, claimId, includeStartTime, startTime, refer
.replace(/\)/g, '%29')}/${claimId}?${urlParams.toString()}`;
}
function generateEmbedUrlEncoded(claimName, claimId, includeStartTime, startTime, referralLink) {
let urlParams = new URLSearchParams();
if (includeStartTime && startTime) {
urlParams.append('t', startTime);
}
if (referralLink) {
urlParams.append('r', referralLink);
}
return `${URL}/%24/embed/${encodeURIComponent(claimName)
.replace(/'/g, '%27')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')}/${claimId}?${urlParams.toString()}`;
}
function generateEmbedIframeData(src) {
const width = '560';
const height = '315';
@ -79,6 +95,7 @@ module.exports = {
generateDownloadUrl,
generateEmbedIframeData,
generateEmbedUrl,
generateEmbedUrlEncoded,
generateStreamUrl,
getParameterByName,
getThumbnailCdnUrl,

View file

@ -2,7 +2,7 @@ const { URL, SITE_NAME, PROXY_URL, THUMBNAIL_HEIGHT, THUMBNAIL_WIDTH } = require
const {
generateEmbedIframeData,
generateEmbedUrl,
generateEmbedUrlEncoded,
getParameterByName,
getThumbnailCdnUrl,
escapeHtmlProperty,
@ -54,7 +54,7 @@ function generateOEmbedData(claim, referrerQuery) {
const authorUrl = authorClaim ? `${URL}/${authorUrlPath}` : null;
const thumbnailUrl = value && value.thumbnail && value.thumbnail.url && getThumbnailCdnUrl(value.thumbnail.url);
const videoUrl =
encodeURIComponent(generateEmbedUrl(claim.name, claim.claim_id)) +
generateEmbedUrlEncoded(claim.name, claim.claim_id) +
(referrerQuery ? `r=${encodeURIComponent(escapeHtmlProperty(referrerQuery))}` : '');
const { html, width, height } = generateEmbedIframeData(videoUrl);