Skip to content

Commit

Permalink
return stream photo
Browse files Browse the repository at this point in the history
  • Loading branch information
lluisd committed May 18, 2024
1 parent 98cbc6f commit bf69fb1
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,26 @@ mongoose.connect(config.database).then(() => {

app.use('/images', express.static('images'));

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

app.get('/img/:id', (req, res) => {
Expand All @@ -116,3 +123,4 @@ mongoose.connect(config.database).then(() => {




0 comments on commit bf69fb1

Please sign in to comment.