import { FileManager } from "./formContext" /** Simple web-based FileManager that uploads directly to the API and constructs URLs synchronously. * Suitable for desktop/portal contexts where no local caching or offline support is needed. */ export default class SimpleFileManager implements FileManager { protected apiUrl: string /** @param apiUrl API base URL e.g. "https://api.mwater.co/v3/" */ constructor(apiUrl: string) { this.apiUrl = apiUrl } /** Get URL to download a file. Resolves instantly. */ async getFileUrl(fileId: string): Promise { return this.apiUrl + `files/${fileId}` } /** Upload a file directly to the API */ async uploadFile(file: File, fileId: string): Promise { const formData = new FormData() formData.append("file", file) const resp = await fetch(this.apiUrl + `files/${fileId}`, { method: "POST", body: formData }) if (!resp.ok && resp.status !== 409) { throw new Error("File upload failed: " + resp.statusText) } } }