Library & Memorabilia
Relevant source files
The following files were used as context for generating this wiki page:
The Library and Memorabilia system within the Lou Gehrig Fan Club (LGFC) repository serves as a centralized repository for historical content, member stories, and archived media. The Library module facilitates the submission and viewing of written entries, while the Memorabilia module provides a specialized view of the photo archive specifically for items tagged as historical artifacts.
These systems are integrated into the authenticated FanClub area (/fanclub/**), requiring user sessions for access. Data is persisted using Cloudflare D1, and media assets are managed via Backblaze B2, though they are served to the frontend through Cloudflare Pages Functions.
Sources: context.md:12-16, src/app/fanclub/library/page.tsx:24
System Architecture
The architecture follows a standard Next.js App Router pattern combined with Cloudflare Pages Functions for API logic. The frontend components use React hooks for state management and client-side filtering, while the backend interacts with the D1 database instance.
Data Flow Diagram
The following diagram illustrates the flow of data from a member's submission through the API to the database, and the subsequent retrieval for the Library display.
Library Module
The Library module consists of a submission interface for members to contribute stories and a viewing interface to browse approved or recent entries.
Member Submissions
Members can submit content including a title and a story body. Submissions are protected by the useMemberSession hook, ensuring only authenticated members can post. The submission UI enforces basic validation: name length (≥2), email length (≥5), title length (≥3), and content length (≥20).
Sources: src/app/fanclub/submit/page.tsx:8-12, src/app/fanclub/submit/page.tsx:35
Library Listing and Search
The LibraryPage provides a read-only view of entries. It includes a client-side search feature that filters items by title or content using a useMemo hook for performance.
Sources: src/app/fanclub/library/page.tsx:31-37
| Component | Functionality | Source File |
|---|---|---|
LibraryPage | Displays list of recent entries with search capability. | src/app/fanclub/library/page.tsx |
FanclubSubmitPage | Form for members to submit new articles/notes. | src/app/fanclub/submit/page.tsx |
/api/library/list | API endpoint to retrieve library entries from D1. | lgfc-lite-configure-remaining.sh |
/api/library/submit | API endpoint to store new member submissions. | lgfc-lite-configure-remaining.sh |
Memorabilia Module
The Memorabilia module is a specialized subset of the Photo Archive. It specifically filters for records where the is_memorabilia flag is set to true (1).
Memorabilia Retrieval Logic
The API for listing photos accepts a memorabilia query parameter. When set to 1, the SQL query is modified to include a WHERE is_memorabilia = 1 clause.
Memorabilia Data Structure
The memorabilia items are derived from the photos table schema.
| Field | Type | Description |
|---|---|---|
id | number | Unique identifier for the item. |
url | string | URL for the media asset (Backblaze B2/Cloudflare). |
is_memorabilia | number (boolean) | Flag (1 or 0) indicating historical artifact status. |
description | string | null | Descriptive text for the item. |
thumbnail_url | string | null | Optional smaller image for grid views. |
| Sources: src/app/fanclub/memorabilia/page.tsx:8, lgfc-lite-configure-remaining.sh:173 |
API Specifications
The system utilizes several Cloudflare Pages Functions to handle data operations. All endpoints return a standard JSON object containing an ok boolean and either items/item for success or error for failure.
Endpoint: /api/library/list
Used to fetch a list of library entries ordered by creation date.
- Method: GET
- Parameters:
limit(default: 10, max: 50) - Response:
{ ok: true, items: LibraryListItem[] }
Sources: lgfc-lite-configure-remaining.sh:142-154
Endpoint: /api/photos/list
Used by both the general photo archive and the memorabilia view.
- Method: GET
- Parameters:
limit: Integer (default: 20, max: 100)offset: Integer (default: 0)memorabilia: String ("1" to filter for memorabilia)
Sources: lgfc-lite-configure-remaining.sh:176-184
Implementation Details
The frontend components utilize a custom hook, useMemberSession, which handles authentication by checking localStorage for lgfc_member_email. If a user is not authenticated, they are redirected to the homepage (/).
Sources: context.md:21-23, src/app/fanclub/library/page.tsx:24
Submission Code Snippet
The following snippet from the configuration script defines the backend logic for submitting library entries:
// From functions/api/library/submit (logic described in script)
const row = await env.DB.prepare(
"INSERT INTO library_entries (name, email, title, content, created_at) VALUES (?, ?, ?, ?, ?)"
)
.bind(name, email, title, content, new Date().toISOString())
.run();
Sources: lgfc-lite-configure-remaining.sh:122-127 (derived from submit implementation logic)
Summary
The Library & Memorabilia system provides a robust framework for preserving the history of Lou Gehrig through member contributions and curated media. By leveraging Cloudflare D1 for structured data and implementing strict authentication via client-side session hooks, the project ensures a secure and performant experience for Fan Club members. The memorabilia feature effectively reuses the existing photo archive infrastructure by applying specific database filters, maintaining architectural simplicity.