Add function to convert an URI to an url that can be shared and opened with lbry-app.
This commit is contained in:
parent
30c18725d8
commit
2f51f79730
2 changed files with 14 additions and 2 deletions
|
@ -22,6 +22,7 @@ export {
|
|||
isURIValid,
|
||||
isURIClaimable,
|
||||
isNameValid,
|
||||
convertToShareLink,
|
||||
} from 'lbryURI';
|
||||
|
||||
// actions
|
||||
|
|
|
@ -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/'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue