Shorten the RSS URL

This will be backward compatible with existing format that uses the full claim_id.
This commit is contained in:
infinite-persistence 2021-07-09 17:33:34 +08:00
parent f6641ee045
commit e7bed19391
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
2 changed files with 12 additions and 10 deletions

View file

@ -150,6 +150,6 @@ export const generateShareUrl = (
export const generateRssUrl = (domain, lbryUrl) => {
const { channelName, channelClaimId } = parseURI(lbryUrl);
const url = `${domain}/$/rss/@${channelName}/${channelClaimId}`;
const url = `${domain}/$/rss/@${channelName}/${channelClaimId.slice(0, 2)}`;
return url;
};

View file

@ -16,15 +16,17 @@ async function doClaimSearch(options) {
return results ? results.items : undefined;
}
async function getChannelClaim(claimId) {
const options = {
claim_ids: [claimId],
page_size: 1,
no_totals: true,
};
async function getChannelClaim(name, claimId) {
let claim;
try {
const url = `lbry://${name}#${claimId}`;
const response = await Lbry.resolve({ urls: [url] });
const claims = await doClaimSearch(options);
return claims ? claims[0] : undefined;
if (response && response[url] && !response[url].error) {
claim = response && response[url];
}
} catch {}
return claim || 'The RSS URL is invalid or is not associated with any channel.';
}
async function getClaimsFromChannel(claimId, count) {
@ -86,7 +88,7 @@ async function getRss(ctx) {
return 'Invalid URL';
}
const channelClaim = await getChannelClaim(ctx.params.claimId);
const channelClaim = await getChannelClaim(ctx.params.claimName, ctx.params.claimId);
if (typeof channelClaim === 'string' || !channelClaim) {
return channelClaim;
}