No description
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-25 18:44:56 -07:00
example photo-feed module: router, sharp pipeline, storage backends, metadata, feed 2026-10-25 17:59:02 -07:00
src feat: 413 responses include the active limits 2026-10-25 18:44:56 -07:00
test feat: 413 responses include the active limits 2026-10-25 18:44:56 -07:00
.gitignore scaffold: Node 22 ESM package with express 5, multer, sharp 2026-10-25 17:59:02 -07:00
package-lock.json feat: accept HEIC/HEIF by converting to JPEG via WASM decoder 2026-10-25 18:10:25 -07:00
package.json feat: 413 responses include the active limits 2026-10-25 18:44:56 -07:00
README.md feat: accept HEIC/HEIF by converting to JPEG via WASM decoder 2026-10-25 18:10:25 -07:00

photo-feed

A small, self-hostable photo upload and feed module for Express. Point it at a folder (or later, an S3-compatible bucket), mount its router, and get multi-file uploads with EXIF-corrected thumbnails, a newest-first feed with cursor pagination, and deletes restricted to the uploader. It has no opinion about auth, accounts, or design — those are the host app's job.

Install

Requires Node 22+.

npm install photo-feed

Usage

import express from "express";
import { createPhotoFeed } from "photo-feed";

const app = express();

app.use(express.static("./data")); // serve stored files at their keys

app.use(createPhotoFeed({
  storage: "local",       // "local" | "s3" | a custom {put,get,delete,url,stream} object
  dataDir: "./data",      // images/, thumbnails/, and images.json live here
  thumbWidth: 480,        // max thumbnail width in px
  pageSize: 24,           // default and max feed page size
  maxFileBytes: 25 * 1024 * 1024,
  maxFiles: 20,
  uploaderId: (req) => req.uploaderId, // how the host injects identity
  salt: "a-long-random-secret",
}));

Routes

  • POST /photos — multipart upload. Field photos (repeatable), optional contributor text field. Returns 201 with an array of {id, url, thumbUrl, contributor, createdAt, width, height}. Files over maxFileBytes or uploads over maxFiles return 413.
  • GET /photos — newest-first feed. Optional cursor (opaque, from nextCursor) and limit (≤ pageSize). Returns {photos: [...], nextCursor}; nextCursor is null at the end.
  • DELETE /photos/:id — 204 when the request's uploader matches the photo's uploader, 403 otherwise, 404 when the photo doesn't exist.

Formats

Accepted upload types: JPEG, PNG, GIF, WebP, AVIF, TIFF and HEIC/HEIF. HEIC is decoded with a WASM decoder and stored as JPEG (images/<id>.jpg) — prebuilt sharp cannot decode HEVC — so every stored original is viewable without extra native libraries. Thumbnails are always JPEG.

Ownership

Every photo stores sha256(uploaderId + salt). The plaintext uploader id is never written to disk. Pass a secret salt — it makes the stored hash unusable without it. Deleting requires the same uploaderId for that request.

Storage backends

storage: "local" (the default) writes images/<id>.<ext> and thumbnails/<id>.jpg under dataDir; serve that directory statically (or through your own file route) and the url/thumbUrl fields resolve.

storage: "s3" selects an S3/Garage backend that is not implemented yet — every operation currently throws. Configure it via the same environment variable names used elsewhere: S3_ENDPOINT, S3_REGION, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY.

Any object implementing {put, get, delete, url, stream} is accepted as a custom backend.

Example

A runnable demo with a minimal upload form lives in example/:

node example/server.js
# open http://localhost:3000

Uploads land in example/data/images/ and example/data/thumbnails/, and GET /photos returns the feed JSON.

Status

Early. Auth, sessions, HTML, and styling are deliberately out of scope; see the project vault for the roadmap.