repond to pr feedback

This commit is contained in:
Sean Yesmunt 2019-07-01 23:04:27 -04:00
parent 1b9d540c67
commit 63ba459574
4 changed files with 28 additions and 52 deletions

40
dist/bundle.es.js vendored
View file

@ -918,14 +918,12 @@ function parseURI(URI, requireProto = false) {
// Validate protocol // Validate protocol
if (requireProto && !proto) { if (requireProto && !proto) {
console.error(__('LBRY URIs must include a protocol prefix (lbry://).')); throw new Error(__('LBRY URIs must include a protocol prefix (lbry://).'));
return {};
} }
// Validate and process name // Validate and process name
if (!claimName) { if (!claimName) {
console.error(__('URI does not include name.')); throw new Error(__('URI does not include name.'));
return {};
} }
const isChannel = claimName.startsWith('@'); const isChannel = claimName.startsWith('@');
@ -933,13 +931,11 @@ function parseURI(URI, requireProto = false) {
if (isChannel) { if (isChannel) {
if (!channelName) { if (!channelName) {
console.error(__('No channel name after @.')); throw new Error(__('No channel name after @.'));
return {};
} }
if (channelName.length < channelNameMinLength) { if (channelName.length < channelNameMinLength) {
console.error(__(`Channel names must be at least %s characters.`, channelNameMinLength)); throw new Error(__(`Channel names must be at least %s characters.`, channelNameMinLength));
return {};
} }
contentName = path; contentName = path;
@ -947,8 +943,7 @@ function parseURI(URI, requireProto = false) {
const nameBadChars = (channelName || claimName).match(regexInvalidURI); const nameBadChars = (channelName || claimName).match(regexInvalidURI);
if (nameBadChars) { if (nameBadChars) {
console.error(__(`Invalid character %s in name: %s.`, nameBadChars.length === 1 ? '' : 's', nameBadChars.join(', '))); throw new Error(__(`Invalid character %s in name: %s.`, nameBadChars.length === 1 ? '' : 's', nameBadChars.join(', ')));
return {};
} }
// Validate and process modifier (claim ID, bid position or claim sequence) // Validate and process modifier (claim ID, bid position or claim sequence)
@ -957,8 +952,7 @@ function parseURI(URI, requireProto = false) {
let bidPosition; let bidPosition;
if (modSep) { if (modSep) {
if (!modVal) { if (!modVal) {
console.error(__(`No modifier provided after separator %s.`, modSep)); throw new Error(__(`No modifier provided after separator %s.`, modSep));
return {};
} }
if (modSep === '#') { if (modSep === '#') {
@ -971,37 +965,31 @@ function parseURI(URI, requireProto = false) {
} }
if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) { if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) {
console.error(__(`Invalid claim ID %s.`, claimId)); throw new Error(__(`Invalid claim ID %s.`, claimId));
return {};
} }
if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) { if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Claim sequence must be a number.')); throw new Error(__('Claim sequence must be a number.'));
return {};
} }
if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) { if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Bid position must be a number.')); throw new Error(__('Bid position must be a number.'));
return {};
} }
// Validate and process path // Validate and process path
if (path) { if (path) {
if (!isChannel) { if (!isChannel) {
console.error(__('Only channel URIs may have a path.')); throw new Error(__('Only channel URIs may have a path.'));
return {};
} }
const pathBadChars = path.match(regexInvalidURI); const pathBadChars = path.match(regexInvalidURI);
if (pathBadChars) { if (pathBadChars) {
console.error(__(`Invalid character in path: %s`, pathBadChars.join(', '))); throw new Error(__(`Invalid character in path: %s`, pathBadChars.join(', ')));
return {};
} }
contentName = path; contentName = path;
} else if (pathSep) { } else if (pathSep) {
console.error(__('No path provided after /')); throw new Error(__('No path provided after /'));
return {};
} }
return _extends({ return _extends({
@ -1377,7 +1365,7 @@ const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaim
const selectMyClaimsWithoutChannels = reselect.createSelector(selectMyClaims, myClaims => myClaims.filter(claim => !claim.name.match(/^@/)).sort((a, b) => a.timestamp - b.timestamp)); const selectMyClaimsWithoutChannels = reselect.createSelector(selectMyClaims, myClaims => myClaims.filter(claim => !claim.name.match(/^@/)).sort((a, b) => a.timestamp - b.timestamp));
const selectMyClaimUrisWithoutChannels = reselect.createSelector(selectMyClaimsWithoutChannels, myClaims => myClaims.sort((a, b) => a.confirmations - b.confirmations).map(claim => `lbry://${claim.name}#${claim.claim_id}`)); const selectMyClaimUrisWithoutChannels = reselect.createSelector(selectMyClaimsWithoutChannels, myClaims => myClaims.sort((a, b) => b.timestamp - a.timestamp).map(claim => `lbry://${claim.name}#${claim.claim_id}`));
const selectAllMyClaimsByOutpoint = reselect.createSelector(selectMyClaimsRaw, claims => new Set(claims && claims.length ? claims.map(claim => `${claim.txid}:${claim.nout}`) : null)); const selectAllMyClaimsByOutpoint = reselect.createSelector(selectMyClaimsRaw, claims => new Set(claims && claims.length ? claims.map(claim => `${claim.txid}:${claim.nout}`) : null));
@ -2456,7 +2444,7 @@ const selectFileListDownloadedSort = reselect.createSelector(selectState$3, stat
const selectDownloadedUris = reselect.createSelector(selectFileInfosDownloaded, const selectDownloadedUris = reselect.createSelector(selectFileInfosDownloaded,
// We should use permament_url but it doesn't exist in file_list // We should use permament_url but it doesn't exist in file_list
info => info.slice().reverse().map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`)); info => info.slice().reverse().map(claim => console.log(claim) || `lbry://${claim.claim_name}#${claim.claim_id}`));
// //

View file

@ -44,14 +44,12 @@ export function parseURI(URI, requireProto = false) {
// Validate protocol // Validate protocol
if (requireProto && !proto) { if (requireProto && !proto) {
console.error(__('LBRY URIs must include a protocol prefix (lbry://).')); throw new Error(__('LBRY URIs must include a protocol prefix (lbry://).'));
return {};
} }
// Validate and process name // Validate and process name
if (!claimName) { if (!claimName) {
console.error(__('URI does not include name.')); throw new Error(__('URI does not include name.'));
return {};
} }
const isChannel = claimName.startsWith('@'); const isChannel = claimName.startsWith('@');
@ -59,13 +57,11 @@ export function parseURI(URI, requireProto = false) {
if (isChannel) { if (isChannel) {
if (!channelName) { if (!channelName) {
console.error(__('No channel name after @.')); throw new Error(__('No channel name after @.'));
return {};
} }
if (channelName.length < channelNameMinLength) { if (channelName.length < channelNameMinLength) {
console.error(__(`Channel names must be at least %s characters.`, channelNameMinLength)); throw new Error(__(`Channel names must be at least %s characters.`, channelNameMinLength));
return {};
} }
contentName = path; contentName = path;
@ -73,14 +69,13 @@ export function parseURI(URI, requireProto = false) {
const nameBadChars = (channelName || claimName).match(regexInvalidURI); const nameBadChars = (channelName || claimName).match(regexInvalidURI);
if (nameBadChars) { if (nameBadChars) {
console.error( throw new Error(
__( __(
`Invalid character %s in name: %s.`, `Invalid character %s in name: %s.`,
nameBadChars.length === 1 ? '' : 's', nameBadChars.length === 1 ? '' : 's',
nameBadChars.join(', ') nameBadChars.join(', ')
) )
); );
return {};
} }
// Validate and process modifier (claim ID, bid position or claim sequence) // Validate and process modifier (claim ID, bid position or claim sequence)
@ -89,8 +84,7 @@ export function parseURI(URI, requireProto = false) {
let bidPosition; let bidPosition;
if (modSep) { if (modSep) {
if (!modVal) { if (!modVal) {
console.error(__(`No modifier provided after separator %s.`, modSep)); throw new Error(__(`No modifier provided after separator %s.`, modSep));
return {};
} }
if (modSep === '#') { if (modSep === '#') {
@ -103,37 +97,31 @@ export function parseURI(URI, requireProto = false) {
} }
if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) { if (claimId && (claimId.length > claimIdMaxLength || !claimId.match(/^[0-9a-f]+$/))) {
console.error(__(`Invalid claim ID %s.`, claimId)); throw new Error(__(`Invalid claim ID %s.`, claimId));
return {};
} }
if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) { if (claimSequence && !claimSequence.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Claim sequence must be a number.')); throw new Error(__('Claim sequence must be a number.'));
return {};
} }
if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) { if (bidPosition && !bidPosition.match(/^-?[1-9][0-9]*$/)) {
console.error(__('Bid position must be a number.')); throw new Error(__('Bid position must be a number.'));
return {};
} }
// Validate and process path // Validate and process path
if (path) { if (path) {
if (!isChannel) { if (!isChannel) {
console.error(__('Only channel URIs may have a path.')); throw new Error(__('Only channel URIs may have a path.'));
return {};
} }
const pathBadChars = path.match(regexInvalidURI); const pathBadChars = path.match(regexInvalidURI);
if (pathBadChars) { if (pathBadChars) {
console.error(__(`Invalid character in path: %s`, pathBadChars.join(', '))); throw new Error(__(`Invalid character in path: %s`, pathBadChars.join(', ')));
return {};
} }
contentName = path; contentName = path;
} else if (pathSep) { } else if (pathSep) {
console.error(__('No path provided after /')); throw new Error(__('No path provided after /'));
return {};
} }
return { return {

View file

@ -264,7 +264,7 @@ export const selectMyClaimUrisWithoutChannels = createSelector(
selectMyClaimsWithoutChannels, selectMyClaimsWithoutChannels,
myClaims => myClaims =>
myClaims myClaims
.sort((a, b) => a.confirmations - b.confirmations) .sort((a, b) => b.timestamp - a.timestamp)
.map(claim => `lbry://${claim.name}#${claim.claim_id}`) .map(claim => `lbry://${claim.name}#${claim.claim_id}`)
); );

View file

@ -236,5 +236,5 @@ export const selectDownloadedUris = createSelector(
info info
.slice() .slice()
.reverse() .reverse()
.map(claim => `lbry://${claim.claim_name}#${claim.claim_id}`) .map(claim => console.log(claim) || `lbry://${claim.claim_name}#${claim.claim_id}`)
); );