process.env.NODE_ENV = "production"; import preact from "preact"; import { observable } from "mobx"; import { observer } from "../render-utils/observer"; import { isNode } from "socket-function/src/misc"; import { delay } from "socket-function/src/batching"; import { formatNumber, formatDateTime } from "socket-function/src/formatting/format"; import { css } from "typesafecss"; import { InputLabel } from "../render-utils/InputLabel"; import { redButton, greenButton, errorMessage } from "../render-utils/colors"; import { createArchives } from "../storage/remoteStorage/createArchives"; import { ArchiveFileInfo } from "../storage/IArchives"; // The bucket's routing URL: server, account ("example"), and bucket ("examplefiles") in one. Nothing else is needed - the first call creates the bucket if it doesn't exist yet. const STORAGE_URL = "https://storage.vidgridweb.com:4444/file/example/examplefiles/storage/storagerouting.json"; const ACCESS_CHECK_INTERVAL = 1000 * 15; const archives = createArchives(STORAGE_URL); @observer class ExampleStoragePage extends preact.Component { synced = observable({ files: [] as ArchiveFileInfo[], loaded: false, selectedPath: "", content: "", contentLoaded: false, newFileName: "", access: undefined as { machineId: string; ip: string; reason: string } | undefined, error: "", }); componentDidMount() { void (async () => { while (true) { let access = await archives.waitingForAccess(); this.synced.access = access; if (!access) break; await delay(ACCESS_CHECK_INTERVAL); } await this.refresh(); })(); } private async refresh() { try { this.synced.files = await archives.findInfo("", { type: "files" }); this.synced.loaded = true; this.synced.error = ""; } catch (e) { this.synced.error = String(e); } } private async openFile(path: string) { this.synced.selectedPath = path; this.synced.contentLoaded = false; let data = await archives.get(path); this.synced.content = data && data.toString() || ""; this.synced.contentLoaded = true; } private async createFile() { let name = this.synced.newFileName.trim(); if (!name) return; await archives.set(name, Buffer.from("")); this.synced.newFileName = ""; await this.refresh(); await this.openFile(name); } private async deleteFile(path: string) { await archives.del(path); if (this.synced.selectedPath === path) { this.synced.selectedPath = ""; this.synced.content = ""; this.synced.contentLoaded = false; } await this.refresh(); } render() { let synced = this.synced; return