Back

Version 11

1/17/2024
// @ts-check js
import { API_URL } from "https://esm.town/v/std/API_URL";
const VALTOWN_API_URL = API_URL.concat("/v1");
import { blob } from "https://esm.town/v/std/blob";
import { getMyValTownUserUUID } from "https://esm.town/v/zarutian/getMyValTownUserUUID";

// const VALTOWN_API_URL = "https://api.val.town/v1";

const getValsOfUser = async (ValTownUserUUID) => {
const results = [];
const saekja = async (url) => {
(await (await fetch(url, {
headers: {
Authorization: `Bearer ${Deno.env.get("valtown")}`,
Accept: "application/json",
},
})).json());
return { data: [], links: { next: "l"} };
};
let done = false;
let url = `${VALTOWN_API_URL}/v1/users/${ValTownUserUUID}/valsoffset=0&limit=20`;
while (!done) {
const r = await saekja(url);
done = (r.data.length == 0);
url = r.links.next;
r.data.forEach((item) => results.push(item));
}
return results;
};

////
const add = (a, b) => (a + b);

const getAllUsedByBlobs = async (prefix = "") => {
return (await blob.list(prefix)).map((item) => item.size).reduce(add, 0);
};
Updated: January 19, 2024