• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
figleaf

figleaf

photo

Public
Like
photo
Home
Code
7
.claude
1
.vtignore
AGENTS.md
README.md
deno.json
E
photoEmailHandler.ts
H
servePhoto.ts
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
servePhoto.ts
https://figleaf--e5907e2ababb11f085f50224a6c84d84.web.val.run
README.md

Photo Display Service

A simple Val Town project that displays a photo on a webpage, updatable via email.

Overview

This project consists of two Val Town handlers:

  1. Email Handler (photoEmailHandler.ts) - Receives photos via email and stores them
  2. HTTP Handler (servePhoto.ts) - Serves the current photo on a webpage

How It Works

Uploading Photos

Send an email with exactly one image attachment to your Val Town email address. The handler will:

  • Validate the image attachment
  • Store the image in blob storage
  • Keep a history of all uploaded photos
  • Send you a confirmation email with upload details

Viewing Photos

Visit your Val's HTTP endpoint to see:

  • The current photo displayed in a clean, centered layout
  • A small counter showing which photo number it is (e.g., "This is the 3rd photo.")

Features

  • Email-based uploads - No UI needed to update photos
  • Upload history - Tracks all photos with metadata (timestamp, sender, filename)
  • Photo counter - Displays which upload number the current photo is
  • Multiple format support - JPEG, PNG, GIF, WebP, SVG, BMP, TIFF, ICO
  • Error handling - Email notifications for upload errors
  • Caching - HTTP responses cached for 5 minutes for performance

Project Structure

photo/
├── photoEmailHandler.ts    # Email trigger handler
├── servePhoto.ts           # HTTP endpoint handler
├── deno.json               # Deno configuration
└── README.md               # This file

API Routes

GET /

Serves an HTML page displaying the current photo with a counter.

GET /image

Returns the raw image file with appropriate Content-Type header.

Storage Schema

Blob Keys

  • photo - The current photo (binary data)
  • photoMeta - Metadata for the current photo
    { contentType: string, extension: string, originalFilename: string, uploadedAt: string, photoNumber: number }
  • photoHistory_{n} - Historical record for each upload
    { photoNumber: number, uploadedAt: string, filename: string, contentType: string }

Email Handler Behavior

Success Case

  • Attachment count: 1 image
  • Response: Confirmation email with upload details

Error Cases

  • No images: Error email requesting an image attachment
  • Multiple images: Error email requesting exactly one image
  • Processing error: Error email with error details

Usage

  1. Deploy both vals to your Val Town account
  2. Configure photoEmailHandler.ts as an email trigger
  3. Configure servePhoto.ts as an HTTP trigger
  4. Email a photo to your Val Town email address
  5. Visit your HTTP endpoint to see the photo

Technical Details

  • Runtime: Deno on Val Town
  • Storage: Val Town Blob Storage
  • Image formats: Determined by MIME type
  • Max photo size: Limited by Val Town blob storage limits
  • Cache duration: 5 minutes (300 seconds)

Customization

Adjust Image Display

Edit the CSS in servePhoto.ts to change:

  • Background color
  • Maximum image width (currently 9600px)
  • Counter styling and position

Modify Email Notifications

Edit the email templates in photoEmailHandler.ts to customize:

  • Confirmation message content
  • Error message formatting
  • Email subjects

License

MIT

HTTP
  • servePhoto.ts
    figleaf--e5…84.web.val.run
Email
  • photoEmailHandler.ts
Code
.claude.vtignoreAGENTS.mdREADME.mddeno.json
E
photoEmailHandler.ts
H
servePhoto.ts
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.