Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle channel page giving 404 #25

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading