Skip to content

Commit

Permalink
redirect to stream image on screenshot if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed May 18, 2024
1 parent 8bc54b9 commit f02ac85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 11 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,17 @@ mongoose.connect(config.database).then(() => {
app.use('/images', express.static('images'));

app.get('/i/:id', (req, res) => {
// TwitchService.getChannel().then(async (channel) => {
// if (channel && channel.streamId) {
// const screenshots = await ScreenshotService.getScreenshots(channel.streamId)
// const image = screenshots.find((s) => s.name === req.params.id)
// if (image) {
// res.redirect(__dirname + `/stream/#lg=1&slide=${req.params.id}`);
// }
// }
// });
TwitchService.getChannel().then(async (channel) => {
if (channel && channel.streamId) {
const screenshots = await ScreenshotService.getScreenshots(channel.streamId)
if (screenshots.length > 0) {
const image = screenshots.find((s) => s.name === req.params.id)
if (image) {
res.redirect(__dirname + `/stream/#lg=1&slide=${req.params.id}`);
}
}
}
});
res.sendFile(__dirname + `/public/images/${req.params.id}.jpg`)
});

Expand Down
2 changes: 1 addition & 1 deletion services/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function getScreenshots(streamId) {
if (streamId) {
return await dbManager.getScreenshots(streamId)
} else {
return null
return []
}

}
Expand Down

0 comments on commit f02ac85

Please sign in to comment.