From 921a46a13ae7828823f7513093dfae1d025681f2 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 18 Oct 2023 16:51:23 +0800 Subject: [PATCH] Linting fixes --- packages/rss-handler/src/index.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/rss-handler/src/index.ts b/packages/rss-handler/src/index.ts index 048592c27..5d1a3c654 100644 --- a/packages/rss-handler/src/index.ts +++ b/packages/rss-handler/src/index.ts @@ -31,7 +31,6 @@ type FeedFetchResult = { async function fetchAndChecksum(url: string): Promise { try { - // Fetch the content from the URL const response = await axios.get(url, { responseType: 'arraybuffer', headers: { @@ -42,15 +41,15 @@ async function fetchAndChecksum(url: string): Promise { }, }) - // Create a sha256 hash of the content const hash = crypto.createHash('sha256') - hash.update(response.data) + hash.update(response.data as Buffer) - return { url, content: response.data, checksum: hash.digest('hex') } + const dataStr = (response.data as Buffer).toString() + + return { url, content: dataStr, checksum: hash.digest('hex') } } catch (error) { - throw new Error( - `Failed to fetch or hash content from ${url}. Error: ${error}` - ) + console.log(error) + throw new Error(`Failed to fetch or hash content from ${url}.`) } } @@ -228,14 +227,13 @@ export const rssHandler = Sentry.GCPFunction.wrapHttpFunction( let lastItemFetchedAt: Date | null = null let lastValidItem: Item | null = null - let updatedLastFetchedChecksum: string | null - let fetchResult = await fetchAndChecksum(feedUrl) + const fetchResult = await fetchAndChecksum(feedUrl) if (fetchResult.checksum === lastFetchedChecksum) { console.log('feed has not been updated', feedUrl, lastFetchedChecksum) return res.status(200) } - updatedLastFetchedChecksum = fetchResult.checksum + const updatedLastFetchedChecksum = fetchResult.checksum // fetch feed let itemCount = 0