Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
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
import process from "node:process";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export const likedUpdated = async (interval: Interval) => {
// If the interval never ran, there's no time range to check for updates
if (!interval.lastRunAt) {
return;
}
const res = await fetchJSON(
"https://api.val.town/v1/me/likes",
{
headers: {
Authorization: `Bearer ${process.env.vt_token}`,
},
},
);
const likes = res.data;
// TODO: filter out my own vals
const updated = likes.filter((likedVal) =>
new Date(likedVal.runEndAt) > interval.lastRunAt
);
if (updated.length > 0) {
console.email(
updated,
updated.length === 1
? "A val you liked was updated!"
: `${updated.length} vals you liked were updated`,
);
}
};
October 23, 2023