import { paginateAPI } from "https://esm.town/v/andreterron/paginateAPI";
import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
let max: { lines: number; name: string } | undefined;
const opts = {
headers: {
Authorization: `Bearer ${Deno.env.get("valtown")}`,
},
};
const me = await fetchJSON(
`${API_URL}/v1/me`,
opts,
);
const vals = await paginateAPI(
`${API_URL}/v1/users/${me.id}/vals?limit=100`,
opts,
);
for (let val of vals) {
const lines = ((val.code as (string | null)) ?? "").trim().split("\n").length;
if (max === undefined || lines > max.lines) {
max = { lines, name: val.name };
}
}
console.log("Longest val:", max?.name, `(${max.lines ?? 0} lines)`);