mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
31 lines
817 B
TypeScript
31 lines
817 B
TypeScript
import { CatalogItem } from '@protos/blitz_items';
|
|
import { CatalogItemAccessor } from '../catalogItemAccessor';
|
|
import { MetadataAccessor } from './abstract';
|
|
|
|
export class RemoteMetadataAccessor extends MetadataAccessor {
|
|
constructor(private base: string) {
|
|
super();
|
|
}
|
|
|
|
async get(item: string) {
|
|
const response = await fetch(`${this.base}/${item}.pb`);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Item ${item} does not exist in remote metadata`);
|
|
}
|
|
|
|
const buffer = new Uint8Array(await response.arrayBuffer());
|
|
const catalogItem = CatalogItem.decode(buffer);
|
|
|
|
return new CatalogItemAccessor(catalogItem);
|
|
}
|
|
|
|
add() {
|
|
throw new Error('Cannot add items to remote metadata');
|
|
}
|
|
|
|
filter(): CatalogItemAccessor[] {
|
|
throw new Error('Cannot filter remote metadata');
|
|
}
|
|
}
|