From 2f51f79730aeb60cb4763aacb0bdf54c2f0fe4f8 Mon Sep 17 00:00:00 2001 From: Daniel Dominguez Date: Mon, 21 May 2018 14:20:22 -0300 Subject: [PATCH] Add function to convert an URI to an url that can be shared and opened with lbry-app. --- src/index.js | 1 + src/lbryURI.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index c6f8ab7..bddde8b 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,7 @@ export { isURIValid, isURIClaimable, isNameValid, + convertToShareLink, } from 'lbryURI'; // actions diff --git a/src/lbryURI.js b/src/lbryURI.js index 9fd136b..c755357 100644 --- a/src/lbryURI.js +++ b/src/lbryURI.js @@ -145,7 +145,7 @@ export function parseURI(URI, requireProto = false) { * * 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; let { claimName, path } = URIObj; @@ -179,7 +179,7 @@ export function buildURI(URIObj, includeProto = true) { } return ( - (includeProto ? 'lbry://' : '') + + (includeProto ? protoDefault : '') + claimName + (claimId ? `#${claimId}` : '') + (claimSequence ? `:${claimSequence}` : '') + @@ -228,3 +228,14 @@ export function isURIClaimable(URI) { !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/' + ); +}