2019-12-06 22:12:48 +01:00
|
|
|
// Can't use aliases here because we're doing exports/require
|
2021-06-10 20:23:25 +02:00
|
|
|
|
2022-05-13 15:14:05 +02:00
|
|
|
import { DOMAIN } from 'config';
|
2019-12-06 22:12:48 +01:00
|
|
|
const PAGES = require('../constants/pages');
|
2021-10-17 10:36:14 +02:00
|
|
|
const { parseURI, buildURI } = require('../util/lbryURI');
|
|
|
|
const COLLECTIONS_CONSTS = require('../constants/collections');
|
2019-12-06 22:12:48 +01:00
|
|
|
|
2021-05-13 21:21:21 +02:00
|
|
|
function encodeWithSpecialCharEncode(string) {
|
|
|
|
// encodeURIComponent doesn't encode `'` and others
|
|
|
|
// which other services may not like
|
|
|
|
return encodeURIComponent(string).replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29');
|
2021-01-22 21:37:20 +01:00
|
|
|
}
|
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
export const formatLbryUrlForWeb = (uri) => {
|
2020-07-23 16:22:57 +02:00
|
|
|
let newUrl = uri.replace('lbry://', '/').replace(/#/g, ':');
|
|
|
|
if (newUrl.startsWith('/?')) {
|
|
|
|
// This is a lbry link to an internal page ex: lbry://?rewards
|
|
|
|
newUrl = newUrl.replace('/?', '/$/');
|
|
|
|
}
|
|
|
|
|
|
|
|
return newUrl;
|
2019-12-02 18:30:08 +01:00
|
|
|
};
|
|
|
|
|
2022-01-18 05:24:59 +01:00
|
|
|
export const formatLbryChannelName = (uri) => uri && uri.replace('lbry://', '').replace(/#/g, ':');
|
2022-01-14 21:24:16 +01:00
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
export const formatFileSystemPath = (path) => {
|
2019-12-02 18:30:08 +01:00
|
|
|
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
|
|
|
|
*/
|
2021-04-23 21:59:48 +02:00
|
|
|
export const 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;
|
|
|
|
|
2019-12-09 20:42:10 +01:00
|
|
|
if (Object.values(PAGES).includes(page)) {
|
|
|
|
let actualUrl = '/$/' + page;
|
|
|
|
|
|
|
|
if (queryString) {
|
|
|
|
actualUrl += `?${queryString.slice(1)}`;
|
|
|
|
}
|
2019-12-03 18:55:29 +01:00
|
|
|
|
2019-12-09 20:42:10 +01:00
|
|
|
return actualUrl;
|
|
|
|
}
|
2019-12-02 18:30:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regular claim url
|
|
|
|
return path;
|
|
|
|
};
|
2019-12-06 22:12:48 +01:00
|
|
|
|
2021-01-25 18:05:23 +01:00
|
|
|
export const formatWebUrlIntoLbryUrl = (pathname, search) => {
|
2019-12-06 22:12:48 +01:00
|
|
|
// 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);
|
|
|
|
let appLink = `lbry://?${path || PAGES.DISCOVER}`;
|
|
|
|
|
|
|
|
if (search) {
|
|
|
|
// We already have a leading "?" for the query param on internal pages
|
|
|
|
appLink += search.replace('?', '&');
|
|
|
|
}
|
|
|
|
|
|
|
|
return appLink;
|
|
|
|
};
|
2020-02-12 05:59:30 +01:00
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
export const generateInitialUrl = (hash) => {
|
2020-02-12 05:59:30 +01:00
|
|
|
let url = '/';
|
|
|
|
if (hash) {
|
|
|
|
hash = hash.replace('#', '');
|
|
|
|
url = hash.startsWith('/') ? hash : '/' + hash;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
};
|
2020-05-06 05:05:59 +02:00
|
|
|
|
2021-01-25 18:05:23 +01:00
|
|
|
export const generateLbryContentUrl = (canonicalUrl, permanentUrl) => {
|
2020-05-06 05:05:59 +02:00
|
|
|
return canonicalUrl ? canonicalUrl.split('lbry://')[1] : permanentUrl.split('lbry://')[1];
|
|
|
|
};
|
|
|
|
|
2021-04-23 21:59:48 +02:00
|
|
|
export const generateLbryWebUrl = (lbryUrl) => {
|
2020-05-06 05:05:59 +02:00
|
|
|
return lbryUrl.replace(/#/g, ':');
|
|
|
|
};
|
|
|
|
|
2021-06-10 20:23:25 +02:00
|
|
|
export const generateEncodedLbryURL = (domain, lbryWebUrl, includeStartTime, startTime, listId) => {
|
|
|
|
let urlParams = new URLSearchParams();
|
|
|
|
|
|
|
|
if (includeStartTime) {
|
|
|
|
urlParams.append('t', startTime.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listId) {
|
|
|
|
urlParams.append(COLLECTIONS_CONSTS.COLLECTION_ID, listId);
|
|
|
|
}
|
|
|
|
const urlParamsString = urlParams.toString();
|
|
|
|
const encodedPart = encodeWithSpecialCharEncode(`${lbryWebUrl}?${urlParamsString}`);
|
2020-08-29 19:58:38 +02:00
|
|
|
return `${domain}/${encodedPart}`;
|
2020-05-06 05:05:59 +02:00
|
|
|
};
|
|
|
|
|
2021-06-10 20:23:25 +02:00
|
|
|
export const generateShareUrl = (
|
|
|
|
domain,
|
|
|
|
lbryUrl,
|
|
|
|
referralCode,
|
|
|
|
rewardsApproved,
|
|
|
|
includeStartTime,
|
|
|
|
startTime,
|
|
|
|
listId
|
|
|
|
) => {
|
2020-05-06 05:05:59 +02:00
|
|
|
let urlParams = new URLSearchParams();
|
|
|
|
if (referralCode && rewardsApproved) {
|
|
|
|
urlParams.append('r', referralCode);
|
|
|
|
}
|
|
|
|
|
2021-06-10 20:23:25 +02:00
|
|
|
if (listId) {
|
|
|
|
urlParams.append(COLLECTIONS_CONSTS.COLLECTION_ID, listId);
|
|
|
|
}
|
|
|
|
|
2020-05-06 05:05:59 +02:00
|
|
|
if (includeStartTime) {
|
|
|
|
urlParams.append('t', startTime.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
const urlParamsString = urlParams.toString();
|
2020-12-14 20:48:08 +01:00
|
|
|
|
2021-01-13 22:39:46 +01:00
|
|
|
const { streamName, streamClaimId, channelName, channelClaimId } = parseURI(lbryUrl);
|
|
|
|
|
|
|
|
let uriParts = {
|
2021-05-13 21:21:21 +02:00
|
|
|
...(streamName ? { streamName: encodeWithSpecialCharEncode(streamName) } : {}),
|
2021-01-13 22:39:46 +01:00
|
|
|
...(streamClaimId ? { streamClaimId } : {}),
|
2021-05-13 21:21:21 +02:00
|
|
|
...(channelName ? { channelName: encodeWithSpecialCharEncode(channelName) } : {}),
|
2021-01-13 22:39:46 +01:00
|
|
|
...(channelClaimId ? { channelClaimId } : {}),
|
|
|
|
};
|
|
|
|
|
|
|
|
const encodedUrl = buildURI(uriParts, false);
|
|
|
|
const lbryWebUrl = encodedUrl.replace(/#/g, ':');
|
|
|
|
|
2020-12-16 01:44:37 +01:00
|
|
|
const url = `${domain}/${lbryWebUrl}` + (urlParamsString === '' ? '' : `?${urlParamsString}`);
|
2020-05-06 05:05:59 +02:00
|
|
|
return url;
|
|
|
|
};
|
2021-06-30 08:02:09 +02:00
|
|
|
|
2021-07-12 18:17:04 +02:00
|
|
|
export const generateRssUrl = (domain, channelClaim) => {
|
|
|
|
if (!channelClaim || channelClaim.value_type !== 'channel' || !channelClaim.canonical_url) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = `${domain}/$/rss/${channelClaim.canonical_url.replace('lbry://', '').replace('#', ':')}`;
|
2021-06-30 08:02:09 +02:00
|
|
|
return url;
|
|
|
|
};
|
2021-09-10 19:27:21 +02:00
|
|
|
|
|
|
|
export const generateListSearchUrlParams = (collectionId) => {
|
|
|
|
const urlParams = new URLSearchParams();
|
|
|
|
urlParams.set(COLLECTIONS_CONSTS.COLLECTION_ID, collectionId);
|
|
|
|
return `?` + urlParams.toString();
|
|
|
|
};
|
2022-05-13 15:14:05 +02:00
|
|
|
|
|
|
|
// Google cache url
|
|
|
|
// ex: webcache.googleusercontent.com/search?q=cache:MLwN3a8fCbYJ:https://lbry.tv/%40Bombards_Body_Language:f+&cd=12&hl=en&ct=clnk&gl=us
|
|
|
|
// Extract the lbry url and use that instead
|
|
|
|
// Without this it will try to render lbry://search
|
|
|
|
export function generateGoogleCacheUrl(search, path) {
|
|
|
|
const googleCacheRegex = new RegExp(`(https://${DOMAIN}/)([^+]*)`);
|
|
|
|
const [x, y, googleCachedUrl] = search.match(googleCacheRegex); // eslint-disable-line
|
|
|
|
|
|
|
|
if (googleCachedUrl) {
|
|
|
|
const actualUrl = decodeURIComponent(googleCachedUrl);
|
|
|
|
if (actualUrl) {
|
|
|
|
path = actualUrl.replace(/:/g, '#');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Playlists v2: Refactors, touch ups + Queue Mode (#1604)
* Playlists v2
* Style pass
* Change playlist items arrange icon
* Playlist card body open by default
* Refactor collectionEdit components
* Paginate & Refactor bid field
* Collection page changes
* Add Thumbnail optional
* Replace extra info for description on collection page
* Playlist card right below video on medium screen
* Allow editing private collections
* Add edit option to menus
* Allow deleting a public playlist but keeping a private version
* Add queue to Save menu, remove edit option from Builtin pages, show queue on playlists page
* Fix scroll to recent persisting on medium screen
* Fix adding to queue from menu
* Fixes for delete
* PublishList: delay mounting Items tab to prevent lock-up (#1783)
For a large list, the playlist publish form is unusable (super-slow typing) due to the entire list being mounted despite the tab is not active.
The full solution is still to paginate it, but for now, don't mount the tab until it is selected. Add a spinner to indicate something is loading. It's not prefect, but it's throwaway code anyway. At least we can fill in the fields properly now.
* Batch-resolve private collections (#1782)
* makeSelectClaimForClaimId --> selectClaimForClaimId
Move away from the problematic `makeSelect*`, especially in large loops.
* Batch-resolve private collections
1758
This alleviates the lock-up that is caused by large number of invidual resolves. There will still be some minor stutter due to the large DOM that React needs to handle -- that is logged in 1758 and will be handled separately.
At least the stutter is short (1-2s) and the app is still usable.
Private list items are being resolve individually, super slow if the list is large (>100). Published lists doesn't have this issue.
doFetchItemsInCollections contains most of the useful logic, but it isn't called for private/built-in lists because it's not an actual claim.
Tweaked doFetchItemsInCollections to handle private (UUID-based) collections.
* Use persisted state for floating player playlist card body
- I find it annoying being open everytime
* Fix removing edits from published playlist
* Fix scroll on mobile
* Allow going editing items from toast
* Fix ClaimShareButton
* Prevent edit/publish of builtin
* Fix async inside forEach
* Fix sync on queue edit
* Fix autoplayCountdown replay
* Fix deleting an item scrolling the playlist
* CreatedAt fixes
* Remove repost for now
* Anon publish fixes
* Fix mature case on floating
Co-authored-by: infinite-persistence <64950861+infinite-persistence@users.noreply.github.com>
2022-07-13 15:59:59 +02:00
|
|
|
|
|
|
|
const CLAIM_ID_LENGTH = 40;
|
|
|
|
|
|
|
|
export function parseClaimIdFromPermanentUrl(url, failureId = '0') {
|
|
|
|
// - `parseURI` is too expensive for large loops, so this serves as a lighter
|
|
|
|
// alternative when iterating a list of permanent URLs.
|
|
|
|
// - It does not verify the permanent URL format, so only use this for areas
|
|
|
|
// where parsing failure is not fatal (e.g. if parsing for ist of IDs to
|
|
|
|
// resolve, missing a few wouldn't matter since components can resolve
|
|
|
|
// individually).
|
|
|
|
const parts = url.split('#');
|
|
|
|
const id = parts[parts.length - 1];
|
|
|
|
return id && id.length === CLAIM_ID_LENGTH ? id : failureId;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getPathForPage = (page) => `/$/${page}/`;
|