RSS: Use canonical_url (with ':') instead of slicing to 2 characters.
## Changes - Change to canonical_url (with ':'). - The old format of 'claimName/claimId' needs to be supported still, since we shipped with it. ## Notes - It would be nice to use regex instead of 2 separate paths, but I couldn't figure out how to make the koa variables work.
This commit is contained in:
parent
4bd5beb2f6
commit
ad1c826f2c
4 changed files with 17 additions and 11 deletions
|
@ -103,7 +103,7 @@ function ClaimMenuList(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const shareUrl: string = generateShareUrl(SHARE_DOMAIN, uri);
|
const shareUrl: string = generateShareUrl(SHARE_DOMAIN, uri);
|
||||||
const rssUrl: string = isChannel ? generateRssUrl(URL, uri) : '';
|
const rssUrl: string = isChannel ? generateRssUrl(URL, claim) : '';
|
||||||
const isCollectionClaim = claim && claim.value_type === 'collection';
|
const isCollectionClaim = claim && claim.value_type === 'collection';
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
const isPlayable =
|
const isPlayable =
|
||||||
|
@ -369,7 +369,7 @@ function ClaimMenuList(props: Props) {
|
||||||
|
|
||||||
<hr className="menu__separator" />
|
<hr className="menu__separator" />
|
||||||
|
|
||||||
{isChannelPage && IS_WEB && (
|
{isChannelPage && IS_WEB && rssUrl && (
|
||||||
<MenuItem className="comment__menu-option" onSelect={handleCopyRssLink}>
|
<MenuItem className="comment__menu-option" onSelect={handleCopyRssLink}>
|
||||||
<div className="menu__link">
|
<div className="menu__link">
|
||||||
<Icon aria-hidden icon={ICONS.RSS} />
|
<Icon aria-hidden icon={ICONS.RSS} />
|
||||||
|
|
|
@ -148,8 +148,11 @@ export const generateShareUrl = (
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateRssUrl = (domain, lbryUrl) => {
|
export const generateRssUrl = (domain, channelClaim) => {
|
||||||
const { channelName, channelClaimId } = parseURI(lbryUrl);
|
if (!channelClaim || channelClaim.value_type !== 'channel' || !channelClaim.canonical_url) {
|
||||||
const url = `${domain}/$/rss/@${channelName}${channelClaimId ? `/${channelClaimId.slice(0, 2)}` : ''}`;
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${domain}/$/rss/${channelClaim.canonical_url.replace('lbry://', '').replace('#', ':')}`;
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,12 @@ function getStreamUrl(ctx) {
|
||||||
return streamUrl;
|
return streamUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rssMiddleware = async (ctx) => {
|
||||||
|
const xml = await getRss(ctx);
|
||||||
|
ctx.set('Content-Type', 'application/rss+xml');
|
||||||
|
ctx.body = xml;
|
||||||
|
};
|
||||||
|
|
||||||
router.get(`/$/api/content/get`, async (ctx) => {
|
router.get(`/$/api/content/get`, async (ctx) => {
|
||||||
let content;
|
let content;
|
||||||
try {
|
try {
|
||||||
|
@ -43,11 +49,8 @@ router.get(`/$/stream/:claimName/:claimId`, async (ctx) => {
|
||||||
ctx.redirect(streamUrl);
|
ctx.redirect(streamUrl);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get(`/$/rss/:claimName/:claimId`, async (ctx) => {
|
router.get(`/$/rss/:claimName/:claimId`, rssMiddleware);
|
||||||
const xml = await getRss(ctx);
|
router.get(`/$/rss/:claimName::claimId`, rssMiddleware);
|
||||||
ctx.set('Content-Type', 'application/rss+xml');
|
|
||||||
ctx.body = xml;
|
|
||||||
});
|
|
||||||
|
|
||||||
router.get('*', async (ctx) => {
|
router.get('*', async (ctx) => {
|
||||||
const html = await getHtml(ctx);
|
const html = await getHtml(ctx);
|
||||||
|
|
|
@ -108,7 +108,7 @@ async function getRss(ctx) {
|
||||||
return channelClaim;
|
return channelClaim;
|
||||||
}
|
}
|
||||||
|
|
||||||
const feed = await getFeed(channelClaim, `${URL}/$/rss/${ctx.params.claimName}/${ctx.params.claimId}`);
|
const feed = await getFeed(channelClaim, `${URL}${ctx.request.url}`);
|
||||||
return postProcess(feed.rss2());
|
return postProcess(feed.rss2());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue