Both stores carried their own ~28-line request<T>, and formatBytes existed twice – the second copy had lost the "B" branch, so a small sprite would have read as 0 KB had its caller ever passed one under a kilobyte. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
30 lines
946 B
TypeScript
30 lines
946 B
TypeScript
import { apiRequest } from './http';
|
|
import type { StoredTexture, TextureStore, UploadedTexture } from './TextureStore';
|
|
|
|
export class HttpTextureStore implements TextureStore {
|
|
constructor(private readonly endpoint: string) {}
|
|
|
|
async upload(bytes: Blob | ArrayBuffer, type: string): Promise<UploadedTexture> {
|
|
return this.request<UploadedTexture>('POST', 'textures', { bytes, type });
|
|
}
|
|
|
|
async list(): Promise<StoredTexture[]> {
|
|
return this.request<StoredTexture[]>('GET', 'textures');
|
|
}
|
|
|
|
async delete(file: string): Promise<void> {
|
|
await this.request<void>('DELETE', `textures/${encodeURIComponent(file)}`);
|
|
}
|
|
|
|
private async request<T>(
|
|
method: string,
|
|
route: string,
|
|
payload?: { bytes: Blob | ArrayBuffer; type: string },
|
|
): Promise<T> {
|
|
return apiRequest<T>(this.endpoint, method, route, {
|
|
headers: payload ? { 'Content-Type': payload.type } : {},
|
|
body: payload?.bytes,
|
|
});
|
|
}
|
|
}
|