1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export let evalPost2 = fetchJSON(
4 "https://api.val.town/v1/eval",
5 {
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2import { HNcache } from "https://esm.town/v/stevekrouse/HNcache";
3import { hnPostIdsBy } from "https://esm.town/v/akkartik/hnPostIdsBy?v=3";
6 let postIds = await hnPostIdsBy(user);
7 return postIds.slice(0, 10).map(async (id) => {
8 HNcache[id] = await fetchJSON(
9 `https://hacker-news.firebaseio.com/v0/item/${id}.json`
10 );
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
2import { dateMeProfiles } from "https://esm.town/v/stevekrouse/dateMeProfiles";
3
4// can only do first 100 because Val Town only allows 100 fetches per run
5export let allDateMeDocsLength =
6 (await Promise.all(
7 dateMeProfiles.slice(0, 100).map((p) =>
8 p.Profile?.at(0)?.href &&
9 fetchText(p.Profile[0].href).catch((e) => void 0)
10 ),
11 )).join("").length;
4 const app = new Elysia()
5 .get("/", () => items).post("/", () => items.push(Math.random()));
6 return app.fetch(req);
7};
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export let pageIncludes = async function (url, str) {
4 const f = await fetch(url);
5 const t = await f.text();
6 return t.includes(str);
6 filters,
7 current_state,
8 fetch_limit,
9 enable_toggle,
10 force,
15
16 // TODO: handle >10 subreddits by raising and exception?
17 let fetch_budget = Math.floor(fetch_limit / Object.keys(filters).length);
18 let additional_fetches_required = {};
19 let fetch_total = 0;
20
21 for (const subreddit in filters) {
44 filters: subreddit_filters,
45 after_utc: last_run_at_utc,
46 fetch_limit: fetch_budget,
47 });
48
49 fetch_total += result.fetches;
50
51 if (result.next_fetch_from) {
52 additional_fetches_required[subreddit] = result.next_fetch_from;
53 }
54
55 let extra_message = additional_fetches_required[subreddit]
56 ? `, reached fetch limit (${fetch_budget}), loading more posts after other subreddits if possible`
57 : "";
58 console.log(`processed ${result.new_posts} posts${extra_message}`);
66 }
67
68 // TODO: handle additional_fetches_required
69
70 let text = [];
1import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=5";
2
3export const discordWebhook = async ({ url, content }: {
5 content: string;
6}) => {
7 const text = await fetchText(url, {
8 method: "POST",
9 headers: {
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export let getURLMetadata = async (url) => {
4 const response = await fetch(url);
5 const webpage = await response.text();
6 // Maybe this will work when val.town switches to Deno :-)
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export const proxyFetch1 = async (req, res) => {
4 const { url, options } = req.body;
5 try {
6 const response = await fetch(url, options);
7 return res.status(response.status).send(await response.text());
8 } catch (e) {
9 const errorMessage = e instanceof Error ? e.message : "Unknown error";
10 console.error("Failed to initiate fetch", e);
11 return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
12 }
13};
1import { fetch } from "https://esm.town/v/std/fetch";
2import { rule } from "https://esm.town/v/cescyang/rule";
3
7 "https://sapphire.api.microsoftapp.net/config/api/v1/get?setmkt=en-us&setplatform=android&setchannel=production&settenant=sapphire-bing";
8 try {
9 const response = await fetch(url, {
10 method: "GET",
11 });