mirror of
https://github.com/tcgdex/compiler.git
synced 2025-07-03 04:09:19 +00:00
Updated illustrators
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
22
endpoints/illustrators/index.ts
Normal file
22
endpoints/illustrators/index.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { fetchIllustrators, illustratorToIllustratorSimple } from "../illustratorUtil"
|
||||
import { IllustratorsList } from "../../sdk/dist/types/interfaces/Illustrator"
|
||||
import { getBaseFolder } from "../util"
|
||||
import { promises as fs} from "fs"
|
||||
|
||||
const lang = process.env.CARDLANG || "en"
|
||||
const endpoint = getBaseFolder(lang, "illustrators")
|
||||
|
||||
const btsp = async () => {
|
||||
|
||||
const db = await fetchIllustrators()
|
||||
|
||||
const res: IllustratorsList = {
|
||||
count: db.length,
|
||||
list: db.map((ill, index) => illustratorToIllustratorSimple(ill, index))
|
||||
}
|
||||
|
||||
await fs.mkdir(endpoint, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/index.json`, JSON.stringify(res))
|
||||
}
|
||||
|
||||
btsp()
|
49
endpoints/illustrators/item.ts
Normal file
49
endpoints/illustrators/item.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { fetchIllustrators } from "../illustratorUtil"
|
||||
import { IllustratorSingle } from "../../sdk/dist/types/interfaces/Illustrator"
|
||||
import { getBaseFolder, getAllCards } from "../util"
|
||||
import { promises as fs} from "fs"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
import { isCardAvailable, cardToCardSimple } from "../cardUtil"
|
||||
import { Langs } from "../../db/interfaces/LangList"
|
||||
|
||||
const lang = process.env.CARDLANG as Langs || "en"
|
||||
const endpoint = getBaseFolder(lang, "illustrators")
|
||||
|
||||
interface t {
|
||||
[key: string]: Array<Card>
|
||||
}
|
||||
|
||||
const btsp = async () => {
|
||||
|
||||
const db = await fetchIllustrators()
|
||||
const cards = getAllCards()
|
||||
|
||||
const tmp: t = {}
|
||||
|
||||
|
||||
for (const i of cards) {
|
||||
const card: Card = require(`../../db/cards/${i}`).default
|
||||
|
||||
if (!isCardAvailable(card, lang) || !card.illustrator) continue
|
||||
|
||||
if (!(card.illustrator in tmp)) tmp[card.illustrator] = []
|
||||
tmp[card.illustrator].push(card)
|
||||
}
|
||||
|
||||
for (const illustrator in tmp) {
|
||||
if (tmp.hasOwnProperty(illustrator)) {
|
||||
const list = tmp[illustrator];
|
||||
|
||||
const toSave: IllustratorSingle = {
|
||||
id: db.indexOf(illustrator),
|
||||
name: illustrator,
|
||||
cards: list.map(el => cardToCardSimple(el, lang))
|
||||
}
|
||||
|
||||
await fs.mkdir(`${endpoint}/${toSave.id}`, {recursive: true})
|
||||
await fs.writeFile(`${endpoint}/${toSave.id}/index.json`, JSON.stringify(toSave))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
btsp()
|
31
endpoints/illustrators/updateDB.ts
Normal file
31
endpoints/illustrators/updateDB.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { getAllCards2 } from "../util"
|
||||
import Card from "../../db/interfaces/Card"
|
||||
|
||||
import { promises as fs} from "fs"
|
||||
import { illustratorsFile, fetchIllustrators } from "../illustratorUtil"
|
||||
|
||||
const dbFile = illustratorsFile
|
||||
|
||||
const btsp = async () => {
|
||||
const db = await fetchIllustrators()
|
||||
|
||||
|
||||
const list = getAllCards2()
|
||||
for (let i of list) {
|
||||
i = i.replace("./", "../../")
|
||||
const card: Card = require(i).default
|
||||
|
||||
if (!card.illustrator) continue
|
||||
console.log(i)
|
||||
|
||||
const illustrator = card.illustrator
|
||||
|
||||
if (!db.includes(illustrator)) {
|
||||
db.push(illustrator)
|
||||
}
|
||||
}
|
||||
|
||||
await fs.writeFile(dbFile, JSON.stringify(db))
|
||||
}
|
||||
|
||||
btsp()
|
Reference in New Issue
Block a user