created proxy for parser backend

This commit is contained in:
2025-05-22 23:31:17 +05:00
parent 9faf3f7618
commit 8e4ce66cc4
14 changed files with 146 additions and 15 deletions
+17 -5
View File
@@ -10,20 +10,28 @@ export interface SaveStatusResponse {
}
export class SaveParserBackendService {
private API_BASE = 'http://localhost:5226'
private API_BASE = '/api/proxy/parserBackend'
private async tryGetResponseJson(res: Response): Promise<string> {
try {
const body = await res.json()
return JSON.stringify(body)
} catch {}
return ''
}
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',
'Content-Type': 'application/octet-stream',
},
body: file,
})
if (!response.ok) {
throw new Error(`Failed to upload save: ${response.statusText} \n${await response.text()}`)
throw new Error(`Failed to upload save: ${response.statusText} ${await this.tryGetResponseJson(response)}`)
}
return await response.json()
@@ -34,7 +42,9 @@ export class SaveParserBackendService {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Failed to get save status: ${response.statusText} \n${await response.text()}`)
throw new Error(
`Failed to get save status: ${response.statusText} ${await this.tryGetResponseJson(response)}`
)
}
return await response.json()
@@ -45,7 +55,9 @@ export class SaveParserBackendService {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`Failed to get parsed save: ${response.statusText} \n${await response.text()}`)
throw new Error(
`Failed to get parsed save: ${response.statusText} ${await this.tryGetResponseJson(response)}`
)
}
return await response.json()