2019-12-02 18:30:08 +01:00
|
|
|
exports.formatLbryUrlForWeb = uri => {
|
|
|
|
return uri.replace('lbry://', '/').replace(/#/g, ':');
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.formatFileSystemPath = path => {
|
|
|
|
if (!path) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let webUrl = path.replace(/\\/g, '/');
|
|
|
|
|
|
|
|
if (webUrl[0] !== '/') {
|
|
|
|
webUrl = `/${webUrl}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return encodeURI(`file://${webUrl}`).replace(/[?#]/g, encodeURIComponent);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Function that handles page redirects
|
|
|
|
ex: lbry://?rewards
|
|
|
|
ex: open.lbry.com/?rewards
|
|
|
|
*/
|
2019-12-03 18:55:29 +01:00
|
|
|
exports.formatInAppUrl = path => {
|
2019-12-02 18:30:08 +01:00
|
|
|
// 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;
|
|
|
|
let actualUrl = '/$/' + page;
|
|
|
|
|
|
|
|
if (queryString) {
|
2019-12-03 18:55:29 +01:00
|
|
|
actualUrl += `?${queryString.slice(1)}`;
|
2019-12-02 18:30:08 +01:00
|
|
|
}
|
2019-12-03 18:55:29 +01:00
|
|
|
|
|
|
|
return actualUrl;
|
2019-12-02 18:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regular claim url
|
|
|
|
return path;
|
|
|
|
};
|