refactor(utils): clean up fetchGameData
This commit is contained in:
parent
9a1feb829c
commit
36ea248c9f
@ -3,7 +3,7 @@ import { XMLParser } from 'fast-xml-parser'
|
|||||||
|
|
||||||
import { GAME_ENDPOINTS, client } from '../config/ENDPOINTS'
|
import { GAME_ENDPOINTS, client } from '../config/ENDPOINTS'
|
||||||
import type { DomainTypes } from '../types/Domain'
|
import type { DomainTypes } from '../types/Domain'
|
||||||
import { convertXML } from '../mapping'
|
import { convertTXT, convertXML } from '../mapping'
|
||||||
import { parseData } from './parseData'
|
import { parseData } from './parseData'
|
||||||
|
|
||||||
export const fetchGameData = async (
|
export const fetchGameData = async (
|
||||||
@ -17,18 +17,23 @@ export const fetchGameData = async (
|
|||||||
await client
|
await client
|
||||||
.get(endpoint.src, { responseType: ResponseType.Text })
|
.get(endpoint.src, { responseType: ResponseType.Text })
|
||||||
.then(async ({ data }) => {
|
.then(async ({ data }) => {
|
||||||
|
const currentData = data as string
|
||||||
|
|
||||||
switch (endpoint.convert) {
|
switch (endpoint.convert) {
|
||||||
case 'XML':
|
case 'XML':
|
||||||
const convertedData = new XMLParser({
|
const convertedData = new XMLParser({
|
||||||
ignoreAttributes: false,
|
ignoreAttributes: false,
|
||||||
attributeNamePrefix: ''
|
attributeNamePrefix: ''
|
||||||
}).parse(data as string)
|
}).parse(currentData)
|
||||||
|
|
||||||
const XML2JSON = convertXML(convertedData, endpoint.src)
|
const XML2JSON = convertXML(convertedData, endpoint.src)
|
||||||
|
|
||||||
console.log(XML2JSON)
|
|
||||||
|
|
||||||
return await parseData(endpoint.fileName, XML2JSON)
|
return await parseData(endpoint.fileName, XML2JSON)
|
||||||
|
case 'TXT':
|
||||||
|
return await convertTXT(currentData)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return await parseData(endpoint.fileName, currentData)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user