1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { rawFetch } from "https://esm.town/v/std/rawFetch";
3
4/**
5 * Wraps the JavaScript Fetch function to anonymize where the request is
6 * coming from ([Docs ↗](https://docs.val.town/std/fetch))
7 *
8 * @param {string | URL} input - The URL to fetch
9 * @param {RequestInit} [requestInit] - Optional configuration data (HTTP
10 * method, headers, etc) ([Docs ↗](https://deno.land/api@v1.42.1?s=RequestInit))
11 */
12export async function fetch(input: string | URL, requestInit?: RequestInit) {
13 let query = new URLSearchParams({
14 url: input.toString(),
15 });
16 return rawFetch(`${API_URL}/v1/fetch?${query}`, {
17 ...requestInit,
18 headers: {
61 attachments?: AttachmentData[];
62}) => {
63 let result = await fetch(
64 `${API_URL}/v1/email`,
65 {
35
36async function execute(statement: InStatement): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
49
50async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52 method: "POST",
53 headers: {
82async function list(prefix?: string): Promise<{ key: string; size: number; lastModified: string }[]> {
83 let querystring = prefix ? `?prefix=${encodeURIComponent(prefix)}` : "";
84 const res = await fetch(`${API_URL}/v1/blob${querystring}`, {
85 headers: {
86 Authorization: `Bearer ${Deno.env.get("valtown")}`,
95
96async function delete_(key: string) {
97 const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
98 method: "DELETE",
99 headers: {
108
109async function get(key: string) {
110 const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
111 headers: {
112 Authorization: `Bearer ${Deno.env.get("valtown")}`,
124
125async function set(key: string, value: BodyInit) {
126 const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
127 method: "POST",
128 headers: {
9app.get("/", async (c) => c.html(await sqlite_admin_tables()));
10app.get("/:table", async (c) => c.html(await sqlite_admin_table(c.req.param("table"))));
11export default basicAuth(app.fetch);
11});
12
13export default app.fetch;
1// SPDX-License-Identifier: 0BSD
2import { fetchVal } from "https://esm.town/v/vladimyr/fetchVal";
3import { serveReadme } from "https://esm.town/v/vladimyr/serveReadme";
4import { toHonoHandler } from "https://esm.town/v/vladimyr/toHonoHandler";
11 // const { author, name } = c.req.param();
12 const query = c.req.query();
13 const res = await fetch(
14 "https://raw.githubusercontent.com/burningion/dab-and-tpose-controlled-lights/master/src/dab-tpose-controller.py",
15 );
19});
20
21export default router.fetch;
22
23export async function createScreenshot(code: string, theme: string = "dark-plus"): Promise<URL> {
24In any other platform, I would have just given up and moved on. But Val Town is different. I was confident that I could address this issue in userspace, without having to wait for the platform to implement it.
25
26Val Town allows you to run a val on a cron schedule, so I wrote a val that would fetch all the vals from the API, and store them as a sqlite table (did I mention that every user get it's own sqlite database ?).
27
28```ts
38 let url = "https://api.val.town/v1/search/vals?query=%20&limit=100";
39
40 // fetch all vals, and store them in the sqlite table
41 while (true) {
42 const resp = await fetch(url);
43 if (!resp.ok) {
44 throw new Error(await resp.text());
1import { fetch } from "https://esm.town/v/std/fetch";
2
3// Send a pushover message.
16 url: string;
17}) {
18 return await fetch("https://api.pushover.net/1/messages.json", {
19 method: "POST",
20 headers: {
9}
10
11async function fetchText(url: string, options?: any) {
12 const response = await fetch(normalizeURL(url), {
13 redirect: "follow",
14 ...(options || {}),
19
20export const webScrapeBytesNewsletter = async () => {
21 const html = await fetchText(NEWSLETTER_URL);
22 const $ = cheerio.load(html);
23 const latestIssueSection = $("main > :nth-child(2)");