encode share url parts

This commit is contained in:
Sean Yesmunt 2021-01-13 16:39:46 -05:00
parent d9b8f0310a
commit 72ac5a5437
2 changed files with 15 additions and 13 deletions

View file

@ -49,9 +49,7 @@ function SocialShare(props: Props) {
const encodedLbryURL: string = generateEncodedLbryURL(SHARE_DOMAIN, lbryWebUrl, includeStartTime, startTimeSeconds); const encodedLbryURL: string = generateEncodedLbryURL(SHARE_DOMAIN, lbryWebUrl, includeStartTime, startTimeSeconds);
const shareUrl: string = generateShareUrl( const shareUrl: string = generateShareUrl(
SHARE_DOMAIN, SHARE_DOMAIN,
lbryWebUrl, lbryUrl,
canonicalUrl,
permanentUrl,
referralCode, referralCode,
rewardsApproved, rewardsApproved,
includeStartTime, includeStartTime,

View file

@ -1,5 +1,6 @@
// Can't use aliases here because we're doing exports/require // Can't use aliases here because we're doing exports/require
const PAGES = require('../constants/pages'); const PAGES = require('../constants/pages');
const { parseURI, buildURI } = require('lbry-redux');
exports.formatLbryUrlForWeb = uri => { exports.formatLbryUrlForWeb = uri => {
let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':'); let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':');
@ -91,16 +92,7 @@ exports.generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTim
return `${domain}/${encodedPart}`; return `${domain}/${encodedPart}`;
}; };
exports.generateShareUrl = ( exports.generateShareUrl = (domain, lbryUrl, referralCode, rewardsApproved, includeStartTime, startTime) => {
domain,
lbryWebUrl,
canonicalUrl,
permanentUrl,
referralCode,
rewardsApproved,
includeStartTime,
startTime
) => {
let urlParams = new URLSearchParams(); let urlParams = new URLSearchParams();
if (referralCode && rewardsApproved) { if (referralCode && rewardsApproved) {
urlParams.append('r', referralCode); urlParams.append('r', referralCode);
@ -112,6 +104,18 @@ exports.generateShareUrl = (
const urlParamsString = urlParams.toString(); const urlParamsString = urlParams.toString();
const { streamName, streamClaimId, channelName, channelClaimId } = parseURI(lbryUrl);
let uriParts = {
...(streamName ? { streamName: encodeURIComponent(streamName) } : {}),
...(streamClaimId ? { streamClaimId } : {}),
...(channelName ? { channelName: encodeURIComponent(channelName) } : {}),
...(channelClaimId ? { channelClaimId } : {}),
};
const encodedUrl = buildURI(uriParts, false);
const lbryWebUrl = encodedUrl.replace(/#/g, ':');
const url = `${domain}/${lbryWebUrl}` + (urlParamsString === '' ? '' : `?${urlParamsString}`); const url = `${domain}/${lbryWebUrl}` + (urlParamsString === '' ? '' : `?${urlParamsString}`);
return url; return url;
}; };