Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { runValAPIAuth } from "https://esm.town/v/stevekrouse/runValAPIAuth";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
import { whoami } from "https://esm.town/v/stevekrouse/whoami";
export async function r2(key, value?, keys?) {
// GET
if (value === undefined) {
let handle = whoami().at(-1).slice(1).split(".")[0]
.replace("@", "");
return fetchJSON(
`https://pub-6feb98c078874338b9a3bce6ab56e815.r2.dev/${handle}/${key}`,
{ agent: null },
);
}
// SET
return runValAPIAuth({
val: "@stevekrouse.r2Proxy",
args: [key, JSON.stringify(value)],
keys,
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023