Skip to content

Commit

Permalink
Merge pull request #25 from MarcelRobitaille/issue_22
Browse files Browse the repository at this point in the history
Gracefully handle channel page giving 404
  • Loading branch information
MarcelRobitaille authored Jan 3, 2025
2 parents 4fac7ef + cd9443e commit 18e1460
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [3.0.2] 2025-01-03

### Fixes
- Fix writing headers after sending response in authentication server.
- Gracefully handle channel page giving 404 (instead of killing the process) (#22).

## [3.0.1] 2024-12-31

### Fixes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bbyen",
"version": "3.0.1",
"version": "3.0.2",
"description": "Bring Back YouTube Email Notifications!",
"main": "src/index.js",
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions src/google/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,12 @@ const genAuthToken = async (oauth2Client: OAuth2Client) => {
try {
logger.info('Creating tokens from code')
const { tokens } = await oauth2Client.getToken(code)
res.end('Authorization successful. You may now close this tab.')
res.writeHead(200)
.end('Authorization successful. You may now close this tab.')
resolve(tokens)
} catch (err) {
console.error(err)
res.end(`Authorization failed. ${err}`)
res.writeHead(500)
res.writeHead(500).end(`Authorization failed. ${err}`)
reject(err)
}
server.close()
Expand Down
14 changes: 8 additions & 6 deletions src/videos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ const getChannelsVideos = async ({
auth,
sendVideoEmail,
db,
}: IGetChannelsVideos): boolean => {
const { channelId, channelTitle, channelThumbnail } = channel
}: IGetChannelsVideos): Promise<boolean> => {
const { channelId, channelThumbnail } = channel

const videosSent = new Set((await db.all(SQL`
SELECT videoId FROM videos WHERE channelId=${channelId};
`)).map(v => v.videoId))

const feed = await parser.parseURL([
'https://www.youtube.com/feeds/videos.xml',
'?channel_id=', channelId,
].join(''))
const url = `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`
const feed = await parser.parseURL(url)
.catch((err) => {
logger.warn(`Error parsing videos from '${url}': ${err.message}`)
return { items: [] }
})

for (let { videoId } of feed.items) {
try {
Expand Down

0 comments on commit 18e1460

Please sign in to comment.