mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-18 10:22:28 -05:00
90 lines
No EOL
2.2 KiB
TypeScript
90 lines
No EOL
2.2 KiB
TypeScript
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
|
|
console.log(username)
|
|
|
|
let streamerData = await twitch.getStreamerInfo(username)
|
|
.catch(next)
|
|
|
|
if (streamerData)
|
|
res.send({
|
|
status: 'ok',
|
|
data: streamerData
|
|
})
|
|
})
|
|
|
|
profileRouter.get('/discover', async (req, res, next) => {
|
|
let cursor = req.query.cursor?.toString()
|
|
let discoveryData;
|
|
if (cursor) {
|
|
discoveryData = await twitch.getDirectory(15, cursor)
|
|
.catch(next)
|
|
} else {
|
|
discoveryData = await twitch.getDirectory(15)
|
|
.catch(next)
|
|
}
|
|
|
|
res.send({
|
|
status: 'ok',
|
|
data: discoveryData
|
|
})
|
|
})
|
|
|
|
profileRouter.get('/discover/:game', async (req, res, 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({
|
|
status: 'ok',
|
|
data: 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({
|
|
status: 'ok',
|
|
data: badges
|
|
})
|
|
})
|
|
|
|
profileRouter.get('/search', async (req, res, next) => {
|
|
const query = req.query.query
|
|
if(!query)
|
|
return res.status(400).send({
|
|
status: 'error',
|
|
message: 'No query provided'
|
|
})
|
|
|
|
const result = await twitch.getSearchResult(query.toString())
|
|
.catch(next)
|
|
res.send({
|
|
status: 'ok',
|
|
data: result
|
|
})
|
|
})
|
|
|
|
export default profileRouter |