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
30
31
32
import { fetchPaginatedData } from "https://esm.town/v/nbbaier/fetchPaginatedData";
import { deleteVal } from "https://esm.town/v/neverstew/deleteVal";
export async function listEmptyVals(id: string) {
const token = Deno.env.get("valtown");
const res = await fetchPaginatedData(`https://api.val.town/v1/users/${id}/vals`, {
headers: { Authorization: `Bearer ${token}` },
});
return res.filter((v) => (v.code.length === 0)).map(v => v.name);
}
export async function deleteEmptyVals(id: string) {
const token = Deno.env.get("valtown");
const res = await fetchPaginatedData(`https://api.val.town/v1/users/${id}/vals`, {
headers: { Authorization: `Bearer ${token}` },
});
const vals = res.filter((v) => (v.code.length === 0)).forEach(
async v => {
try {
const result = await deleteVal({
token,
id: v.id,
});
if (result.status === 204) {
console.log(`Successfully deleted val: ${v.name}`);
}
} catch (error) {
console.log(error);
}
},
);
}