Add function to convert an URI to an url that can be shared and opened with lbry-app.

This commit is contained in:
Daniel Dominguez 2018-05-21 14:20:22 -03:00
parent 30c18725d8
commit 2f51f79730
2 changed files with 14 additions and 2 deletions

View file

@ -22,6 +22,7 @@ export {
isURIValid, isURIValid,
isURIClaimable, isURIClaimable,
isNameValid, isNameValid,
convertToShareLink,
} from 'lbryURI'; } from 'lbryURI';
// actions // actions

View file

@ -145,7 +145,7 @@ export function parseURI(URI, requireProto = false) {
* *
* The channelName key will accept names with or without the @ prefix. * The channelName key will accept names with or without the @ prefix.
*/ */
export function buildURI(URIObj, includeProto = true) { export function buildURI(URIObj, includeProto = true, protoDefault = 'lbry://') {
const { claimId, claimSequence, bidPosition, contentName, channelName } = URIObj; const { claimId, claimSequence, bidPosition, contentName, channelName } = URIObj;
let { claimName, path } = URIObj; let { claimName, path } = URIObj;
@ -179,7 +179,7 @@ export function buildURI(URIObj, includeProto = true) {
} }
return ( return (
(includeProto ? 'lbry://' : '') + (includeProto ? protoDefault : '') +
claimName + claimName +
(claimId ? `#${claimId}` : '') + (claimId ? `#${claimId}` : '') +
(claimSequence ? `:${claimSequence}` : '') + (claimSequence ? `:${claimSequence}` : '') +
@ -228,3 +228,14 @@ export function isURIClaimable(URI) {
!parts.path !parts.path
); );
} }
export function convertToShareLink(URI) {
if (URI.match(/pending_claim/)) return URI;
const { claimName, path, bidPosition, claimSequence, claimId } = parseURI(URI);
return buildURI(
{ claimName, path, claimSequence, bidPosition, claimId },
true,
'https://open.lbry.io/'
);
}