diff --git a/src/modules/processing/services/snapchat.js b/src/modules/processing/services/snapchat.js index 78fb1cb8..44a2b84e 100644 --- a/src/modules/processing/services/snapchat.js +++ b/src/modules/processing/services/snapchat.js @@ -9,13 +9,17 @@ async function getSpotlight(id) { const html = await fetch(`https://www.snapchat.com/spotlight/${id}`, { headers: { 'User-Agent': genericUserAgent } }).then((r) => r.text()).catch(() => null); - if (!html) return { error: 'ErrorCouldntFetch' }; + if (!html) { + return { error: 'ErrorCouldntFetch' }; + } const videoURL = html.match(SPOTLIGHT_VIDEO_REGEX)?.[1]; - if (videoURL) return { - urls: videoURL, - filename: `snapchat_${id}.mp4`, - audioFilename: `snapchat_${id}_audio` + if (videoURL) { + return { + urls: videoURL, + filename: `snapchat_${id}.mp4`, + audioFilename: `snapchat_${id}_audio` + } } } @@ -23,7 +27,9 @@ async function getStory(username, storyId) { const html = await fetch(`https://www.snapchat.com/add/${username}${storyId ? `/${storyId}` : ''}`, { headers: { 'User-Agent': genericUserAgent } }).then((r) => r.text()).catch(() => null); - if (!html) return { error: 'ErrorCouldntFetch' }; + if (!html) { + return { error: 'ErrorCouldntFetch' }; + } const nextDataString = html.match(NEXT_DATA_REGEX)?.[1]; if (nextDataString) { @@ -33,11 +39,12 @@ async function getStory(username, storyId) { if (storyIdParam && data.props.pageProps.story) { const story = data.props.pageProps.story.snapList.find((snap) => snap.snapId.value === storyIdParam); if (story) { - if (story.snapMediaType === 0) + if (story.snapMediaType === 0) { return { urls: story.snapUrls.mediaUrl, isPhoto: true } + } return { urls: story.snapUrls.mediaUrl, @@ -64,9 +71,16 @@ export default async function(obj) { let params = obj; if (obj.url.hostname === 't.snapchat.com' && obj.shortLink) { const link = await getRedirectingURL(`https://t.snapchat.com/${obj.shortLink}`); - if (!link || !link.startsWith('https://www.snapchat.com/')) return { error: 'ErrorCouldntFetch' }; + + if (!link?.startsWith('https://www.snapchat.com/')) { + return { error: 'ErrorCouldntFetch' }; + } + const extractResult = extract(normalizeURL(link)); - if (!extractResult || extractResult.host !== 'snapchat') return { error: 'ErrorCouldntFetch' }; + if (extractResult?.host !== 'snapchat') { + return { error: 'ErrorCouldntFetch' }; + } + params = extractResult.patternMatch; }