Added Support for legal file (#13)

* Added Support for legal file

Signed-off-by: Avior <florian.bouillon@delta-wings.net>

* Fixed bug

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-06-18 23:35:14 +02:00 committed by GitHub
parent c3723463e9
commit ddc8916d08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 15 deletions

View File

@ -17,7 +17,7 @@ export default class implements Endpoint<SerieList, SerieSingle, {}, Array<Serie
for (let key = 0; key < common.length; key++) {
const val = common[key];
const gen = await serieToSerieSingle(val, this.lang)
const name = val.name[this.lang]
const name = val.name[this.lang] as string
items[name] = gen
items[val.id] = gen
}

View File

@ -15,7 +15,7 @@
"@dzeio/logger": "^2.0.0-alpha.0",
"@dzeio/object-util": "^1.0.4",
"@dzeio/queue": "^1.2.0",
"@tcgdex/sdk": "^2.0.0-beta.4",
"@tcgdex/sdk": "^2.2.0-beta",
"@types/glob": "^7.1.1",
"@types/node": "^15.0.1",
"@types/node-fetch": "^2.5.7",

View File

@ -1,5 +1,5 @@
import { setToSetSimple } from "./setUtil"
import { fetchRemoteFile, smartGlob } from "./util"
import { cardIsLegal, fetchRemoteFile, smartGlob } from "./util"
import { Set, SupportedLanguages, Card, Types } from 'db/interfaces'
import { Card as CardSingle, CardResume } from '@tcgdex/sdk/interfaces'
import translate from './translationUtil'
@ -81,7 +81,7 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
})),
attacks: card.attacks?.map((el) => ({
cost: el.cost?.map((t) => translate('types', t, lang)),
cost: el.cost?.map((t) => translate('types', t, lang)) as Array<Types>,
name: el.name[lang] as string,
effect: el.effect ? el.effect[lang] : undefined,
damage: el.damage
@ -105,6 +105,11 @@ export async function cardToCardSingle(localId: string, card: Card, lang: Suppor
energyType: translate('energyType', card.energyType, lang) as any,
regulationMark: card.regulationMark,
legal: {
standard: cardIsLegal('standard', card, localId),
expanded: cardIsLegal('expanded', card, localId)
}
}
}

View File

@ -1,5 +1,5 @@
import { Set, SupportedLanguages } from "db/interfaces"
import { fetchRemoteFile, smartGlob } from "./util"
import { fetchRemoteFile, setIsLegal, smartGlob } from "./util"
import { cardToCardSimple, getCards } from './cardUtil'
import { SetResume, Set as SetSingle } from '@tcgdex/sdk/interfaces'
@ -99,9 +99,9 @@ export async function setToSetSingle(set: Set, lang: SupportedLanguages): Promis
firstEd: cards.reduce((count, card) => count + (card[1].variants?.firstEdition ?? set.variants?.firstEdition ? 1 : 0), 0),
},
releaseDate: set.releaseDate,
legal: set.legal && {
standard: set.legal.standard,
expanded: set.legal.expanded
legal: {
standard: setIsLegal('standard', set),
expanded: setIsLegal('expanded', set)
},
logo: pics[0],
symbol: pics[1],

View File

@ -73,10 +73,9 @@ const translations: Record<string, Record<translatable, Record<string, string>>>
}
}
export default function translate(item: translatable, key: string | undefined, lang: SupportedLanguages): string {
export default function translate(item: translatable, key: string | undefined, lang: SupportedLanguages): string | undefined {
if (!key) {
throw new Error(`No Key ${lang}${item}.${key}`);
return ''
return key
}
if (lang === 'en') {
return key

View File

@ -1,5 +1,7 @@
import { Card, Set } from 'db/interfaces'
import glob from 'glob'
import fetch from 'node-fetch'
import * as legals from '../db/legals'
export function urlize(str: string): string {
return str.replace('?', '%3F').normalize('NFC').replace(/["'\u0300-\u036f]/g, "")
@ -29,3 +31,29 @@ export async function smartGlob(query: string) {
}
return globCache[query]
}
export function cardIsLegal(type: 'standard' | 'expanded', card: Card, localId: string) {
const legal = legals[type]
if (
legal.includes.series.includes(card.set.serie.id) ||
legal.includes.sets.includes(card.set.id) ||
(card.regulationMark && legal.includes.regulationMark.includes(card.regulationMark))
) {
return !(
legal.excludes.sets.includes(card.set.id) ||
legal.excludes.cards.includes(`${card.set.id}-${localId}`)
)
}
return false
}
export function setIsLegal(type: 'standard' | 'expanded', set: Set) {
const legal = legals[type]
if (
legal.includes.series.includes(set.serie.id) ||
legal.includes.sets.includes(set.id)
) {
return !legal.excludes.sets.includes(set.id)
}
return false
}

View File

@ -19,10 +19,10 @@
resolved "https://registry.yarnpkg.com/@dzeio/queue/-/queue-1.2.0.tgz#cc61133f182f4b15267f974c63a7a9e4591365f5"
integrity sha512-YCDgMy41bYH7Rn5nIuH5T3W30Up69LhVqKm5IbK0ybjqyf90Sb9qeRpyqbtG+CV6kQnakhpkcr8ZqtRQWCVtrQ==
"@tcgdex/sdk@^2.0.0-beta.4":
version "2.0.0-beta.4"
resolved "https://registry.yarnpkg.com/@tcgdex/sdk/-/sdk-2.0.0-beta.4.tgz#dc3fdab6a20fcbc314955c9fb04c3d8d5963d78b"
integrity sha512-iTtjf0Xb8Nj8i6NNit3jB/L+jrIZyIqm1C63I0YW+sGWlUdpuq4yDdgyyiscCCP6gRdlh8nsNwN6KkkYGXVDYg==
"@tcgdex/sdk@^2.2.0-beta":
version "2.2.0-beta"
resolved "https://registry.yarnpkg.com/@tcgdex/sdk/-/sdk-2.2.0-beta.tgz#7fd9708ab438d839f31d3ba929da4e8a74376bf7"
integrity sha512-g5hkFmlw8fCfOj3CaZ+6NLgX0ttFbPSqrp2hZpzDYeV4qckBEu+qSDtP+G7LiXYPF+SQGjSKXQulxTNJZOcDLQ==
dependencies:
isomorphic-unfetch "^3.1.0"