fix desktop build
This commit is contained in:
parent
513e239771
commit
d7f95ddd43
2 changed files with 35 additions and 11 deletions
|
@ -8,7 +8,7 @@ function encodeWithApostropheEncode(string) {
|
||||||
return encodeURIComponent(string).replace(/'/g, '%27');
|
return encodeURIComponent(string).replace(/'/g, '%27');
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.formatLbryUrlForWeb = uri => {
|
export const formatLbryUrlForWeb = uri => {
|
||||||
let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':');
|
let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':');
|
||||||
if (newUrl.startsWith('/?')) {
|
if (newUrl.startsWith('/?')) {
|
||||||
// This is a lbry link to an internal page ex: lbry://?rewards
|
// This is a lbry link to an internal page ex: lbry://?rewards
|
||||||
|
@ -18,7 +18,7 @@ exports.formatLbryUrlForWeb = uri => {
|
||||||
return newUrl;
|
return newUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.formatFileSystemPath = path => {
|
export const formatFileSystemPath = path => {
|
||||||
if (!path) {
|
if (!path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ exports.formatFileSystemPath = path => {
|
||||||
ex: lbry://?rewards
|
ex: lbry://?rewards
|
||||||
ex: open.lbry.com/?rewards
|
ex: open.lbry.com/?rewards
|
||||||
*/
|
*/
|
||||||
exports.formatInAppUrl = path => {
|
export const formatInAppUrl = path => {
|
||||||
// Determine if we need to add a leading "/$/" for app pages
|
// Determine if we need to add a leading "/$/" for app pages
|
||||||
const APP_PAGE_REGEX = /(\?)([a-z]*)(.*)/;
|
const APP_PAGE_REGEX = /(\?)([a-z]*)(.*)/;
|
||||||
const appPageMatches = APP_PAGE_REGEX.exec(path);
|
const appPageMatches = APP_PAGE_REGEX.exec(path);
|
||||||
|
@ -61,7 +61,7 @@ exports.formatInAppUrl = path => {
|
||||||
return path;
|
return path;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.formatWebUrlIntoLbryUrl = (pathname, search) => {
|
export const formatWebUrlIntoLbryUrl = (pathname, search) => {
|
||||||
// If there is no uri, the user is on an internal page
|
// If there is no uri, the user is on an internal page
|
||||||
// pathname will either be "/" or "/$/{page}"
|
// pathname will either be "/" or "/$/{page}"
|
||||||
const path = pathname.startsWith('/$/') ? pathname.slice(3) : pathname.slice(1);
|
const path = pathname.startsWith('/$/') ? pathname.slice(3) : pathname.slice(1);
|
||||||
|
@ -75,7 +75,7 @@ exports.formatWebUrlIntoLbryUrl = (pathname, search) => {
|
||||||
return appLink;
|
return appLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateInitialUrl = hash => {
|
export const generateInitialUrl = hash => {
|
||||||
let url = '/';
|
let url = '/';
|
||||||
if (hash) {
|
if (hash) {
|
||||||
hash = hash.replace('#', '');
|
hash = hash.replace('#', '');
|
||||||
|
@ -84,21 +84,21 @@ exports.generateInitialUrl = hash => {
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateLbryContentUrl = (canonicalUrl, permanentUrl) => {
|
export const generateLbryContentUrl = (canonicalUrl, permanentUrl) => {
|
||||||
return canonicalUrl ? canonicalUrl.split('lbry://')[1] : permanentUrl.split('lbry://')[1];
|
return canonicalUrl ? canonicalUrl.split('lbry://')[1] : permanentUrl.split('lbry://')[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateLbryWebUrl = lbryUrl => {
|
export const generateLbryWebUrl = lbryUrl => {
|
||||||
return lbryUrl.replace(/#/g, ':');
|
return lbryUrl.replace(/#/g, ':');
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTime) => {
|
export const generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTime) => {
|
||||||
const queryParam = includeStartTime ? `?t=${startTime}` : '';
|
const queryParam = includeStartTime ? `?t=${startTime}` : '';
|
||||||
const encodedPart = encodeWithApostropheEncode(`${lbryWebUrl}${queryParam}`);
|
const encodedPart = encodeWithApostropheEncode(`${lbryWebUrl}${queryParam}`);
|
||||||
return `${domain}/${encodedPart}`;
|
return `${domain}/${encodedPart}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generateShareUrl = (domain, lbryUrl, referralCode, rewardsApproved, includeStartTime, startTime) => {
|
export const generateShareUrl = (domain, lbryUrl, 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);
|
||||||
|
|
|
@ -1,5 +1,29 @@
|
||||||
|
const PAGES = require('../../ui/constants/pages');
|
||||||
const config = require('../../config');
|
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) {
|
async function redirectMiddleware(ctx, next) {
|
||||||
const requestHost = ctx.host;
|
const requestHost = ctx.host;
|
||||||
|
@ -22,7 +46,7 @@ async function redirectMiddleware(ctx, next) {
|
||||||
|
|
||||||
if (requestHost === 'open.lbry.com' || requestHost === 'open.lbry.io') {
|
if (requestHost === 'open.lbry.com' || requestHost === 'open.lbry.io') {
|
||||||
const openQuery = '?src=open';
|
const openQuery = '?src=open';
|
||||||
let redirectUrl = config.URL + formatInAppUrl(url, openQuery);
|
let redirectUrl = config.URL + formatInAppUrl(url);
|
||||||
|
|
||||||
if (redirectUrl.includes('?')) {
|
if (redirectUrl.includes('?')) {
|
||||||
redirectUrl = redirectUrl.replace('?', `${openQuery}&`);
|
redirectUrl = redirectUrl.replace('?', `${openQuery}&`);
|
||||||
|
|
Loading…
Reference in a new issue