Adam Bandel


Media Feed Gallery

Aug 2026
Type: web-app
Code: 31k lines
Files: 100
Active: Jan 2026 to Aug 2026
Stack:
JavaScriptNode.js / ExpressSQLite (better-sqlite3, FTS5)PreactViteSharpffmpegDocker
Tags:
mediaaggregationself-hosted

Overview

Media Feed Gallery is a self-hosted web app that pulls media from 4chan boards, Reddit subreddits, booru image boards and sites that gallery-dl can read into one gallery. It syncs a source when asked, or once a day when automatic refresh is switched on, stores the thumbnails locally along with every full file that gets opened or saved, and hides reposts of images it already has.

It is built to be a polite client of the sites it pulls from, with rate limiting, exponential backoff, and by default at most one automatic refresh per source a day, so it doesn’t flood them with requests. Reddit and gallery-dl go through my Search Gateway, so this app holds no Reddit credentials and runs no Python. Since July 2026 it runs in Docker on my home server, reachable only on my own network.

A separate Browse tab is a read-only explorer for an existing media library on the same server. It shares the interface but none of the gallery’s data.

Screenshots

Catalog View

Lightbox Viewer

Overview Dashboard

Problem

Browsing media across 4chan, Reddit and various booru sites means switching between tabs and interfaces and losing track of things. The sites have inconsistent APIs, aggressive rate limits, and no shared way to save or organize media. Imageboard content also doesn’t last: threads get pruned, and their media disappears with them.

This project keeps a local copy instead. It syncs every source into one database, caches thumbnails at sync time and full files once they are opened or saved, and shows it all in one interface.

Approach

Fetchers deal with each source’s quirks, a sync service runs the syncs, and a scheduler handles automatic refresh from a job queue that survives restarts. The gallery has feeds per source, views that mix several sources, full-text search, saved items, and a fullscreen carousel with shuffle and a slideshow.

Stack

Challenges

Outcomes

It pulls from all four kinds of source. Thumbnails, and anything already opened, load from local disk instead of the source. Saved items download their full files automatically, and the saved list can be exported as a zip. By June 2026 it held about 286,000 posts and 470,000 media items, and the first full duplicate pass hid 60,302 posts.

Limits

Implementation Notes

The RequestGovernor waits on any backoff for the provider or host, then on the token buckets, then on the concurrency slots:

// RequestGovernor.fetch (excerpt)
await this._waitForBackoff(providerKey, hostname);

// Token throttles occur before acquiring semaphores so waiting does not block concurrency slots.
await this._getProviderBucket(providerKey).take(1);
await this._getHostBucket(hostname).take(1);

const hostSem = this._getHostSemaphore(hostname);
await this.globalSemaphore.acquire();
await hostSem.acquire();

// ... the request, with a timeout, then:
if (res.status === 429 || res.status === 503) {
  // Respect server-provided backoff hints when available.
  const retryAfter = parseRetryAfterSeconds(res.headers.get('retry-after'));
  const backoffSec = retryAfter ?? this.config.defaultBackoffSec;
  this._applyBackoff(providerKey, hostname, backoffSec);
}

The auto-refresh scheduler keeps its jobs in SQLite, and a provider’s worker claims the next due job in one statement:

// Claim the next due job for a provider type (sources.type). Uses a single atomic UPDATE with RETURNING.
claimNextDueForProvider: db.prepare(`
  UPDATE refresh_jobs
  SET status = 'running',
      locked_at = strftime('%s', 'now'),
      locked_by = ?,
      last_started_at = strftime('%s', 'now'),
      updated_at = strftime('%s', 'now')
  WHERE id = (
    SELECT rj.id
    FROM refresh_jobs rj
    JOIN sources s ON s.id = rj.source_id
    WHERE rj.status = 'queued'
      AND rj.run_after <= strftime('%s', 'now')
      AND s.enabled = 1
      AND s.type = ?
    ORDER BY rj.run_after ASC, rj.id ASC
    LIMIT 1
  )
    AND status = 'queued'
  RETURNING *
`),

Views combine several sources. Providers alternate one to one, and within a provider, sources take turns by weight, so a heavier source shows up more often. The ranking runs in SQL over only the rows the current page can need, not the whole table.


Related Posts

No posts yet.