2023-04-23 20:18:16 +01:00
|
|
|
import { ResponseType } from '@tauri-apps/api/http'
|
|
|
|
|
2023-05-02 15:49:05 +01:00
|
|
|
import { GAMEDATA_ENDPOINTS, client } from '../config/Endpoints'
|
2023-04-28 14:40:45 +01:00
|
|
|
import type { ConvertionHandler } from '../types'
|
2023-05-02 15:49:05 +01:00
|
|
|
import type { DomainTypes } from '../config/Domain'
|
|
|
|
import { parseData } from './parseData'
|
|
|
|
import { Convertion } from '../config/Convertion'
|
|
|
|
import { downloadGamedata } from './rusty'
|
2023-04-23 20:18:16 +01:00
|
|
|
|
|
|
|
export const handleConvertion = async (
|
|
|
|
domain: DomainTypes,
|
2023-04-23 23:28:28 +01:00
|
|
|
callback: ConvertionHandler,
|
2023-04-23 20:18:16 +01:00
|
|
|
assetsOption = false
|
|
|
|
): Promise<void> => {
|
|
|
|
if (!assetsOption) {
|
2023-04-23 23:28:28 +01:00
|
|
|
callback('Initializing Gamedata configuration...', 'loading')
|
2023-04-23 20:18:16 +01:00
|
|
|
|
2023-05-02 15:49:05 +01:00
|
|
|
const gameData = await GAMEDATA_ENDPOINTS(domain)
|
|
|
|
|
2023-04-23 20:18:16 +01:00
|
|
|
await Promise.all(
|
2023-05-02 15:49:05 +01:00
|
|
|
gameData.map(async (endpoint) => {
|
|
|
|
if (endpoint.src.startsWith('http')) {
|
|
|
|
return await client
|
|
|
|
.get(endpoint.src, { responseType: ResponseType.Text })
|
|
|
|
.then(async ({ data }) => {
|
|
|
|
return await downloadGamedata(data as string, endpoint).catch((error) => {
|
|
|
|
return console.log(error)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
return callback(error, 'error')
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
return await parseData(Convertion.gamedataDir, endpoint.file_name, endpoint.src)
|
|
|
|
}
|
2023-04-23 20:18:16 +01:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2023-04-28 14:40:45 +01:00
|
|
|
// callback('Converting shockwave files...', 'loading')
|
2023-04-23 23:28:28 +01:00
|
|
|
|
|
|
|
// fetch, read and convert the files from the production folder in the user downloads' folder
|
|
|
|
// write the files into a seperate folder
|
2023-04-23 20:18:16 +01:00
|
|
|
} else {
|
|
|
|
/* ASSETS_ENDPOINTS(domain).map((endpoint) => {
|
|
|
|
client.get()
|
|
|
|
}) */
|
|
|
|
}
|
|
|
|
}
|