libs5/src/storage.ts

32 lines
765 B
TypeScript
Raw Normal View History

2023-08-30 18:37:51 +00:00
export default class StorageLocation {
type: number;
parts: string[];
binaryParts: Uint8Array[] = [];
expiry: number; // Unix timestamp in seconds
providerMessage?: Uint8Array; // Made optional, similar to `late` in Dart
constructor(type: number, parts: string[], expiry: number) {
this.type = type;
this.parts = parts;
this.expiry = expiry;
}
get bytesUrl(): string {
return this.parts[0];
}
get outboardBytesUrl(): string {
if (this.parts.length === 1) {
return `${this.parts[0]}.obao`;
}
return this.parts[1];
}
toString(): string {
const expiryDate = new Date(this.expiry * 1000);
return `StorageLocation(${this.type}, ${
this.parts
}, expiry: ${expiryDate.toISOString()})`;
}
}