1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { rootRef } from "https://esm.town/v/andreterron/rootRef?v=2";
import { blob } from "https://esm.town/v/std/blob";
import { Hono } from "npm:hono";
import { basicAuth } from "npm:hono/basic-auth";
const app = new Hono();
function getValUrl() {
const val = rootRef();
return `https://${val.userHandle}-${val.valName}.web.val.run`;
}
const valUrl = getValUrl();
app.use(
"/*",
basicAuth({
username: "admin",
password: Deno.env.get("MANAGER_KEY"),
}),
);
app.get("/", async (c) => {
const blobs = await blob.list();
for (let el of blobs) {
el.deleteUrl = `${valUrl}/delete/${el.key}`;
el.value = await blob.getJSON(el.key);
}
return c.json(blobs);
});
app.get("/delete/:blobKey", async (c) => {
const blobKey = c.req.param("blobKey");
const current = await blob.getJSON(blobKey);
if (current === undefined) {
return c.text("the blob does not exist");
}
console.log("deleting", current);
await blob.delete(blobKey);
return c.text("blob deleted");
});
app.get("/dummy", async (c) => {
await blob.setJSON("dummyBlob1", 101);
await blob.setJSON("dummyBlob2", "dummy text");
await blob.setJSON("dummyBlob3", { dummy: true, test: 101 });
return c.text("dummy data added");
});
export default app.fetch;