1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import process from "node:process";
import { pros } from "https://esm.town/v/stevekrouse/pros";
import { email } from "https://esm.town/v/std/email?v=9";
import { verifyAPIAuth } from "https://esm.town/v/stevekrouse/verifyAPIAuth";
export async function r2Proxy(key, value, auth) {
let { handle } = await verifyAPIAuth(auth);
if (!handle)
return "Could not verify auth";
await email({ subject: `r2 proxy called ${handle}: ${key}` });
if (!pros.includes(handle))
return "r2 only for pro users";
const { S3Client } = await import(
"https://deno.land/x/s3_lite_client@0.6.1/mod.ts"
);
const s3client = new S3Client({
endPoint: process.env.r2_endpoint_url.replace("https://", ""),
region: "enam",
bucket: "userspace-proxy",
accessKey: process.env.r2_access_key_id,
secretKey: process.env.r2_secret_access_key,
});
return s3client.putObject(`${handle}/${key}`, value);
}
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