diff --git a/web/src/rss.js b/web/src/rss.js index 2a9a39067e..9d74cee3c7 100644 --- a/web/src/rss.js +++ b/web/src/rss.js @@ -1,9 +1,8 @@ -const { fetchStreamUrl } = require('./fetchStreamUrl'); const { lbryProxy: Lbry } = require('../lbry'); const { URL, SITE_NAME, PROXY_URL } = require('../../config.js'); -const Mime = require('mime-types'); const Rss = require('rss'); const moment = require('moment'); +const { generateContentUrl } = require('./fetchStreamUrl'); Lbry.setDaemonConnectionString(PROXY_URL); const NUM_ENTRIES = 500; @@ -76,37 +75,41 @@ function encodeWithSpecialCharEncode(string) { * @param claims Array of freaking claims. * @returns {Array<{status, value}> | null} */ -async function fetchStreamUrls(claims) { - return Promise.allSettled(claims.map((c) => fetchStreamUrl(c.name, c.claim_id))) - .then((results) => results) - .catch(() => null); +function fetchStreamUrls(claims) { + try { + const results = claims.map((c) => generateContentUrl(c)); + return results; + } catch (error) { + console.error(error); // eslint-disable-line no-console + return null; + } } -async function generateEnclosureForClaimContent(claim, streamUrl) { +function generateEnclosureForClaimContent(claim, streamUrl) { const value = claim.value; if (!value || !value.stream_type) { return undefined; } - const fileExt = value.source && value.source.media_type && '.' + Mime.extension(value.source.media_type); + // const fileExt = value.source && value.source.media_type && '.' + Mime.extension(value.source.media_type); switch (value.stream_type) { case 'video': return { - url: streamUrl + (streamUrl.endsWith('.mp4') ? '' : fileExt || '.mp4'), + url: streamUrl, type: (value.source && value.source.media_type) || 'video/mp4', size: (value.source && value.source.size) || 0, // Per spec, 0 is a valid fallback. }; case 'audio': return { - url: streamUrl + (streamUrl.endsWith('.mp3') ? '' : fileExt || '.mp3'), + url: streamUrl, type: (value.source && value.source.media_type) || 'audio/mpeg', size: (value.source && value.source.size) || 0, // Per spec, 0 is a valid fallback. }; case 'image': return { - url: streamUrl + (streamUrl.endsWith('.jpg') ? '' : fileExt || '.jpg'), + url: streamUrl, type: (value.source && value.source.media_type) || 'image/jpeg', size: (value.source && value.source.size) || 0, // Per spec, 0 is a valid fallback. }; @@ -266,7 +269,7 @@ async function generateFeed(feedLink, channelClaim, claimsInChannel) { }); // --- Parallel pre-fetch of stream url --- - const streamUrls = await fetchStreamUrls(claimsInChannel); + const streamUrls = fetchStreamUrls(claimsInChannel); // --- Content --- for (let i = 0; i < claimsInChannel.length; ++i) { @@ -283,7 +286,6 @@ async function generateFeed(feedLink, channelClaim, claimsInChannel) { c.value && c.value.release_time ? c.value.release_time * 1000 : c.meta && c.meta.creation_timestamp * 1000; const claimStreamUrl = streamUrls ? streamUrls[i] : ''; - const streamUrl = claimStreamUrl.status === 'fulfilled' ? claimStreamUrl.value : ''; feed.item({ title: title, @@ -292,7 +294,7 @@ async function generateFeed(feedLink, channelClaim, claimsInChannel) { guid: undefined, // defaults to 'url' author: undefined, // defaults feed author property date: new Date(date), - enclosure: await generateEnclosureForClaimContent(c, streamUrl), + enclosure: generateEnclosureForClaimContent(c, claimStreamUrl), custom_elements: [ { 'itunes:title': title }, { 'itunes:author': channelTitle },