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("");
51app.get("/", async (c) => {
52 try {
53 // Use our helper function to fetch the current Bing image
54 const response = await fetchBingImage();
55 if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
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
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
4
5* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
7
8## Migrations
18The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
19
20The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.
3export const tableName = "reactHonoStarter_messages";
4export const USERS = "USERS";
5export async function createTables() {
6 await sqlite.batch([
7 `CREATE TABLE IF NOT EXISTS ${tableName} (
6export const CONVERSATIONS = "app_conversations";
7
8export async function createTables() {
9 await sqlite.batch([
10 `PRAGMA foreign_keys = ON`,