Merge pull request #193 from lbryio/can

canonical_url fixes
This commit is contained in:
Sean Yesmunt 2019-09-05 09:52:57 -04:00 committed by GitHub
commit 362d764c4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 108 additions and 73 deletions

84
dist/bundle.es.js vendored
View file

@ -692,7 +692,7 @@ const Lbry = {
// Returns a human readable media type based on the content type or extension of a file that is returned by the sdk
getMediaType: (contentType, fileName) => {
if (fileName) {
const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(jpeg|jpg|png|gif)$/i, 'image'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book'], [/\.(lbry)$/i, 'application']];
const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(jpeg|jpg|png|gif|svg)$/i, 'image'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book'], [/\.(lbry)$/i, 'application']];
const res = formats.reduce((ret, testpair) => {
switch (testpair[0].test(ret)) {
@ -1045,7 +1045,7 @@ function buildURI(UrlObj, includeProto = true, protoDefault = 'lbry://') {
const { claimId, claimName, contentName } = deprecatedParts;
if (!claimName && !channelName && !streamName) {
throw new Error(__("'claimName', 'channelName', and 'streamName' are all empty. One must be present to build a url."));
console.error(__("'claimName', 'channelName', and 'streamName' are all empty. One must be present to build a url."));
}
const formattedChannelName = channelName && (channelName.startsWith('@') ? channelName : `@${channelName}`);
@ -1724,8 +1724,8 @@ const makeSelectRecommendedContentForUri = uri => reselect.createSelector(makeSe
let recommendedContent;
if (claim) {
// If we are at a vanity uri, build the full uri so we can properly filter
const currentUri = atVanityURI ? buildURI({ streamClaimId: claim.claim_id, streamName: claim.name }) : uri;
// always grab full URL - this can change once search returns canonical
const currentUri = buildURI({ streamClaimId: claim.claim_id, streamName: claim.name });
const { title } = claim.value;
@ -1747,13 +1747,12 @@ const makeSelectFirstRecommendedFileForUri = uri => reselect.createSelector(make
// accepts a regular claim uri lbry://something
// returns the channel uri that created this claim lbry://@channel
const makeSelectChannelForClaimUri = (uri, includePrefix = false) => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
if (!claim || !claim.signing_channel) {
if (!claim || !claim.signing_channel || !claim.signing_channel.canonical_url) {
return null;
}
const { claim_id: claimId, name } = claim.signing_channel;
let channel = `${name}#${claimId}`;
return includePrefix ? `lbry://${channel}` : channel;
const { canonical_url: canonicalUrl } = claim.signing_channel;
return includePrefix ? canonicalUrl : canonicalUrl.slice('lbry://'.length);
});
const makeSelectTagsForUri = uri => reselect.createSelector(makeSelectMetadataForUri(uri), metadata => {
@ -1772,6 +1771,8 @@ const makeSelectShortUrlForUri = uri => reselect.createSelector(makeSelectClaimF
const makeSelectCanonicalUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.canonical_url);
const makeSelectPermanentUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.permanent_url);
const makeSelectSupportsForUri = uri => reselect.createSelector(selectSupportsByOutpoint, makeSelectClaimForUri(uri), (byOutpoint, claim) => {
if (!claim || !claim.is_mine) {
return null;
@ -1830,8 +1831,6 @@ function creditsToString(amount) {
return creditString;
}
//
function doUpdateBalance() {
return (dispatch, getState) => {
const {
@ -2874,7 +2873,7 @@ const selectIsResolvingPublishUris = reselect.createSelector(selectState$5, sele
const { isChannel } = parseURI(uri);
let isResolvingShortUri;
if (isChannel) {
if (isChannel && name) {
const shortUri = buildURI({ streamName: name });
isResolvingShortUri = resolvingUris.includes(shortUri);
}
@ -3034,7 +3033,7 @@ const doUploadThumbnail = (filePath, thumbnailBuffer, fsAdapter, fs, path) => di
const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => {
const { name, amount, value = {} } = claim;
const channelName = claim && claim.signing_channel && claim.signing_channel.normalized_name || null;
const channelName = claim && claim.signing_channel && claim.signing_channel.name || null;
const {
author,
description,
@ -3543,6 +3542,7 @@ function handleClaimAction(state, action) {
const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId);
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
let newResolvingUrls = new Set(state.resolvingUris);
Object.entries(resolveInfo).forEach(([url, resolveResponse]) => {
// $FlowFixMe
@ -3554,11 +3554,26 @@ function handleClaimAction(state, action) {
if (stream) {
byId[stream.claim_id] = stream;
byUri[url] = stream.claim_id;
} else if (channel) {
byId[channel.claim_id] = channel;
byUri[url] = channel.claim_id;
// Also add the permanent_url here until lighthouse returns canonical_url for search results
byUri[stream.permanent_url] = stream.claim_id;
newResolvingUrls.delete(stream.canonical_url);
newResolvingUrls.delete(stream.permanent_url);
}
if (channel) {
if (!stream) {
byUri[url] = channel.claim_id;
}
byId[channel.claim_id] = channel;
// Also add the permanent_url here until lighthouse returns canonical_url for search results
byUri[channel.permanent_url] = channel.claim_id;
byUri[channel.canonical_url] = channel.claim_id;
newResolvingUrls.delete(channel.canonical_url);
newResolvingUrls.delete(channel.permanent_url);
}
newResolvingUrls.delete(url);
if (!stream && !channel) {
byUri[url] = null;
}
@ -3568,10 +3583,27 @@ function handleClaimAction(state, action) {
byId,
claimsByUri: byUri,
channelClaimCounts,
resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri])
resolvingUris: Array.from(newResolvingUrls)
});
}
reducers[RESOLVE_URIS_STARTED] = (state, action) => {
const { uris } = action.data;
const oldResolving = state.resolvingUris || [];
const newResolving = oldResolving.slice();
uris.forEach(uri => {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
});
return Object.assign({}, state, {
resolvingUris: newResolving
});
};
reducers[RESOLVE_URIS_COMPLETED] = (state, action) => {
return _extends$5({}, handleClaimAction(state, action));
};
@ -3669,7 +3701,7 @@ reducers[FETCH_CHANNEL_CLAIMS_COMPLETED] = (state, action) => {
allClaimIds.add(claim.claim_id);
currentPageClaimIds.push(claim.claim_id);
byId[claim.claim_id] = claim;
claimsByUri[`lbry://${claim.name}#${claim.claim_id}`] = claim.claim_id;
claimsByUri[claim.canonical_url] = claim.claim_id;
});
}
@ -3742,23 +3774,6 @@ reducers[UPDATE_CHANNEL_COMPLETED] = (state, action) => {
});
};
reducers[RESOLVE_URIS_STARTED] = (state, action) => {
const { uris } = action.data;
const oldResolving = state.resolvingUris || [];
const newResolving = oldResolving.slice();
uris.forEach(uri => {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
});
return Object.assign({}, state, {
resolvingUris: newResolving
});
};
reducers[CLAIM_SEARCH_STARTED] = (state, action) => {
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
fetchingClaimSearchByQuery[action.data.query] = true;
@ -4900,6 +4915,7 @@ exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri;
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris;
exports.makeSelectPendingByUri = makeSelectPendingByUri;
exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri;
exports.makeSelectPublishFormValue = makeSelectPublishFormValue;
exports.makeSelectQueryWithOptions = makeSelectQueryWithOptions;
exports.makeSelectRecommendedContentForUri = makeSelectRecommendedContentForUri;

View file

@ -173,6 +173,7 @@ export {
makeSelectClaimsInChannelForCurrentPageState,
makeSelectShortUrlForUri,
makeSelectCanonicalUrlForUri,
makeSelectPermanentUrlForUri,
makeSelectSupportsForUri,
selectPendingById,
selectClaimsById,

View file

@ -37,7 +37,7 @@ const Lbry: LbryTypes = {
const formats = [
[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'],
[/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'],
[/\.(jpeg|jpg|png|gif)$/i, 'image'],
[/\.(jpeg|jpg|png|gif|svg)$/i, 'image'],
[/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'],
[/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'],
[/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'],

View file

@ -199,7 +199,7 @@ export function buildURI(
}
if (!claimName && !channelName && !streamName) {
throw new Error(
console.error(
__(
"'claimName', 'channelName', and 'streamName' are all empty. One must be present to build a url."
)

View file

@ -173,8 +173,7 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis
dispatch: Dispatch
) => {
const { name, amount, value = {} } = claim;
const channelName =
(claim && claim.signing_channel && claim.signing_channel.normalized_name) || null;
const channelName = (claim && claim.signing_channel && claim.signing_channel.name) || null;
const {
author,
description,

View file

@ -1,4 +1,3 @@
// @flow
import * as ACTIONS from 'constants/action_types';
import Lbry from 'lbry';
import { doToast } from 'redux/actions/notifications';
@ -11,7 +10,7 @@ export function doUpdateBalance() {
const {
wallet: { balance: balanceInStore },
} = getState();
Lbry.account_balance().then((response: BalanceResponse) => {
Lbry.account_balance().then(response => {
const { available } = response;
const balance = parseFloat(available);
if (balanceInStore !== balance) {
@ -217,7 +216,8 @@ export function doSendTip(amount, claimId, isSupport, successCallback, errorCall
const balance = selectBalance(state);
const myClaims = selectMyClaimsRaw(state);
const shouldSupport = isSupport || (myClaims ? myClaims.find(claim => claim.claim_id === claimId) : false);
const shouldSupport =
isSupport || (myClaims ? myClaims.find(claim => claim.claim_id === claimId) : false);
if (balance - amount <= 0) {
dispatch(

View file

@ -65,6 +65,7 @@ function handleClaimAction(state: State, action: any): State {
const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId);
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
let newResolvingUrls = new Set(state.resolvingUris);
Object.entries(resolveInfo).forEach(([url: string, resolveResponse: ResolveResponse]) => {
// $FlowFixMe
@ -76,11 +77,26 @@ function handleClaimAction(state: State, action: any): State {
if (stream) {
byId[stream.claim_id] = stream;
byUri[url] = stream.claim_id;
} else if (channel) {
byId[channel.claim_id] = channel;
byUri[url] = channel.claim_id;
// Also add the permanent_url here until lighthouse returns canonical_url for search results
byUri[stream.permanent_url] = stream.claim_id;
newResolvingUrls.delete(stream.canonical_url);
newResolvingUrls.delete(stream.permanent_url);
}
if (channel) {
if (!stream) {
byUri[url] = channel.claim_id;
}
byId[channel.claim_id] = channel;
// Also add the permanent_url here until lighthouse returns canonical_url for search results
byUri[channel.permanent_url] = channel.claim_id;
byUri[channel.canonical_url] = channel.claim_id;
newResolvingUrls.delete(channel.canonical_url);
newResolvingUrls.delete(channel.permanent_url);
}
newResolvingUrls.delete(url);
if (!stream && !channel) {
byUri[url] = null;
}
@ -90,10 +106,27 @@ function handleClaimAction(state: State, action: any): State {
byId,
claimsByUri: byUri,
channelClaimCounts,
resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri]),
resolvingUris: Array.from(newResolvingUrls),
});
}
reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state: State, action: any): State => {
const { uris }: { uris: Array<string> } = action.data;
const oldResolving = state.resolvingUris || [];
const newResolving = oldResolving.slice();
uris.forEach(uri => {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
});
return Object.assign({}, state, {
resolvingUris: newResolving,
});
};
reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = (state: State, action: any): State => {
return {
...handleClaimAction(state, action),
@ -196,7 +229,7 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state: State, action: any):
allClaimIds.add(claim.claim_id);
currentPageClaimIds.push(claim.claim_id);
byId[claim.claim_id] = claim;
claimsByUri[`lbry://${claim.name}#${claim.claim_id}`] = claim.claim_id;
claimsByUri[claim.canonical_url] = claim.claim_id;
});
}
@ -269,23 +302,6 @@ reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State
});
};
reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state: State, action: any): State => {
const { uris }: { uris: Array<string> } = action.data;
const oldResolving = state.resolvingUris || [];
const newResolving = oldResolving.slice();
uris.forEach(uri => {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
});
return Object.assign({}, state, {
resolvingUris: newResolving,
});
};
reducers[ACTIONS.CLAIM_SEARCH_STARTED] = (state: State, action: any): State => {
const fetchingClaimSearchByQuery = Object.assign({}, state.fetchingClaimSearchByQuery);
fetchingClaimSearchByQuery[action.data.query] = true;

View file

@ -456,10 +456,8 @@ export const makeSelectRecommendedContentForUri = (uri: string) =>
let recommendedContent;
if (claim) {
// If we are at a vanity uri, build the full uri so we can properly filter
const currentUri = atVanityURI
? buildURI({ streamClaimId: claim.claim_id, streamName: claim.name })
: uri;
// always grab full URL - this can change once search returns canonical
const currentUri = buildURI({ streamClaimId: claim.claim_id, streamName: claim.name });
const { title } = claim.value;
@ -488,14 +486,13 @@ export const makeSelectFirstRecommendedFileForUri = (uri: string) =>
export const makeSelectChannelForClaimUri = (uri: string, includePrefix: boolean = false) =>
createSelector(
makeSelectClaimForUri(uri),
(claim: ?StreamClaim) => {
if (!claim || !claim.signing_channel) {
(claim: ?Claim) => {
if (!claim || !claim.signing_channel || !claim.signing_channel.canonical_url) {
return null;
}
const { claim_id: claimId, name } = claim.signing_channel;
let channel = `${name}#${claimId}`;
return includePrefix ? `lbry://${channel}` : channel;
const { canonical_url: canonicalUrl } = claim.signing_channel;
return includePrefix ? canonicalUrl : canonicalUrl.slice('lbry://'.length);
}
);
@ -539,6 +536,12 @@ export const makeSelectCanonicalUrlForUri = (uri: string) =>
claim => claim && claim.canonical_url
);
export const makeSelectPermanentUrlForUri = (uri: string) =>
createSelector(
makeSelectClaimForUri(uri),
claim => claim && claim.permanent_url
);
export const makeSelectSupportsForUri = (uri: string) =>
createSelector(
selectSupportsByOutpoint,

View file

@ -84,7 +84,7 @@ export const selectIsResolvingPublishUris = createSelector(
const { isChannel } = parseURI(uri);
let isResolvingShortUri;
if (isChannel) {
if (isChannel && name) {
const shortUri = buildURI({ streamName: name });
isResolvingShortUri = resolvingUris.includes(shortUri);
}