mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
commit
44c9bfce48
2 changed files with 28 additions and 4 deletions
|
|
@ -572,16 +572,22 @@ export const enqueueRssFeedFetch = async (
|
|||
const { GOOGLE_CLOUD_PROJECT } = process.env
|
||||
const payload = {
|
||||
subscriptionId: rssFeedSubscription.id,
|
||||
userId: rssFeedSubscription.user.id,
|
||||
feedUrl: rssFeedSubscription.url,
|
||||
lastFetchedAt: rssFeedSubscription.lastFetchedAt,
|
||||
}
|
||||
|
||||
const headers = {
|
||||
[OmnivoreAuthorizationHeader]: generateVerificationToken(
|
||||
rssFeedSubscription.user.id
|
||||
),
|
||||
}
|
||||
|
||||
const createdTasks = await createHttpTaskWithToken({
|
||||
project: GOOGLE_CLOUD_PROJECT,
|
||||
queue: 'omnivore-rss-queue',
|
||||
payload,
|
||||
taskHandlerUrl: env.queue.rssFeedTaskHandlerUrl,
|
||||
requestHeaders: headers,
|
||||
})
|
||||
|
||||
if (!createdTasks || !createdTasks[0].name) {
|
||||
|
|
|
|||
|
|
@ -98,13 +98,31 @@ export const rssHandler = Sentry.GCPFunction.wrapHttpFunction(
|
|||
return res.status(500).send('INTERNAL_SERVER_ERROR')
|
||||
}
|
||||
|
||||
const token = req.header('Omnivore-Authorization')
|
||||
if (!token) {
|
||||
console.error('Missing authorization header')
|
||||
return res.status(401).send('UNAUTHORIZED')
|
||||
}
|
||||
|
||||
try {
|
||||
let userId: string
|
||||
|
||||
try {
|
||||
const decoded = jwt.verify(token, process.env.JWT_SECRET) as {
|
||||
uid: string
|
||||
}
|
||||
userId = decoded.uid
|
||||
} catch (e) {
|
||||
console.error('Authorization error', e)
|
||||
return res.status(401).send('UNAUTHORIZED')
|
||||
}
|
||||
|
||||
if (!isRssFeedRequest(req.body)) {
|
||||
console.error('Invalid request body', req.body)
|
||||
return res.status(400).send('INVALID_REQUEST_BODY')
|
||||
}
|
||||
|
||||
const { userId, feedUrl, subscriptionId, lastFetchedAt } = req.body
|
||||
const { feedUrl, subscriptionId, lastFetchedAt } = req.body
|
||||
console.log('Processing feed', feedUrl, lastFetchedAt)
|
||||
|
||||
// fetch feed
|
||||
|
|
@ -121,10 +139,10 @@ export const rssHandler = Sentry.GCPFunction.wrapHttpFunction(
|
|||
continue
|
||||
}
|
||||
|
||||
// skip old items and items that were published before 48h
|
||||
// skip old items and items that were published before 24h
|
||||
const publishedAt = new Date(item.isoDate)
|
||||
if (
|
||||
publishedAt < new Date(Date.now() - 48 * 60 * 60 * 1000) ||
|
||||
publishedAt < new Date(Date.now() - 24 * 60 * 60 * 1000) ||
|
||||
publishedAt < new Date(lastFetchedAt)
|
||||
) {
|
||||
console.log('Skipping old feed item', item.link)
|
||||
|
|
|
|||
Loading…
Reference in a new issue