Skip to content

Commit

Permalink
fix: the set name and card id being the same
Browse files Browse the repository at this point in the history
Signed-off-by: Avior <[email protected]>
  • Loading branch information
Aviortheking committed Nov 12, 2023
1 parent 36b17db commit e64b876
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions server/compiler/utils/cardUtil.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable sort-keys */
import { Card, Set, SupportedLanguages, Types } from '../../../interfaces'
import { CardResume, Card as CardSingle } from '../../../meta/definitions/api'
import { setToSetSimple } from './setUtil'
import { cardIsLegal, DB_PATH, fetchRemoteFile, smartGlob } from './util'
import { Set, SupportedLanguages, Card, Types } from '../../../interfaces'
import { Card as CardSingle, CardResume } from '../../../meta/definitions/api'
import translate from './translationUtil'
import { DB_PATH, cardIsLegal, fetchRemoteFile, smartGlob } from './util'

export async function getCardPictures(cardId: string, card: Card, lang: SupportedLanguages): Promise<string | undefined> {
try {
Expand Down Expand Up @@ -131,15 +131,18 @@ export async function getCards(lang: SupportedLanguages, set?: Set): Promise<Arr
const cards = await smartGlob(`${DB_PATH}/data/${(set && set.serie.name.en) ?? '*'}/${(set && set.name.en) ?? '*'}/*.js`)
const list: Array<[string, Card]> = []
for (const path of cards) {
const id = path.substring(path.lastIndexOf('/') + 1, path.lastIndexOf('.'))
const setName = (set && set.name.en) ?? (() => {
const part1 = path.substr(0, path.lastIndexOf(id) - 1)
return part1.substr(part1.lastIndexOf('/') + 1)
})()
const serieName = (set && set.serie.name.en) ?? (() => {
const part1 = path.substr(0, path.lastIndexOf(setName) - 1)
return part1.substr(part1.lastIndexOf('/') + 1)
})()
let items = path.split('/')
items = items.slice(items.length - 3)

// get the card id
let id = items[2]
id = id.substring(0, id.lastIndexOf('.'))

// get it's set name
const setName = (set && set.name.en) ?? items[1]

// get it's serie name
const serieName = (set && set.serie.name.en) ?? items[0]
// console.log(path, id, setName)
const c = await getCard(serieName, setName, id)
if (!c.name[lang]) {
Expand Down

0 comments on commit e64b876

Please sign in to comment.