Merge pull request #27 from dan1d/share-link-uri
Add function to convert an URI to an url that can be shared and opened with lbry-app
This commit is contained in:
commit
0c6bffccc3
2 changed files with 7 additions and 2 deletions
|
@ -23,6 +23,7 @@ export {
|
||||||
isURIValid,
|
isURIValid,
|
||||||
isURIClaimable,
|
isURIClaimable,
|
||||||
isNameValid,
|
isNameValid,
|
||||||
|
convertToShareLink,
|
||||||
} from 'lbryURI';
|
} from 'lbryURI';
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
|
|
|
@ -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,7 @@ export function isURIClaimable(URI) {
|
||||||
!parts.path
|
!parts.path
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function convertToShareLink(URI) {
|
||||||
|
return buildURI(parseURI(URI), true, 'https://open.lbry.io/');
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue