summaryrefslogtreecommitdiff
path: root/viewer/main.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/main.ts')
-rw-r--r--viewer/main.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/viewer/main.ts b/viewer/main.ts
index 4320b68..5aa1df6 100644
--- a/viewer/main.ts
+++ b/viewer/main.ts
@@ -17,3 +17,45 @@ function draw() {
canvas.addEventListener("resize", () => draw())
draw()
+class Resource<T> {
+ constructor(public hash: Uint8Array) { }
+ toString() {
+ return Array.from(this.hash)
+ .map(e => e.toString(16).padStart(2, "0"))
+ .join("")
+ }
+ async download_raw() {
+ const res = await fetch(`http://127.0.0.1:28556/${this.toString()}`)
+ if (!res.ok) throw new Error("aaaa");
+ return await res.bytes()
+ }
+}
+
+function read_res_table(buffer: Uint8Array): { [key: string]: Uint8Array[] } {
+ const view = new DataView(buffer.buffer)
+ let p = 0
+ const out: { [key: string]: Uint8Array[] } = {}
+ while (p < view.byteLength) {
+ const key_len = view.getInt16(p, true)
+ p += 2
+ const value_len = view.getInt16(p, true)
+ p += 2
+ const key = String.fromCharCode(...buffer.slice(p, p + key_len))
+ p += key_len
+ const value = buffer.slice(p, p + value_len)
+ p += value_len
+ out[key] ??= []
+ out[key].push(value)
+ }
+ return out
+}
+
+async function init() {
+ const resp = await fetch("http://127.0.0.1:28556/entry")
+ if (!resp.ok) throw new Error("aaaa");
+ const entry_res = new Resource(await resp.bytes())
+
+ const entry = await entry_res.download_raw()
+ console.log(read_res_table(entry))
+}
+init() \ No newline at end of file