some lbryURI updates from lbry-app master
This commit is contained in:
parent
ca06c27d32
commit
4a0f8505f8
7 changed files with 768 additions and 736 deletions
1404
build/index.js
1404
build/index.js
File diff suppressed because it is too large
Load diff
12
src/index.js
12
src/index.js
|
@ -1,9 +1,17 @@
|
||||||
// common
|
// common
|
||||||
import Lbry from 'lbry';
|
import Lbry from 'lbry';
|
||||||
import Lbryapi from 'lbryapi';
|
import Lbryapi from 'lbryapi';
|
||||||
import Lbryuri from 'lbryuri';
|
|
||||||
|
|
||||||
export { Lbry, Lbryapi, Lbryuri };
|
export { Lbry, Lbryapi };
|
||||||
|
export {
|
||||||
|
regexInvalidURI,
|
||||||
|
regexAddress,
|
||||||
|
parseURI,
|
||||||
|
buildURI,
|
||||||
|
normalizeURI,
|
||||||
|
isURIValid,
|
||||||
|
isURIClaimable,
|
||||||
|
} from 'lbryURI';
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
export { doOpenModal, doCloseModal, doShowSnackBar } from 'redux/actions/app';
|
export { doOpenModal, doCloseModal, doShowSnackBar } from 'redux/actions/app';
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
const CHANNEL_NAME_MIN_LEN = 1;
|
const channelNameMinLength = 1;
|
||||||
const CLAIM_ID_MAX_LEN = 40;
|
const claimIdMaxLength = 40;
|
||||||
|
|
||||||
const Lbryuri = {};
|
export const regexInvalidURI = /[^A-Za-z0-9-]/g;
|
||||||
|
export const regexAddress = /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
|
||||||
Lbryuri.REGEXP_INVALID_URI = /[^A-Za-z0-9-]/g;
|
|
||||||
Lbryuri.REGEXP_ADDRESS = /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
* Parses a LBRY name into its component parts. Throws errors with user-friendly
|
||||||
|
@ -28,7 +26,7 @@ Lbryuri.REGEXP_ADDRESS = /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/;
|
||||||
* - contentName (string): For anon claims, the name; for channel claims, the path
|
* - contentName (string): For anon claims, the name; for channel claims, the path
|
||||||
* - channelName (string, if present): Channel name without @
|
* - channelName (string, if present): Channel name without @
|
||||||
*/
|
*/
|
||||||
Lbryuri.parse = (uri, requireProto = false) => {
|
export function parseURI(URI, requireProto = false) {
|
||||||
// Break into components. Empty sub-matches are converted to null
|
// Break into components. Empty sub-matches are converted to null
|
||||||
const componentsRegex = new RegExp(
|
const componentsRegex = new RegExp(
|
||||||
'^((?:lbry://)?)' + // protocol
|
'^((?:lbry://)?)' + // protocol
|
||||||
|
@ -37,7 +35,7 @@ Lbryuri.parse = (uri, requireProto = false) => {
|
||||||
'(/?)(.*)' // path separator, path
|
'(/?)(.*)' // path separator, path
|
||||||
);
|
);
|
||||||
const [proto, name, modSep, modVal, pathSep, path] = componentsRegex
|
const [proto, name, modSep, modVal, pathSep, path] = componentsRegex
|
||||||
.exec(uri)
|
.exec(URI)
|
||||||
.slice(1)
|
.slice(1)
|
||||||
.map(match => match || null);
|
.map(match => match || null);
|
||||||
|
|
||||||
|
@ -61,14 +59,14 @@ Lbryuri.parse = (uri, requireProto = false) => {
|
||||||
throw new Error(__('No channel name after @.'));
|
throw new Error(__('No channel name after @.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channelName.length < CHANNEL_NAME_MIN_LEN) {
|
if (channelName.length < channelNameMinLength) {
|
||||||
throw new Error(__(`Channel names must be at least %s characters.`, CHANNEL_NAME_MIN_LEN));
|
throw new Error(__(`Channel names must be at least %s characters.`, channelNameMinLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
contentName = path;
|
contentName = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nameBadChars = (channelName || name).match(Lbryuri.REGEXP_INVALID_URI);
|
const nameBadChars = (channelName || name).match(regexInvalidURI);
|
||||||
if (nameBadChars) {
|
if (nameBadChars) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
__(
|
__(
|
||||||
|
@ -99,7 +97,7 @@ Lbryuri.parse = (uri, requireProto = false) => {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
claimId &&
|
claimId &&
|
||||||
(claimId.length > CLAIM_ID_MAX_LEN || !claimId.match(/^[0-9a-f]+$/)) &&
|
(claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/)) &&
|
||||||
!claimId.match(/^pending/) // ought to be dropped when savePendingPublish drops hack
|
!claimId.match(/^pending/) // ought to be dropped when savePendingPublish drops hack
|
||||||
) {
|
) {
|
||||||
throw new Error(__(`Invalid claim ID %s.`, claimId));
|
throw new Error(__(`Invalid claim ID %s.`, claimId));
|
||||||
|
@ -119,7 +117,7 @@ Lbryuri.parse = (uri, requireProto = false) => {
|
||||||
throw new Error(__('Only channel URIs may have a path.'));
|
throw new Error(__('Only channel URIs may have a path.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathBadChars = path.match(Lbryuri.REGEXP_INVALID_URI);
|
const pathBadChars = path.match(regexInvalidURI);
|
||||||
if (pathBadChars) {
|
if (pathBadChars) {
|
||||||
throw new Error(__(`Invalid character in path: %s`, pathBadChars.join(', ')));
|
throw new Error(__(`Invalid character in path: %s`, pathBadChars.join(', ')));
|
||||||
}
|
}
|
||||||
|
@ -140,17 +138,17 @@ Lbryuri.parse = (uri, requireProto = false) => {
|
||||||
...(claimId ? { claimId } : {}),
|
...(claimId ? { claimId } : {}),
|
||||||
...(path ? { path } : {}),
|
...(path ? { path } : {}),
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes an object in the same format returned by lbryuri.parse() and builds a URI.
|
* Takes an object in the same format returned by parse() and builds a URI.
|
||||||
*
|
*
|
||||||
* The channelName key will accept names with or without the @ prefix.
|
* The channelName key will accept names with or without the @ prefix.
|
||||||
*/
|
*/
|
||||||
Lbryuri.build = (uriObj, includeProto = true) => {
|
export function buildURI(URIObj, includeProto = true) {
|
||||||
const { claimId, claimSequence, bidPosition, contentName, channelName } = uriObj;
|
const { claimId, claimSequence, bidPosition, contentName, channelName } = URIObj;
|
||||||
|
|
||||||
let { name, path } = uriObj;
|
let { name, path } = URIObj;
|
||||||
|
|
||||||
if (channelName) {
|
if (channelName) {
|
||||||
const channelNameFormatted = channelName.startsWith('@') ? channelName : `@${channelName}`;
|
const channelNameFormatted = channelName.startsWith('@') ? channelName : `@${channelName}`;
|
||||||
|
@ -188,36 +186,35 @@ Lbryuri.build = (uriObj, includeProto = true) => {
|
||||||
(bidPosition ? `${bidPosition}` : '') +
|
(bidPosition ? `${bidPosition}` : '') +
|
||||||
(path ? `/${path}` : '')
|
(path ? `/${path}` : '')
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
/* Takes a parseable LBRY URI and converts it to standard, canonical format (currently this just
|
/* Takes a parseable LBRY URI and converts it to standard, canonical format */
|
||||||
* consists of adding the lbry:// prefix if needed) */
|
export function normalizeURI(URI) {
|
||||||
Lbryuri.normalize = uri => {
|
if (URI.match(/pending_claim/)) return URI;
|
||||||
if (uri.match(/pending_claim/)) return uri;
|
|
||||||
|
|
||||||
const { name, path, bidPosition, claimSequence, claimId } = Lbryuri.parse(uri);
|
const { name, path, bidPosition, claimSequence, claimId } = parseURI(URI);
|
||||||
return Lbryuri.build({ name, path, claimSequence, bidPosition, claimId });
|
return buildURI({ name, path, claimSequence, bidPosition, claimId });
|
||||||
};
|
}
|
||||||
|
|
||||||
Lbryuri.isValid = uri => {
|
export function isURIValid(URI) {
|
||||||
let parts;
|
let parts;
|
||||||
try {
|
try {
|
||||||
parts = Lbryuri.parse(Lbryuri.normalize(uri));
|
parts = parseURI(normalizeURI(URI));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return parts && parts.name;
|
return parts && parts.name;
|
||||||
};
|
}
|
||||||
|
|
||||||
Lbryuri.isValidName = (name, checkCase = true) => {
|
export function isNameValid(name, checkCase = true) {
|
||||||
const regexp = new RegExp('^[a-z0-9-]+$', checkCase ? '' : 'i');
|
const regexp = new RegExp('^[a-z0-9-]+$', checkCase ? '' : 'i');
|
||||||
return regexp.test(name);
|
return regexp.test(name);
|
||||||
};
|
}
|
||||||
|
|
||||||
Lbryuri.isClaimable = uri => {
|
export function isURIClaimable(URI) {
|
||||||
let parts;
|
let parts;
|
||||||
try {
|
try {
|
||||||
parts = Lbryuri.parse(Lbryuri.normalize(uri));
|
parts = parseURI(normalizeURI(URI));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -230,9 +227,4 @@ Lbryuri.isClaimable = uri => {
|
||||||
!parts.isChannel &&
|
!parts.isChannel &&
|
||||||
!parts.path
|
!parts.path
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
||||||
if (window) {
|
|
||||||
window.lbryuri = Lbryuri;
|
|
||||||
}
|
}
|
||||||
export default Lbryuri;
|
|
|
@ -1,13 +1,13 @@
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
import * as MODALS from 'constants/modal_types';
|
import * as MODALS from 'constants/modal_types';
|
||||||
import Lbry from 'lbry';
|
import Lbry from 'lbry';
|
||||||
import Lbryuri from 'lbryuri';
|
import { buildURI, normalizeURI } from 'lbryURI';
|
||||||
import { doOpenModal } from 'redux/actions/app';
|
import { doOpenModal } from 'redux/actions/app';
|
||||||
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
|
import { selectMyClaimsRaw, selectResolvingUris } from 'redux/selectors/claims';
|
||||||
|
|
||||||
export function doResolveUris(uris) {
|
export function doResolveUris(uris) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const normalizedUris = uris.map(Lbryuri.normalize);
|
const normalizedUris = uris.map(normalizeURI);
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
|
||||||
// Filter out URIs that are already resolving
|
// Filter out URIs that are already resolving
|
||||||
|
@ -94,7 +94,7 @@ export function doAbandonClaim(txid, nout) {
|
||||||
claimId,
|
claimId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch(doResolveUri(Lbryuri.build({ name, claimId })));
|
dispatch(doResolveUri(buildURI({ name, claimId })));
|
||||||
dispatch(doFetchClaimListMine());
|
dispatch(doFetchClaimListMine());
|
||||||
} else {
|
} else {
|
||||||
dispatch(doOpenModal(MODALS.TRANSACTION_FAILED));
|
dispatch(doOpenModal(MODALS.TRANSACTION_FAILED));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import * as ACTIONS from 'constants/action_types';
|
import * as ACTIONS from 'constants/action_types';
|
||||||
import Lbryuri from 'lbryuri';
|
import { buildURI } from 'lbryURI';
|
||||||
import { doResolveUri } from 'redux/actions/claims';
|
import { doResolveUri } from 'redux/actions/claims';
|
||||||
import { doNavigate } from 'redux/actions/navigation';
|
import { doNavigate } from 'redux/actions/navigation';
|
||||||
import { selectCurrentPage } from 'redux/selectors/navigation';
|
import { selectCurrentPage } from 'redux/selectors/navigation';
|
||||||
|
@ -40,7 +40,7 @@ export function doSearch(rawQuery) {
|
||||||
const actions = [];
|
const actions = [];
|
||||||
|
|
||||||
data.forEach(result => {
|
data.forEach(result => {
|
||||||
const uri = Lbryuri.build({
|
const uri = buildURI({
|
||||||
name: result.name,
|
name: result.name,
|
||||||
claimId: result.claimId,
|
claimId: result.claimId,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import Lbryuri from 'lbryuri';
|
import { normalizeURI } from 'lbryURI';
|
||||||
import { makeSelectCurrentParam } from 'redux/selectors/navigation';
|
import { makeSelectCurrentParam } from 'redux/selectors/navigation';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ export const selectAllClaimsByChannel = createSelector(
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectClaimForUri = uri =>
|
export const makeSelectClaimForUri = uri =>
|
||||||
createSelector(selectClaimsByUri, claims => claims && claims[Lbryuri.normalize(uri)]);
|
createSelector(selectClaimsByUri, claims => claims && claims[normalizeURI(uri)]);
|
||||||
|
|
||||||
export const selectMyClaimsRaw = createSelector(selectState, state => state.myClaims);
|
export const selectMyClaimsRaw = createSelector(selectState, state => state.myClaims);
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ export const selectMyActiveClaims = createSelector(
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectClaimIsMine = rawUri => {
|
export const makeSelectClaimIsMine = rawUri => {
|
||||||
const uri = Lbryuri.normalize(rawUri);
|
const uri = normalizeURI(rawUri);
|
||||||
return createSelector(
|
return createSelector(
|
||||||
selectClaimsByUri,
|
selectClaimsByUri,
|
||||||
selectMyActiveClaims,
|
selectMyActiveClaims,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
|
import { normalizeURI } from 'lbryURI';
|
||||||
import { parseQueryParams, toQueryString } from 'util/query_params';
|
import { parseQueryParams, toQueryString } from 'util/query_params';
|
||||||
import Lbryuri from 'lbryuri';
|
|
||||||
|
|
||||||
export const selectState = state => state.navigation || {};
|
export const selectState = state => state.navigation || {};
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ export const selectPageTitle = createSelector(
|
||||||
case 'developer':
|
case 'developer':
|
||||||
return __('Developer');
|
return __('Developer');
|
||||||
case 'show': {
|
case 'show': {
|
||||||
const parts = [Lbryuri.normalize(params.uri)];
|
const parts = [normalizeURI(params.uri)];
|
||||||
// If the params has any keys other than "uri"
|
// If the params has any keys other than "uri"
|
||||||
if (Object.keys(params).length > 1) {
|
if (Object.keys(params).length > 1) {
|
||||||
parts.push(toQueryString(Object.assign({}, params, { uri: null })));
|
parts.push(toQueryString(Object.assign({}, params, { uri: null })));
|
||||||
|
|
Loading…
Reference in a new issue