fix getting 403 when parsing some rss url by setting a user agent in the request

This commit is contained in:
Hongbo Wu
2023-09-27 10:38:49 +08:00
parent bebcaaf44b
commit 010e2841da
2 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import Parser from 'rss-parser'
import { Brackets } from 'typeorm'
import { Subscription } from '../../entity/subscription'
import { User } from '../../entity/user'
import { getRepository } from '../../entity/utils'
@ -31,13 +32,17 @@ import { Merge } from '../../util'
import { analytics } from '../../utils/analytics'
import { enqueueRssFeedFetch } from '../../utils/createTask'
import { authorized } from '../../utils/helpers'
import { Brackets } from 'typeorm'
type PartialSubscription = Omit<Subscription, 'newsletterEmail'>
const parser = new Parser({
timeout: 30000, // 30 seconds
maxRedirects: 5,
headers: {
// some rss feeds require user agent
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
},
})
export type SubscriptionsSuccessPartial = Merge<

View File

@ -118,9 +118,16 @@ Sentry.GCPFunction.init({
const signToken = promisify(jwt.sign)
const parser = new Parser({
timeout: 60000, // 60 seconds
maxRedirects: 10,
customFields: {
item: [['link', 'links', { keepArray: true }], 'published', 'updated'],
},
headers: {
// some rss feeds require user agent
'User-Agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
},
})
// get link following the order of preference: via, alternate, self