added comments

This commit is contained in:
Altair-sh
2026-09-04 19:36:12 +02:00
parent 95880ca080
commit 0ecac6533c
17 changed files with 68 additions and 29 deletions
+3
View File
@@ -3,11 +3,13 @@
class AuthService {
private API_BASE = '/api/auth'
// Hashes the password before sending it to the backend
private hashPassword(password: string) {
// TODO: password hashing
return password
}
// Logs in with email and password, returning the parsed JSON response.
async login(email: string, password: string) {
const response = await fetch(`${this.API_BASE}/login`, {
method: 'POST',
@@ -25,6 +27,7 @@ class AuthService {
return await response.json()
}
// Registers a new user, returning the parsed JSON response.
async register(name: string, email: string, password: string) {
const response = await fetch(`${this.API_BASE}/register`, {
method: 'POST',
+15 -15
View File
@@ -11,18 +11,20 @@ export interface SaveStatusResponse {
uploadDateTime: string
}
// Tries to read the response body as string, returning an empty string if that fails.
async function getBodyTextOrEmpty(res: Response): Promise<string> {
try {
return await res.text()
} catch {
return ''
}
}
export class SaveParserBackendService {
private API_BASE = PROXY_PATHS.saveParserBackend
private async tryGetResponseJson(res: Response): Promise<string> {
try {
const body = await res.json()
return JSON.stringify(body)
} catch {}
return ''
}
//TODO: save size limit 30 mb
// Uploads a save file for the given game and returns its assigned id.
async uploadSave(game: string, file: File): Promise<UploadSaveResponse> {
const url = `${this.API_BASE}/uploadSave?game=${encodeURIComponent(game)}`
const response = await fetch(url, {
@@ -34,33 +36,31 @@ export class SaveParserBackendService {
})
if (!response.ok) {
throw new Error(`Failed to upload save: ${response.statusText} ${await this.tryGetResponseJson(response)}`)
throw new Error(`Failed to upload save: ${response.statusText} ` + (await getBodyTextOrEmpty(response)))
}
return await response.json()
}
// Fetches the current parsing status of a previously uploaded save.
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} ${await this.tryGetResponseJson(response)}`
)
throw new Error(`Failed to get save status: ${response.statusText} ` + (await getBodyTextOrEmpty(response)))
}
return await response.json()
}
// Fetches the fully parsed data for a save once its parsing is done.
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} ${await this.tryGetResponseJson(response)}`
)
throw new Error(`Failed to get parsed save: ${response.statusText} ` + (await getBodyTextOrEmpty(response)))
}
return await response.json()