Merge pull request #313 from jeffslofish/suport-lbry-link-with-timestamp

This commit is contained in:
Sean Yesmunt 2020-05-11 10:09:07 -04:00 committed by GitHub
commit 3af0b55b8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -12,6 +12,7 @@ declare type LbryUrlObj = {
secondaryClaimSequence?: number, secondaryClaimSequence?: number,
primaryBidPosition?: number, primaryBidPosition?: number,
secondaryBidPosition?: number, secondaryBidPosition?: number,
startTime?: number,
// Below are considered deprecated and should not be used due to unreliableness with claim.canonical_url // Below are considered deprecated and should not be used due to unreliableness with claim.canonical_url
claimName?: string, claimName?: string,

View file

@ -60,6 +60,8 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj
secondaryModSeparator, secondaryModSeparator,
secondaryModValue, secondaryModValue,
] = rest; ] = rest;
const searchParams = new URLSearchParams(qs || '');
const startTime = searchParams.get('t');
// Validate protocol // Validate protocol
if (requireProto && !proto) { if (requireProto && !proto) {
@ -121,6 +123,7 @@ export function parseURI(URL: string, requireProto: boolean = false): LbryUrlObj
: {}), : {}),
...(primaryBidPosition ? { primaryBidPosition: parseInt(primaryBidPosition, 10) } : {}), ...(primaryBidPosition ? { primaryBidPosition: parseInt(primaryBidPosition, 10) } : {}),
...(secondaryBidPosition ? { secondaryBidPosition: parseInt(secondaryBidPosition, 10) } : {}), ...(secondaryBidPosition ? { secondaryBidPosition: parseInt(secondaryBidPosition, 10) } : {}),
...(startTime ? { startTime: parseInt(startTime, 10) } : {}),
// The values below should not be used for new uses of parseURI // The values below should not be used for new uses of parseURI
// They will not work properly with canonical_urls // They will not work properly with canonical_urls
@ -184,6 +187,7 @@ export function buildURI(
primaryBidPosition, primaryBidPosition,
secondaryClaimSequence, secondaryClaimSequence,
secondaryBidPosition, secondaryBidPosition,
startTime,
...deprecatedParts ...deprecatedParts
} = UrlObj; } = UrlObj;
const { claimId, claimName, contentName } = deprecatedParts; const { claimId, claimName, contentName } = deprecatedParts;
@ -233,7 +237,8 @@ export function buildURI(
(secondaryClaimName ? `/${secondaryClaimName}` : '') + (secondaryClaimName ? `/${secondaryClaimName}` : '') +
(secondaryClaimId ? `#${secondaryClaimId}` : '') + (secondaryClaimId ? `#${secondaryClaimId}` : '') +
(secondaryClaimSequence ? `:${secondaryClaimSequence}` : '') + (secondaryClaimSequence ? `:${secondaryClaimSequence}` : '') +
(secondaryBidPosition ? `${secondaryBidPosition}` : '') (secondaryBidPosition ? `${secondaryBidPosition}` : '') +
(startTime ? `?t=${startTime}` : '')
); );
} }
@ -248,6 +253,7 @@ export function normalizeURI(URL: string) {
primaryBidPosition, primaryBidPosition,
secondaryClaimSequence, secondaryClaimSequence,
secondaryBidPosition, secondaryBidPosition,
startTime,
} = parseURI(URL); } = parseURI(URL);
return buildURI({ return buildURI({
@ -259,6 +265,7 @@ export function normalizeURI(URL: string) {
primaryBidPosition, primaryBidPosition,
secondaryClaimSequence, secondaryClaimSequence,
secondaryBidPosition, secondaryBidPosition,
startTime,
}); });
} }