From 88d785a8442bc670be5db291d054fdb6959814ce Mon Sep 17 00:00:00 2001 From: Jeffrey Fisher Date: Thu, 7 May 2020 14:18:40 -0700 Subject: [PATCH] Support lbry:// links with timestamp --- flow-typed/lbryURI.js | 1 + src/lbryURI.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/flow-typed/lbryURI.js b/flow-typed/lbryURI.js index 4365da3..549c991 100644 --- a/flow-typed/lbryURI.js +++ b/flow-typed/lbryURI.js @@ -12,6 +12,7 @@ declare type LbryUrlObj = { secondaryClaimSequence?: number, primaryBidPosition?: number, secondaryBidPosition?: number, + startTime?: number, // Below are considered deprecated and should not be used due to unreliableness with claim.canonical_url claimName?: string, diff --git a/src/lbryURI.js b/src/lbryURI.js index b63c1f2..9b871d7 100644 --- a/src/lbryURI.js +++ b/src/lbryURI.js @@ -60,6 +60,8 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj secondaryModSeparator, secondaryModValue, ] = rest; + const searchParams = new URLSearchParams(qs || ''); + const startTime = searchParams.get('t'); // Validate protocol if (requireProto && !proto) { @@ -121,6 +123,7 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj : {}), ...(primaryBidPosition ? { primaryBidPosition: parseInt(primaryBidPosition, 10) } : {}), ...(secondaryBidPosition ? { secondaryBidPosition: parseInt(secondaryBidPosition, 10) } : {}), + ...(startTime ? { startTime: parseInt(startTime, 10) } : {}), // The values below should not be used for new uses of parseURI // They will not work properly with canonical_urls @@ -184,6 +187,7 @@ export function buildURI( primaryBidPosition, secondaryClaimSequence, secondaryBidPosition, + startTime, ...deprecatedParts } = UrlObj; const { claimId, claimName, contentName } = deprecatedParts; @@ -233,7 +237,8 @@ export function buildURI( (secondaryClaimName ? `/${secondaryClaimName}` : '') + (secondaryClaimId ? `#${secondaryClaimId}` : '') + (secondaryClaimSequence ? `:${secondaryClaimSequence}` : '') + - (secondaryBidPosition ? `${secondaryBidPosition}` : '') + (secondaryBidPosition ? `${secondaryBidPosition}` : '') + + (startTime ? `?t=${startTime}` : '') ); } @@ -248,6 +253,7 @@ export function normalizeURI(URL: string) { primaryBidPosition, secondaryClaimSequence, secondaryBidPosition, + startTime, } = parseURI(URL); return buildURI({ @@ -259,6 +265,7 @@ export function normalizeURI(URL: string) { primaryBidPosition, secondaryClaimSequence, secondaryBidPosition, + startTime, }); }