DEV Community

Cover image for I built a site where you throw tomatoes at any picture (Next.js, Vercel Blob, no sign-up)
P33M
P33M

Posted on

I built a site where you throw tomatoes at any picture (Next.js, Vercel Blob, no sign-up)

I kept seeing those TikTok videos where a tomato flies at the camera, gets smaller as it goes, and splats on the screen. I wanted that exact feel in a browser, so I built Tomato Throw: you upload a picture, optionally give it a name, and get a link. Anyone who opens the link taps to throw tomatoes at it. No account, no email.

Try it: https://tomatothrow.com

Most of the site is small. A few parts fought back, and those are the ones worth writing about.

The flight

My first attempt used CSS transitions, and it looked like a sticker sliding across a screen. A real throw is an arc that shrinks and spins at the same time, and I couldn't get all three from one transition. So the tomato gets keyframes sampled along a quadratic bezier, handed to the Web Animations API:

const STEPS = 18;
const frames: Keyframe[] = [];
for (let i = 0; i <= STEPS; i++) {
  const u = i / STEPS;
  const t = 1 - (1 - u) * (1 - u); // ease-out: fast off the hand, slower far away
  const mt = 1 - t;
  const x = mt * mt * x0 + 2 * mt * t * cx + t * t * x1;
  const y = mt * mt * y0 + 2 * mt * t * cy + t * t * y1;
  const scale = (size0 + (size1 - size0) * Math.pow(t, 0.7)) / size0;
  frames.push({
    offset: u,
    transform: `translate(${x - size0 / 2}px, ${y - size0 / 2}px) rotate(${rot + spin * t}deg) scale(${scale})`,
  });
}
el.animate(frames, { duration: 650, easing: "linear", fill: "forwards" });
Enter fullscreen mode Exit fullscreen mode

The control point sits above the target with a bit of random sideways drift, so no two throws look the same. The ease-out is applied to the parameter instead of the animation, which is why the animation's own easing stays linear.

Splats that can be drawn twice

Each splat is an SVG blob built from a seed: a spiky outline, a lighter inside, droplets, a few seeds. Same seed, same splat, every time. That turned out to matter more than I planned, because the preview image (the card X or Slack shows when someone pastes a link) is rendered on the server with next/og, and it has to look like what you see in the page. The same shape function feeds both.

satori, the renderer behind next/og, only accepts plain SVG elements inside an <svg>, so I couldn't reuse my React components there. I ended up exporting the tomato art as an array of elements instead of a component.

Where pictures live

Vercel's serverless disk is read-only, so my first version died with ENOENT: mkdir '/var/task/.uploads' the moment it left my laptop. I moved to a private Vercel Blob store. Each picture is a single file named <id>~<base64url(name)>.<ext>, which means one list() call tells me whether the picture exists and what it's called. No database.

Vercel also caps request bodies at 4.5 MB, and phone photos are bigger than that. The browser now shrinks them on a canvas before uploading, so a 12 MB photo goes up as a smaller JPEG. GIFs are sent as they are.

The part I'm still unsure about

If anyone can upload anything and share a public link, someone will upload something they shouldn't. So every picture page has a Report button. Three different reporters delete the picture automatically; I store a short hash of each reporter's address so one person can't report the same picture ten times. I can also delete a picture by hand through a token-protected route.

Rate limiting is the weak spot: it's in memory, per serverless instance, so it stops casual flooding and nothing more. A Vercel Firewall rule sits on top of it. If you've run an upload site, I'd like to hear what I've missed.

Small things I'd keep

  • Sounds are synthesized with WebAudio, so there are no audio files to download.
  • The layout uses 100dvh and container query units; mobile browser toolbars broke 100vh for me within five minutes.
  • Pages for individual pictures are noindex but still crawlable, because a crawler can't read a noindex tag on a page it isn't allowed to fetch.

The first tomato I threw was at a picture of my own face, and I recommend starting there.

Top comments (0)