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,
primaryBidPosition?: number,
secondaryBidPosition?: number,
startTime?: number,
// Below are considered deprecated and should not be used due to unreliableness with claim.canonical_url
claimName?: string,

View file

@ -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,
});
}