1import { email } from "https://esm.town/v/std/email";
2
3export default async function (interval: Interval) {
4 try {
5 // Fetch RSS feed from Seth's blog
1const msg = new TextEncoder().encode("data: hello\r\n\r\n");
2
3export default async function(req: Request): Promise<Response> {
4 let timerId: number | undefined;
5 try {
17)`);
18
19async function addFeedback(req: Request) {
20 const formData = await req.formData();
21 let data = Object.fromEntries(formData.entries());
1/**
2 * Sound effects utility functions for the application
3 */
4
7 * @returns A Promise that resolves when the sound has started playing
8 */
9export function playBellSound(): Promise<void> {
10 return new Promise((resolve) => {
11 try {
69 * @returns A Promise that resolves when the sound has started playing
70 */
71export function playSimpleNotification(): Promise<void> {
72 return new Promise((resolve) => {
73 try {
1import * as cheerio from "npm:cheerio";
2
3function getIdFromInstagramLink(url: string): string {
4 const match = url.match(/\/p\/([^/]+)/);
5 return match ? match[1] : "";
6}
7
8function extractInstagramCaption(html: string): string | undefined {
9 const $ = cheerio.load(html);
10
17}
18
19function extractInstagramUsername(html: string): string | undefined {
20 const $ = cheerio.load(html);
21
36}
37
38export default async function instagramPostExtract(
39 url: string,
40): Promise<InstagramPostMeta> {
2import { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
3
4export default function App() {
5 const [url, setUrl] = useState("");
6 const [resultCaption, setResultText] = useState("");
1/**
2 * Helper function to fetch the Bing Image of the Day
3
4 * @returns Promise containing the image response
5 */
6export async function fetchBingImage(): Promise<Response> {
7 try {
8 // Fetch the HTML page
5 * Backup the current Bing Image of the Day to blob storage
6 */
7export async function backupBingImage(): Promise<void> {
8 try {
9 // Fetch the Bing image of the day using our helper
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}
16In a normal server environment, you would likely use a middleware [like this one](https://hono.dev/docs/getting-started/nodejs#serve-static-files) to serve static files. Some frameworks or deployment platforms automatically make any content inside a `public/` folder public.
17
18However in Val Town you need to handle this yourself, and it can be suprisingly difficult to read and serve files in a Val Town Project. This template uses helper functions from [stevekrouse/utils/serve-public](https://www.val.town/x/stevekrouse/utils/branch/main/code/serve-public/README.md), which handle reading project files in a way that will work across branches and forks, automatically transpiles typescript to javascript, and assigns content-types based on the file's extension.
19
20### `index.html`
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
Helper function to send Discord messages
Simple functional CSS library for Val Town
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.