Photo Archives
Relevant source files
The following files were used as context for generating this wiki page:
The Photo Archives system serves as a centralized repository for visual media within the Lou Gehrig Fan Club platform. It encompasses both general historical photographs and specific items categorized as memorabilia. The system provides a structured way to store, categorize, and retrieve images, supporting both public-facing galleries and authenticated FanClub member views.
Sources: context.md, lgfc-lite-configure-remaining.sh:220-221
The architecture relies on Cloudflare D1 for metadata storage and Backblaze B2 for binary asset storage. The system distinguishes between "Photos" and "Memorabilia" primarily through a boolean flag (is_memorabilia) within the unified photos database table, allowing for filtered views and dedicated endpoints for different content types.
Sources: context.md, functions/api/fanclub/memorabilia.ts:32, functions/api/photos/list.ts:13-16
Data Architecture and Schema
The core of the Photo Archives is the photos table in the Cloudflare D1 database. This table stores all metadata related to an asset, including its location in external storage (Backblaze B2), descriptions, and categorization tags.
Database Schema Definition
The following table summarizes the data structure used for archiving media:
| Field | Type | Description |
|---|---|---|
id | INTEGER | Primary key, unique identifier for the record. |
photo_id | TEXT | Specific identifier for B2 storage (often maps to a B2 key). |
url | TEXT | Direct URL to the hosted image asset. |
is_memorabilia | INTEGER | Boolean flag (0 or 1) identifying the item as memorabilia. |
title | TEXT | Short title for the image. |
description | TEXT | Detailed caption or historical context. |
tags | TEXT | Comma-separated strings for filtering and search. |
source | TEXT | Information regarding the origin or uploader of the photo. |
created_at | TIMESTAMP | Record creation date. |
Sources: functions/api/fanclub/photos.ts:39-65, functions/api/photos/list.ts:13-16, lgfc-lite-configure-remaining.sh:173-177
Entity Relationships
The Photo Archives system interacts with the Library system through search queries, providing related context when users browse memorabilia.
API Implementation
The system utilizes Cloudflare Pages Functions to handle media retrieval. Access is categorized into public APIs and protected FanClub member APIs.
Member-Only API Logic
FanClub endpoints require session validation via requireMember. These endpoints support pagination, keyword searching, and tag-based filtering.
Endpoint Summary
| Endpoint | Method | Access | Parameters |
|---|---|---|---|
/api/photos/list | GET | Public | limit, offset, memorabilia (0/1) |
/api/photos/get/[id] | GET | Public | id (path parameter) |
/api/fanclub/photos | GET | Member | q, tags, page |
/api/fanclub/memorabilia | GET | Member | q, tags, page |
Sources: functions/api/photos/list.ts:1-5, functions/api/photos/get.ts:1-5, functions/api/fanclub/photos.ts:21-25
Frontend Components and Views
The frontend is implemented using Next.js client components, providing a responsive grid for browsing media.
Photo Gallery vs. Memorabilia View
While both views source data from the same backend table, they utilize different filters. The Memorabilia view explicitly sets is_memorabilia = 1 in its API requests.
Key Frontend Features
- Pagination: Managed via
limitandoffsetstates to prevent large payload transfers. Sources: src/app/photos/page.tsx:18-20 - Search/Filtering: Local state filtering is combined with server-side query parameters for efficient browsing. Sources: src/app/fanclub/memorabilia/page.tsx:30-35
- Reporting System: FanClub members can report incorrect descriptions or tags directly from the gallery UI. Sources: src/app/fanclub/photo/page.tsx:35-50
Asset Resolution Logic
Image URLs are normalized before being sent to the client. The system uses a utility function, normalizePhotoUrl, to determine the final asset path, accounting for both relative storage keys and absolute URLs, while incorporating the PUBLIC_B2_BASE_URL environment variable.
// Approximate logic found in API handlers
const items = rows.results.map((row) => ({
id: row.id,
thumbnail_url: normalizePhotoUrl({
rawUrl: row.url,
request: context.request,
publicB2BaseUrl: context.env.PUBLIC_B2_BASE_URL
}),
description: row.description
}));
Sources: functions/api/fanclub/photos.ts:67-75, functions/api/fanclub/memorabilia.ts:58-65
Summary
The Photo Archives module provides a robust framework for managing the Lou Gehrig Fan Club's visual history. By leveraging Cloudflare D1 for metadata and a flexible boolean-based categorization system, it allows for seamless transitions between general photography and specialized memorabilia archives while maintaining strict access controls for FanClub members.