2023-03-24 07:41:33 -04:00
|
|
|
import { Router } from 'express'
|
|
|
|
import { TwitchAPI } from '../util/scraping/extractor/index'
|
|
|
|
|
|
|
|
const profileRouter = Router()
|
|
|
|
const twitch = new TwitchAPI()
|
|
|
|
|
|
|
|
profileRouter.get('/users/:username', async (req, res, next) => {
|
|
|
|
const username = req.params.username
|
|
|
|
|
|
|
|
let streamerData = await twitch.getStreamerInfo(username)
|
|
|
|
.catch(next)
|
|
|
|
|
|
|
|
if (streamerData)
|
|
|
|
res.send(streamerData)
|
|
|
|
})
|
|
|
|
|
|
|
|
profileRouter.get('/discover', async (req, res, next) => {
|
2023-03-29 10:03:16 -04:00
|
|
|
let cursor = req.query.cursor
|
|
|
|
let discoveryData;
|
|
|
|
if (cursor) {
|
|
|
|
cursor = cursor.toString()
|
|
|
|
discoveryData = await twitch.getDirectory(15, cursor)
|
|
|
|
} else {
|
|
|
|
discoveryData = await twitch.getDirectory(15)
|
|
|
|
}
|
|
|
|
|
2023-03-24 07:41:33 -04:00
|
|
|
res.send(discoveryData)
|
|
|
|
})
|
|
|
|
|
|
|
|
profileRouter.get('/discover/:game', async (req, res, next) => {
|
|
|
|
let discoveryData = await twitch.getDirectoryGame(req.params.game, 50)
|
2023-03-31 07:56:38 -04:00
|
|
|
.catch(next)
|
|
|
|
|
|
|
|
if(discoveryData)
|
|
|
|
res.send(discoveryData)
|
|
|
|
})
|
|
|
|
|
|
|
|
profileRouter.get('/badges', async (req, res, next) => {
|
|
|
|
let badges = await twitch.getTwitchBadges()
|
|
|
|
.catch(next)
|
|
|
|
|
|
|
|
if(req.query.streamerName) {
|
|
|
|
let broadcastBadges = await twitch.getStreamerBadges(req.query.streamerName.toString())
|
|
|
|
.catch(next)
|
|
|
|
if(broadcastBadges && badges)
|
|
|
|
badges = [...badges, ...broadcastBadges]
|
|
|
|
}
|
|
|
|
|
|
|
|
if(badges)
|
|
|
|
res.send(badges)
|
2023-03-24 07:41:33 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
export default profileRouter
|