From e7fc2c4567569e7cdcd51efd86d25ccd4273ccaa Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 9 Apr 2024 18:39:17 +0800 Subject: [PATCH 1/2] reset failed_at to null if a feed is refreshed successfully after failure --- packages/api/src/jobs/rss/refreshFeed.ts | 2 +- packages/api/src/services/update_subscription.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api/src/jobs/rss/refreshFeed.ts b/packages/api/src/jobs/rss/refreshFeed.ts index 76078a8f4..8fec18c20 100644 --- a/packages/api/src/jobs/rss/refreshFeed.ts +++ b/packages/api/src/jobs/rss/refreshFeed.ts @@ -511,7 +511,7 @@ const processSubscription = async ( // fetch feed let itemCount = 0, - failedAt: Date | undefined + failedAt: Date | null = null const feedLastBuildDate = feed.lastBuildDate logger.info(`Feed last build date ${feedLastBuildDate || 'N/A'}`) diff --git a/packages/api/src/services/update_subscription.ts b/packages/api/src/services/update_subscription.ts index 9d0970ba5..d333f58ba 100644 --- a/packages/api/src/services/update_subscription.ts +++ b/packages/api/src/services/update_subscription.ts @@ -49,7 +49,7 @@ export const updateSubscription = async ( lastFetchedChecksum: newData.lastFetchedChecksum || undefined, status: newData.status || undefined, scheduledAt: newData.scheduledAt || undefined, - failedAt: newData.failedAt || undefined, + failedAt: newData.failedAt, autoAddToLibrary: newData.autoAddToLibrary ?? undefined, isPrivate: newData.isPrivate ?? undefined, fetchContentType: newData.fetchContentType || undefined, From a59c850c5f6f1116e12cd166274547949610f11b Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Tue, 9 Apr 2024 19:44:16 +0800 Subject: [PATCH 2/2] fix telegram channel --- packages/api/src/jobs/rss/refreshFeed.ts | 34 +++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/packages/api/src/jobs/rss/refreshFeed.ts b/packages/api/src/jobs/rss/refreshFeed.ts index 8fec18c20..5afdab813 100644 --- a/packages/api/src/jobs/rss/refreshFeed.ts +++ b/packages/api/src/jobs/rss/refreshFeed.ts @@ -192,22 +192,40 @@ export const fetchAndChecksum = async (url: string) => { const parseFeed = async (url: string, content: string) => { try { - // check if url is a telegram channel - const telegramRegex = /https:\/\/t\.me\/([a-zA-Z0-9_]+)/ + // check if url is a telegram channel or preview + const telegramRegex = /t\.me\/([^/]+)/ const telegramMatch = url.match(telegramRegex) if (telegramMatch) { + let channel = telegramMatch[1] + if (channel.startsWith('s/')) { + channel = channel.slice(2) + } else { + // open the preview page to get the data + const fetchResult = await fetchAndChecksum(`https://t.me/s/${channel}`) + if (!fetchResult) { + return null + } + + content = fetchResult.content + } + const dom = parseHTML(content).document - const title = dom.querySelector('meta[property="og:title"]') + const title = + dom + .querySelector('meta[property="og:title"]') + ?.getAttribute('content') || dom.title // post has attribute data-post const posts = dom.querySelectorAll('[data-post]') const items = Array.from(posts) .map((post) => { - const id = post.getAttribute('data-post') + const id = post.getAttribute('data-post')?.split('/')[1] if (!id) { return null } - const url = `https://t.me/${telegramMatch[1]}/${id}` + const url = `https://t.me/s/${channel}/${id}` + const content = post.outerHTML + // find the