created SaveFileUploadDialog and SaveParserBackendService
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
export interface UploadSaveResponse {
|
||||
id: string
|
||||
}
|
||||
|
||||
export interface SaveStatusResponse {
|
||||
id: string
|
||||
game: string
|
||||
status: string
|
||||
uploadDateTime: string
|
||||
}
|
||||
|
||||
export class SaveParserBackendService {
|
||||
private API_BASE = 'http://localhost:5226'
|
||||
|
||||
async uploadSave(game: string, file: File): Promise<UploadSaveResponse> {
|
||||
const url = `${this.API_BASE}/uploadSave?game=${encodeURIComponent(game)}`
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
},
|
||||
body: file,
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to upload save: ${response.statusText} \n${await response.text()}`)
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
async getSaveStatus(id: string): Promise<SaveStatusResponse> {
|
||||
const url = `${this.API_BASE}/getSaveStatus?id=${encodeURIComponent(id)}`
|
||||
const response = await fetch(url)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get save status: ${response.statusText} \n${await response.text()}`)
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
|
||||
async getParsedSave(id: string): Promise<Record<string, any>> {
|
||||
const url = `${this.API_BASE}/getParsedSave?id=${encodeURIComponent(id)}`
|
||||
const response = await fetch(url)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get parsed save: ${response.statusText} \n${await response.text()}`)
|
||||
}
|
||||
|
||||
return await response.json()
|
||||
}
|
||||
}
|
||||
|
||||
export const saveParserBackendService = new SaveParserBackendService()
|
||||
Reference in New Issue
Block a user