fix desktop build

This commit is contained in:
Sean Yesmunt 2021-01-25 12:05:23 -05:00
parent 513e239771
commit d7f95ddd43
2 changed files with 35 additions and 11 deletions

View file

@ -8,7 +8,7 @@ function encodeWithApostropheEncode(string) {
return encodeURIComponent(string).replace(/'/g, '%27');
}
exports.formatLbryUrlForWeb = uri => {
export const formatLbryUrlForWeb = uri => {
let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':');
if (newUrl.startsWith('/?')) {
// This is a lbry link to an internal page ex: lbry://?rewards
@ -18,7 +18,7 @@ exports.formatLbryUrlForWeb = uri => {
return newUrl;
};
exports.formatFileSystemPath = path => {
export const formatFileSystemPath = path => {
if (!path) {
return;
}
@ -37,7 +37,7 @@ exports.formatFileSystemPath = path => {
ex: lbry://?rewards
ex: open.lbry.com/?rewards
*/
exports.formatInAppUrl = path => {
export const formatInAppUrl = path => {
// Determine if we need to add a leading "/$/" for app pages
const APP_PAGE_REGEX = /(\?)([a-z]*)(.*)/;
const appPageMatches = APP_PAGE_REGEX.exec(path);
@ -61,7 +61,7 @@ exports.formatInAppUrl = path => {
return path;
};
exports.formatWebUrlIntoLbryUrl = (pathname, search) => {
export const formatWebUrlIntoLbryUrl = (pathname, search) => {
// If there is no uri, the user is on an internal page
// pathname will either be "/" or "/$/{page}"
const path = pathname.startsWith('/$/') ? pathname.slice(3) : pathname.slice(1);
@ -75,7 +75,7 @@ exports.formatWebUrlIntoLbryUrl = (pathname, search) => {
return appLink;
};
exports.generateInitialUrl = hash => {
export const generateInitialUrl = hash => {
let url = '/';
if (hash) {
hash = hash.replace('#', '');
@ -84,21 +84,21 @@ exports.generateInitialUrl = hash => {
return url;
};
exports.generateLbryContentUrl = (canonicalUrl, permanentUrl) => {
export const generateLbryContentUrl = (canonicalUrl, permanentUrl) => {
return canonicalUrl ? canonicalUrl.split('lbry://')[1] : permanentUrl.split('lbry://')[1];
};
exports.generateLbryWebUrl = lbryUrl => {
export const generateLbryWebUrl = lbryUrl => {
return lbryUrl.replace(/#/g, ':');
};
exports.generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTime) => {
export const generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTime) => {
const queryParam = includeStartTime ? `?t=${startTime}` : '';
const encodedPart = encodeWithApostropheEncode(`${lbryWebUrl}${queryParam}`);
return `${domain}/${encodedPart}`;
};
exports.generateShareUrl = (domain, lbryUrl, referralCode, rewardsApproved, includeStartTime, startTime) => {
export const generateShareUrl = (domain, lbryUrl, referralCode, rewardsApproved, includeStartTime, startTime) => {
let urlParams = new URLSearchParams();
if (referralCode && rewardsApproved) {
urlParams.append('r', referralCode);

View file

@ -1,5 +1,29 @@
const PAGES = require('../../ui/constants/pages');
const config = require('../../config');
const { formatInAppUrl } = require('../../ui/util/url');
function formatInAppUrl(path) {
// Determine if we need to add a leading "/$/" for app pages
const APP_PAGE_REGEX = /(\?)([a-z]*)(.*)/;
const appPageMatches = APP_PAGE_REGEX.exec(path);
if (appPageMatches && appPageMatches.length) {
// Definitely an app page (or it's formatted like one)
const [, , page, queryString] = appPageMatches;
if (Object.values(PAGES).includes(page)) {
let actualUrl = '/$/' + page;
if (queryString) {
actualUrl += `?${queryString.slice(1)}`;
}
return actualUrl;
}
}
// Regular claim url
return path;
}
async function redirectMiddleware(ctx, next) {
const requestHost = ctx.host;
@ -22,7 +46,7 @@ async function redirectMiddleware(ctx, next) {
if (requestHost === 'open.lbry.com' || requestHost === 'open.lbry.io') {
const openQuery = '?src=open';
let redirectUrl = config.URL + formatInAppUrl(url, openQuery);
let redirectUrl = config.URL + formatInAppUrl(url);
if (redirectUrl.includes('?')) {
redirectUrl = redirectUrl.replace('?', `${openQuery}&`);