mirror of
https://github.com/tcgdex/compiler.git
synced 2025-04-22 10:42:09 +00:00
Updated compiler to use new Assets file
Signed-off-by: Florian BOUILLON <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
39a69d5d56
commit
8d19e46c2c
2
db
2
db
@ -1 +1 @@
|
|||||||
Subproject commit b826798c3b8acda84be12604a1c11fef7abdf67c
|
Subproject commit d62dab4a1d375009345b650518b253d153ceb72e
|
3
main.ts
3
main.ts
@ -15,8 +15,9 @@ const VERSION = 'v2'
|
|||||||
const paths = (await fs.readdir('./endpoints')).filter((f) => f.endsWith('.ts'))
|
const paths = (await fs.readdir('./endpoints')).filter((f) => f.endsWith('.ts'))
|
||||||
|
|
||||||
console.log('Prefetching pictures')
|
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) {
|
for (const file of paths) {
|
||||||
const path = `./endpoints/${file}`
|
const path = `./endpoints/${file}`
|
||||||
console.log(file, 'Running Init')
|
console.log(file, 'Running Init')
|
||||||
|
@ -4,11 +4,9 @@ import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
|
|||||||
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
|
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
|
||||||
import translate, { translateType } from './translationUtil'
|
import translate, { translateType } from './translationUtil'
|
||||||
|
|
||||||
interface ObjectList<T = any> {
|
type ObjectList<T = any> = Partial<Record<string, T>>
|
||||||
[key: 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> {
|
export async function cardToCardSimple(id: string, card: Card, lang: SupportedLanguages): Promise<CardResume> {
|
||||||
const cardName = card.name[lang]
|
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> {
|
export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
const file = await fetchRemoteFile(`https://assets.tcgdex.net/data-${lang}.json`)
|
const file = await fetchRemoteFile(`https://assets.tcgdex.net/datas.json`)
|
||||||
if (file[card.set.serie.id][card.set.id][cardId]) {
|
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}`
|
return `https://assets.tcgdex.net/${lang}/${card.set.serie.id}/${card.set.id}/${cardId}`
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@ -43,9 +42,6 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
|
|||||||
throw new Error(`Card (${localId}) dont exist in (${lang})`)
|
throw new Error(`Card (${localId}) dont exist in (${lang})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: `${card.set.id}-${localId}`,
|
id: `${card.set.id}-${localId}`,
|
||||||
localId: localId,
|
localId: localId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user