fallback to guid if link of rss item is not available

This commit is contained in:
Hongbo Wu
2024-01-26 22:09:53 +08:00
parent 2e1c99780a
commit fd80724d79
2 changed files with 12 additions and 5 deletions

View File

@ -10,6 +10,7 @@ import {
updateSubscriptions,
} from '../../services/update_subscription'
import createHttpTaskWithToken from '../../utils/createTask'
import { logger } from '../../utils/logger'
import { RSSRefreshContext } from './refreshAllFeeds'
type FolderType = 'following' | 'inbox'
@ -475,16 +476,24 @@ const processSubscription = async (
// save each item in the feed
for (const item of feed.items) {
try {
const guid = item.guid || item.link
// use published or updated if isoDate is not available for atom feeds
const isoDate =
item.isoDate || item.published || item.updated || item.created
console.log('Processing feed item', item.links, item.isoDate, feedUrl)
if (!item.links || item.links.length === 0) {
logger.info('Processing feed item', {
guid,
links: item.links,
isoDate,
feedUrl,
})
if (!item.links || item.links.length === 0 || !guid) {
throw new Error('Invalid feed item')
}
const link = getLink(item.links, feedUrl)
// fallback to guid if link is not available
const link = getLink(item.links, feedUrl) || guid
if (!link) {
throw new Error('Invalid feed item link')
}

View File

@ -68,7 +68,6 @@ export const contentFetchRequestHandler: RequestHandler = async (req, res) => {
// users is used when saving article for multiple users
let users = body.users || []
const userId = body.userId
const folder = body.folder
// userId is used when saving article for a single user
if (userId) {
users = [
@ -104,7 +103,6 @@ export const contentFetchRequestHandler: RequestHandler = async (req, res) => {
rssFeedUrl,
savedAt,
publishedAt,
folder,
users,
}