Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
Update index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
0Supa committed Jul 26, 2021
1 parent c36004d commit ad3efda
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,30 @@ app.get('/rcp/:channel', async (req, res) => {
if (cacheData) {
clips = JSON.parse(cacheData)
} else {
const data = (await utils.helix(`clips?broadcaster_id=${user[0].id}&first=100`)).body.data
if (data.length < 5) return res.status(404).send('The channel needs to have at least 5 clips')
clips = await getClips(user[0].id, 3)
if (clips.length < 5) return res.status(404).send('The channel needs to have at least 5 clips')

clips = data.map(clip => clip.thumbnail_url.replace(/-preview.*/, '.mp4'))
await utils.redis.set(`rc:clips:${user[0].id}`, JSON.stringify(clips), "EX", 86400)
}

res.render('index', { clips })
})

async function getClips(channelID, reqs) {
let i = 0
let clips = []
let cursor

while (i < reqs) {
const { data, pagination } = (await utils.helix(`clips?broadcaster_id=${channelID}&first=100${cursor ? `&after=${cursor}` : ''}`)).body
clips = clips.concat(data.map(clip => clip.thumbnail_url.replace(/-preview.*/, '.mp4')))
cursor = pagination.cursor
if (!cursor) { break; }
i++
}
return clips;
}

app.listen(3840, (err) => {
if (err) throw err
console.log(`listening on 3840`)
Expand Down

0 comments on commit ad3efda

Please sign in to comment.