0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-08 13:50:05 -05:00

Add search endpoint

This commit is contained in:
dragongoose 2023-04-16 12:38:34 -04:00
parent 65a6c62b38
commit 7bf75fa99e
No known key found for this signature in database
GPG key ID: 50DB99B921579009
5 changed files with 559 additions and 467 deletions

View file

@ -23,8 +23,10 @@ profileRouter.get('/discover', async (req, res, next) => {
let discoveryData; let discoveryData;
if (cursor) { if (cursor) {
discoveryData = await twitch.getDirectory(15, cursor) discoveryData = await twitch.getDirectory(15, cursor)
.catch(next)
} else { } else {
discoveryData = await twitch.getDirectory(15) discoveryData = await twitch.getDirectory(15)
.catch(next)
} }
res.send({ res.send({
@ -69,4 +71,20 @@ profileRouter.get('/badges', async (req, res, next) => {
}) })
}) })
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 export default profileRouter

View file

@ -5,7 +5,7 @@ export interface Category {
displayName: string displayName: string
viewers: number viewers: number
tags: Tag[] tags: Tag[]
createdAt: Date createdAt?: Date
cursor: string cursor?: string
image: string image: string
} }

View file

@ -17,13 +17,12 @@ export interface StreamData {
export interface StreamerData { export interface StreamerData {
username: string username: string
followers: number followers: number
followersAbbv: string
isLive: boolean isLive: boolean
about: string about: string
socials?: Social[] socials?: Social[]
pfp: string pfp: string
stream?: StreamData | null stream?: StreamData | null
isPartner: boolean isPartner: boolean | null
colorHex: string colorHex: string
id: number id: number
} }

View file

@ -5,5 +5,5 @@ export const errorHandler = (err: Error, req: Request, res: Response, next: Next
return next(err) return next(err)
} }
res.status(500).send({ status: 'error', message: err.message}) res.status(500).send({ status: 'error', message: err})
} }

File diff suppressed because it is too large Load diff