From ad1c826f2c408c7f54bd2476ce1a89598cfff262 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Tue, 13 Jul 2021 00:17:04 +0800 Subject: [PATCH] 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. --- ui/component/claimMenuList/view.jsx | 4 ++-- ui/util/url.js | 9 ++++++--- web/src/routes.js | 13 ++++++++----- web/src/rss.js | 2 +- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/ui/component/claimMenuList/view.jsx b/ui/component/claimMenuList/view.jsx index 822bd13f8..ce9e4de91 100644 --- a/ui/component/claimMenuList/view.jsx +++ b/ui/component/claimMenuList/view.jsx @@ -103,7 +103,7 @@ function ClaimMenuList(props: Props) { } 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'; // $FlowFixMe const isPlayable = @@ -369,7 +369,7 @@ function ClaimMenuList(props: Props) {
- {isChannelPage && IS_WEB && ( + {isChannelPage && IS_WEB && rssUrl && (
diff --git a/ui/util/url.js b/ui/util/url.js index 8cb51e47f..2c88d899d 100644 --- a/ui/util/url.js +++ b/ui/util/url.js @@ -148,8 +148,11 @@ export const generateShareUrl = ( return url; }; -export const generateRssUrl = (domain, lbryUrl) => { - const { channelName, channelClaimId } = parseURI(lbryUrl); - const url = `${domain}/$/rss/@${channelName}${channelClaimId ? `/${channelClaimId.slice(0, 2)}` : ''}`; +export const generateRssUrl = (domain, channelClaim) => { + if (!channelClaim || channelClaim.value_type !== 'channel' || !channelClaim.canonical_url) { + return ''; + } + + const url = `${domain}/$/rss/${channelClaim.canonical_url.replace('lbry://', '').replace('#', ':')}`; return url; }; diff --git a/web/src/routes.js b/web/src/routes.js index 8284ef9dd..112a546a0 100644 --- a/web/src/routes.js +++ b/web/src/routes.js @@ -18,6 +18,12 @@ function getStreamUrl(ctx) { 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) => { let content; try { @@ -43,11 +49,8 @@ router.get(`/$/stream/:claimName/:claimId`, async (ctx) => { ctx.redirect(streamUrl); }); -router.get(`/$/rss/:claimName/:claimId`, async (ctx) => { - const xml = await getRss(ctx); - ctx.set('Content-Type', 'application/rss+xml'); - ctx.body = xml; -}); +router.get(`/$/rss/:claimName/:claimId`, rssMiddleware); +router.get(`/$/rss/:claimName::claimId`, rssMiddleware); router.get('*', async (ctx) => { const html = await getHtml(ctx); diff --git a/web/src/rss.js b/web/src/rss.js index d5f6d3077..d1f5d0710 100644 --- a/web/src/rss.js +++ b/web/src/rss.js @@ -108,7 +108,7 @@ async function getRss(ctx) { 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()); }