created SaveFileUploadDialog and SaveParserBackendService

This commit is contained in:
Altair-sh
2025-05-22 17:09:44 +05:00
parent c216250eca
commit 9faf3f7618
6 changed files with 166 additions and 14 deletions
+55
View File
@@ -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()