2023-04-23 20:18:16 +01:00
|
|
|
import { ResponseType } from '@tauri-apps/api/http'
|
|
|
|
|
|
|
|
import { GAME_ENDPOINTS, client } from '../config/Endpoints'
|
|
|
|
import type { DomainTypes } from '../types/Domain'
|
2023-04-23 23:28:28 +01:00
|
|
|
import { fetchGamedataConfig } from './fetchGamedataConfig'
|
|
|
|
import type { ConvertionHandler } from '../types/global'
|
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
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
GAME_ENDPOINTS(domain).map(async (endpoint) => {
|
|
|
|
await client
|
|
|
|
.get(endpoint.src, { responseType: ResponseType.Text })
|
|
|
|
.then(async ({ data }) => {
|
2023-04-23 23:28:28 +01:00
|
|
|
return await fetchGamedataConfig(data as string, endpoint)
|
2023-04-23 20:18:16 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
return callback(error, 'error')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
}) */
|
|
|
|
}
|
|
|
|
}
|