mirror of
https://github.com/tcgdex/compiler.git
synced 2025-08-04 18:01:59 +00:00
Added Categories endpoint
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
30
endpoints/categories/index.ts
Normal file
30
endpoints/categories/index.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { getBaseFolder } from "../util"
|
||||
import Category from '@tcgdex/sdk/interfaces/Category'
|
||||
import { categorySimple, categoryList } from "./category"
|
||||
import TranslationUtil from "@tcgdex/sdk/TranslationUtil"
|
||||
import { Langs } from "@tcgdex/sdk/interfaces/LangList"
|
||||
import { promises as fs } from 'fs'
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "categories")
|
||||
|
||||
const btsp = async () => {
|
||||
|
||||
const list: Array<categorySimple> = []
|
||||
for (const cat of Object.values(Category)) {
|
||||
if (typeof cat !== "number") continue
|
||||
list.push({
|
||||
id: cat,
|
||||
name: TranslationUtil.translate("category", cat, lang)
|
||||
})
|
||||
}
|
||||
|
||||
const res: categoryList = {
|
||||
count: list.length,
|
||||
list: list
|
||||
}
|
||||
|
||||
await fs.mkdir(endpoint, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
|
||||
}
|
||||
btsp()
|
Reference in New Issue
Block a user