Updated compiler to use new Assets file

Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-04-16 17:39:47 +02:00
parent 39a69d5d56
commit 8d19e46c2c
3 changed files with 8 additions and 11 deletions

2
db

@ -1 +1 @@
Subproject commit b826798c3b8acda84be12604a1c11fef7abdf67c
Subproject commit d62dab4a1d375009345b650518b253d153ceb72e

View File

@ -15,8 +15,9 @@ const VERSION = 'v2'
const paths = (await fs.readdir('./endpoints')).filter((f) => f.endsWith('.ts'))
console.log('Prefetching pictures')
await fetchRemoteFile(`https://assets.tcgdex.net/data-${lang}.json`)
await fetchRemoteFile(`https://assets.tcgdex.net/datas.json`)
console.log('Let\'s GO !')
for (const file of paths) {
const path = `./endpoints/${file}`
console.log(file, 'Running Init')

View File

@ -4,11 +4,9 @@ import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
import translate, { translateType } from './translationUtil'
interface ObjectList<T = any> {
[key: string]: T
}
type ObjectList<T = any> = Partial<Record<string, T>>
type RemoteData = ObjectList<ObjectList<ObjectList<boolean>>>
type RemoteData = ObjectList<ObjectList<ObjectList<ObjectList<string>>>>
export async function cardToCardSimple(id: string, card: Card, lang: SupportedLanguages): Promise<CardResume> {
const cardName = card.name[lang]
@ -26,8 +24,9 @@ export async function cardToCardSimple(id: string, card: Card, lang: SupportedLa
export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {
try {
const file = await fetchRemoteFile(`https://assets.tcgdex.net/data-${lang}.json`)
if (file[card.set.serie.id][card.set.id][cardId]) {
const file = await fetchRemoteFile(`https://assets.tcgdex.net/datas.json`)
const fileExists = !!file[lang]?.[card.set.serie.code]?.[card.set.code]?.[card.localId]
if (fileExists) {
return `https://assets.tcgdex.net/${lang}/${card.set.serie.id}/${card.set.id}/${cardId}`
}
} catch {
@ -43,9 +42,6 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
throw new Error(`Card (${localId}) dont exist in (${lang})`)
}
return {
id: `${card.set.id}-${localId}`,
localId: localId,