0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2024-12-22 13:13:00 -05:00

Add cursor to category game

This commit is contained in:
dragongoose 2023-04-11 14:28:39 -04:00
parent fb1113c0cd
commit cb1fa72077
No known key found for this signature in database
GPG key ID: 50DB99B921579009
2 changed files with 15 additions and 5 deletions

View file

@ -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({

View file

@ -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)}`,