diff --git a/routes/profileRoute.ts b/routes/profileRoute.ts index d42904c..22e3b11 100644 --- a/routes/profileRoute.ts +++ b/routes/profileRoute.ts @@ -19,10 +19,9 @@ profileRouter.get('/users/:username', async (req, res, next) => { }) profileRouter.get('/discover', async (req, res, next) => { - let cursor = req.query.cursor + let cursor = req.query.cursor?.toString() let discoveryData; if (cursor) { - cursor = cursor.toString() discoveryData = await twitch.getDirectory(15, cursor) } else { discoveryData = await twitch.getDirectory(15) @@ -35,8 +34,15 @@ profileRouter.get('/discover', async (req, res, next) => { }) profileRouter.get('/discover/:game', async (req, res, next) => { - let discoveryData = await twitch.getDirectoryGame(req.params.game, 50) - .catch(next) + let discoveryData; + let cursor = req.query.cursor?.toString() + if(cursor) { + discoveryData = await twitch.getDirectoryGame(req.params.game, 50, cursor) + .catch(next) + } else { + discoveryData = await twitch.getDirectoryGame(req.params.game, 50) + .catch(next) + } if(discoveryData) res.send({ diff --git a/util/scraping/extractor/index.ts b/util/scraping/extractor/index.ts index ccf6aa2..3b397df 100644 --- a/util/scraping/extractor/index.ts +++ b/util/scraping/extractor/index.ts @@ -324,7 +324,7 @@ export class TwitchAPI { return formattedCategories } - public getDirectoryGame = async (name: string, streamLimit: number) => { + public getDirectoryGame = async (name: string, streamLimit: number, cursor?: string) => { const payload: any[] = [ { "operationName": "DirectoryPage_Game", @@ -364,6 +364,9 @@ export class TwitchAPI { }, ] + if(cursor) + payload[0].variables.cursor = cursor + const res = await fetch(this.twitchUrl, { method: 'POST', body: JSON.stringify(payload), @@ -390,6 +393,7 @@ export class TwitchAPI { viewers: stream.node.viewersCount, preview: `${process.env.URL}/proxy/img/${base64(stream.node.previewImageURL)}`, tags, + cursor: stream.cursor, streamer: { name: stream.node.broadcaster.displayName, pfp: `${process.env.URL}/proxy/img/${base64(stream.node.broadcaster.profileImageURL)}`,