mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-03 20:29:19 +00:00
34
endpoints/hp/index.ts
Normal file
34
endpoints/hp/index.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { getAllCards, getBaseFolder } from "../util"
|
||||
import { fetchCard, isCardAvailable } from "../cardUtil"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
import { HpList } from "../../sdk/dist/types/interfaces/Hp"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "hp")
|
||||
|
||||
|
||||
const btsp = async () => {
|
||||
const cards = getAllCards()
|
||||
|
||||
const hps: Array<number> = []
|
||||
|
||||
for (const i of cards) {
|
||||
const card = fetchCard(i)
|
||||
if (!isCardAvailable(card, lang) || !card.hp) continue
|
||||
|
||||
if (hps.includes(card.hp)) continue
|
||||
hps.push(card.hp)
|
||||
}
|
||||
|
||||
const hpList: HpList = {
|
||||
count: hps.length,
|
||||
list: hps.sort((a, b) => a > b ? 1 : -1)
|
||||
}
|
||||
|
||||
await fs.mkdir(endpoint, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(hpList))
|
||||
|
||||
}
|
||||
|
||||
btsp()
|
Reference in New Issue
Block a user