1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { escapeHtml } from "https://esm.town/v/vez/escapeHtml";
import { getAllVals } from "https://esm.town/v/vez/getAllVals";
export async function shittyValTownUI(req, res) {
const editVal = (body: {
code: string;
name?: string;
isInterval?: boolean;
}) =>
`fetch('https://api.val.town/eval/@vez.editVal(${JSON.stringify(body)})')`;
return res.send(`<h1>Shitty Val Town 2</h1>
${(await getAllVals("@vez")).map(({ code, name }) => {
const editorId = `${name}-editor`;
const onClick = `(document.getElementById('${name}-button').textContent = 'save 🔄'), fetch('https://api.val.town/eval/@vez.editVal', { method: 'POST', body: JSON.stringify({ name: '${name}', code: document.getElementById('${editorId}').value })}).then((
return `<h2>${name}</h2>
<textarea id="${editorId}" rows="20" cols="120">${escapeHtml(
code
)}</textarea>
<button id="${name}-button" onClick="${onClick}">save</button>`;
})}`);
}
1
2
3
4
5
6
7
8
9
10
11
12
import { getVal } from "https://esm.town/v/vez/getVal";
import { dot } from "https://esm.town/v/vez/dot";
import { getVals } from "https://esm.town/v/nate/getVals?v=4";
export const getAllVals = async (author: string) =>
(
await Promise.all(
(await getVals(author))
.map(dot("name"))
.map(getVal(author))
)
).map(dot("0"));
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
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,
);
// TODO: Paginate
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)`);
1
Next