mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-25 21:58:48 -05:00
Add badges typse
This commit is contained in:
parent
685645ddac
commit
79301bdf37
2 changed files with 95 additions and 1 deletions
|
@ -25,4 +25,12 @@ export interface StreamerData {
|
||||||
isPartner: boolean
|
isPartner: boolean
|
||||||
colorHex: string
|
colorHex: string
|
||||||
id: number
|
id: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Badge {
|
||||||
|
id: string,
|
||||||
|
title: string,
|
||||||
|
setId: string,
|
||||||
|
version: string,
|
||||||
|
images: { [k:string]: string }
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import { LooseObject } from "../../../types/looseTypes"
|
import { LooseObject } from "../../../types/looseTypes"
|
||||||
import { StreamerData, StreamData, Social } from "../../../types/scraping/Streamer"
|
import { StreamerData, StreamData, Social, Badge } from "../../../types/scraping/Streamer"
|
||||||
|
|
||||||
const base64 = (data: String) => {
|
const base64 = (data: String) => {
|
||||||
return Buffer.from(data).toString('base64url')
|
return Buffer.from(data).toString('base64url')
|
||||||
|
@ -417,4 +417,90 @@ export class TwitchAPI {
|
||||||
|
|
||||||
return formatedGameData
|
return formatedGameData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getTwitchBadges = async () => {
|
||||||
|
const payload = [
|
||||||
|
{
|
||||||
|
"operationName": "ChannelPointsPredictionBadges",
|
||||||
|
"variables": {},
|
||||||
|
"extensions": {
|
||||||
|
"persistedQuery": {
|
||||||
|
"sha256Hash": "36995b30b22c31d1cd0aa329987ac9b5368bb7e6e1ab1df42808bdaa80a6dbf9",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const res = await fetch(this.twitchUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers: this.headers
|
||||||
|
})
|
||||||
|
const data = await res.json()
|
||||||
|
|
||||||
|
if(!data[0].data.badges) return null;
|
||||||
|
let formatedBadges: Badge[] = []
|
||||||
|
|
||||||
|
for (let badge of data[0].data.badges) {
|
||||||
|
let formatedBadge: Badge = {
|
||||||
|
id: Buffer.from(badge.id, 'base64').toString(),
|
||||||
|
setId: badge.setID,
|
||||||
|
title: badge.title,
|
||||||
|
version: badge.version,
|
||||||
|
images: {
|
||||||
|
image1x: badge.image1x,
|
||||||
|
image2x: badge.image2x,
|
||||||
|
image4x: badge.image4x,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formatedBadges.push(formatedBadge)
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatedBadges
|
||||||
|
}
|
||||||
|
|
||||||
|
public getStreamerBadges = async (streamerName: string) => {
|
||||||
|
const payload = {
|
||||||
|
"extensions": {
|
||||||
|
"persistedQuery": {
|
||||||
|
"sha256Hash": "86f43113c04606e6476e39dcd432dee47c994d77a83e54b732e11d4935f0cd08",
|
||||||
|
"version": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"operationName": "ChatList_Badges",
|
||||||
|
"variables": {
|
||||||
|
"channelLogin": streamerName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetch(this.twitchUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
headers: this.headers
|
||||||
|
})
|
||||||
|
const data = await res.json()
|
||||||
|
|
||||||
|
if(!data.data.user.broadcastBadges) return null;
|
||||||
|
let formatedBadges: Badge[] = []
|
||||||
|
|
||||||
|
for (let badge of data.data.user.broadcastBadges) {
|
||||||
|
let formatedBadge: Badge = {
|
||||||
|
id: Buffer.from(badge.id, 'base64').toString(),
|
||||||
|
setId: badge.setID,
|
||||||
|
title: badge.title,
|
||||||
|
version: badge.version,
|
||||||
|
images: {
|
||||||
|
image1x: badge.image1x,
|
||||||
|
image2x: badge.image2x,
|
||||||
|
image4x: badge.image4x,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
formatedBadges.push(formatedBadge)
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatedBadges
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue