mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2025-01-03 03:10:05 -05:00
Add more types to extractor
This commit is contained in:
parent
3cf1536236
commit
65a6c62b38
4 changed files with 45 additions and 6 deletions
11
types/scraping/Category.ts
Normal file
11
types/scraping/Category.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export type Tag = string
|
||||
|
||||
export interface Category {
|
||||
name: string
|
||||
displayName: string
|
||||
viewers: number
|
||||
tags: Tag[]
|
||||
createdAt: Date
|
||||
cursor: string
|
||||
image: string
|
||||
}
|
25
types/scraping/CategoryData.ts
Normal file
25
types/scraping/CategoryData.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { Tag } from "./Category"
|
||||
import { StreamData } from "./Streamer"
|
||||
|
||||
export interface CategoryMinifiedStream {
|
||||
title: string
|
||||
viewers: number
|
||||
preview: string
|
||||
tags: Tag[]
|
||||
cursor: string
|
||||
streamer: {
|
||||
name: string
|
||||
pfp: string
|
||||
colorHex: string
|
||||
}
|
||||
}
|
||||
|
||||
export interface CategoryData {
|
||||
name: string
|
||||
cover: string
|
||||
description: string
|
||||
viewers: number
|
||||
followers: number
|
||||
tags: Tag[]
|
||||
streams: CategoryMinifiedStream[]
|
||||
}
|
|
@ -11,6 +11,7 @@ export interface StreamData {
|
|||
startedAt: number
|
||||
viewers: number
|
||||
preview: string
|
||||
cursor?: string
|
||||
}
|
||||
|
||||
export interface StreamerData {
|
||||
|
@ -21,7 +22,7 @@ export interface StreamerData {
|
|||
about: string
|
||||
socials?: Social[]
|
||||
pfp: string
|
||||
stream: StreamData | null
|
||||
stream?: StreamData | null
|
||||
isPartner: boolean
|
||||
colorHex: string
|
||||
id: number
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { LooseObject } from "../../../types/looseTypes"
|
||||
import { StreamerData, StreamData, Social, Badge } from "../../../types/scraping/Streamer"
|
||||
import { Category, Tag } from "../../../types/scraping/Category"
|
||||
import { CategoryData, CategoryMinifiedStream } from "../../../types/scraping/CategoryData"
|
||||
|
||||
const base64 = (data: String) => {
|
||||
return Buffer.from(data).toString('base64url')
|
||||
|
@ -302,10 +304,10 @@ export class TwitchAPI {
|
|||
})
|
||||
const data = await res.json()
|
||||
const categories = data[0].data.directoriesWithTags.edges
|
||||
let formattedCategories = []
|
||||
let formattedCategories: Category[] = []
|
||||
|
||||
for (let category of categories) {
|
||||
let tags = []
|
||||
let tags: Tag[] = []
|
||||
for (let tag of category.node.tags) {
|
||||
tags.push(tag.tagName)
|
||||
}
|
||||
|
@ -380,7 +382,7 @@ export class TwitchAPI {
|
|||
let streams = []
|
||||
if(data[0].data.game.streams)
|
||||
streams = data[0].data.game.streams.edges
|
||||
let formatedStreams = []
|
||||
let formatedStreams: CategoryMinifiedStream[] = []
|
||||
|
||||
for(let stream of streams) {
|
||||
let tags = []
|
||||
|
@ -403,12 +405,12 @@ export class TwitchAPI {
|
|||
}
|
||||
|
||||
const rawGameData = data[1].data.game;
|
||||
let tags = []
|
||||
let tags: Tag[] = []
|
||||
for(let tag of rawGameData.tags) {
|
||||
tags.push(tag.tagName)
|
||||
}
|
||||
|
||||
const formatedGameData = {
|
||||
const formatedGameData: CategoryData = {
|
||||
name: rawGameData.name,
|
||||
cover: `${process.env.URL}/proxy/img/${base64(rawGameData.avatarURL)}`,
|
||||
description: rawGameData.description,
|
||||
|
|
Loading…
Reference in a new issue