Media Asset Administration
Relevant source files
The following files were used as context for generating this wiki page:
Media Asset Administration in the Lou Gehrig Fan Club (LGFC) project encompasses the systems and processes used to manage, ingest, and audit media content stored in Backblaze B2 and tracked via Cloudflare D1. This module provides a centralized administrative interface for viewing the inventory of ingested media, including B2 keys, file sizes, and ETags.
The administration system ensures that media assets are correctly synchronized between external storage (B2) and the application's local database (D1). It supports idempotent ingestion workflows and provides a gated administrative area for asset oversight.
Sources: context.md:12-13, src/app/admin/media-assets/page.tsx:94-95
Asset Data Model
The system utilizes a structured data model to track media assets across storage layers. Each asset is identified by a unique media_uid generated from B2 metadata.
MediaAsset Entity
| Field | Type | Description |
|---|---|---|
id | number | Internal D1 primary key. |
media_uid | string | Stable, deterministic identifier (deterministic hash of file ID and key). |
b2_key | string | The file path/key in the Backblaze B2 bucket. |
b2_file_id | string (null) | The unique file ID assigned by Backblaze B2. |
size | number | File size in bytes. |
etag | string (null) | Entity tag for versioning/caching. |
ingested_at | string (null) | Timestamp of when the record was added to D1. |
Sources: src/app/admin/media-assets/page.tsx:9-17, scripts/d1_media_ingest.js:56-63
Database Schema
The primary storage for asset metadata is the media_assets table in Cloudflare D1.
A unique index idx_media_assets_media_uid is maintained to prevent duplicate ingestion of the same B2 objects.
Sources: scripts/d1_media_ingest.js:188-191, src/app/admin/media-assets/page.tsx:94-95
Ingestion Workflow
The ingestion process is designed to be idempotent, allowing it to be re-run indefinitely without creating duplicate records. It bridges the gap between the B2 inventory and the D1 database.
Ingestion Logic Flow
- Metadata Generation: A stable
media_uidis computed by hashing the combination ofb2_file_idandb2_keyusing SHA-256. - Batch Querying: The script queries D1 in batches (default 500) to check for existing
media_uidrecords. - Filtering: Only objects not present in D1 are prepared for insertion.
- Execution: New records are inserted via
INSERT OR IGNOREstatements using the Wrangler CLI.
Administrative Interface
The project provides a dedicated administrative page located at /admin/media-assets for monitoring the media inventory.
Functional Components
- Authentication: Access is protected by an
x-admin-tokenstored inlocalStorageunder the keylgfc_admin_token. - Inventory Listing: Fetches data from the
/api/admin/media-assets/listendpoint with a default limit of 100 items. - Normalization: The frontend implements a strict normalization layer to validate raw API responses into
MediaAssettypes, ensuring data integrity before rendering.
API Specifications
Administrative endpoints require valid authentication and handle the core logic for asset synchronization and management.
| Endpoint | Method | Purpose | Required Fields |
|---|---|---|---|
/api/admin/media-assets/list | GET | Retrieves the inventory of ingested assets. | limit (query param) |
/api/admin/cms/save | POST | Upserts a content block with a 'draft' status. | key, page, section, title, body_md |
/api/admin/cms/publish | POST | Promotes a draft to 'published' status. | key |
Sources: src/app/admin/media-assets/page.tsx:85, functions/api/admin/cms/save.ts:25-30, functions/api/admin/cms/publish.ts:25-27
Content Revision System
While media assets are directly managed, the administration system also includes a revision mechanism for content associated with media. Saving or publishing assets triggers the creation of records in the content_revisions table, tracking version, updated_by, and the body_md payload.
Sources: functions/api/admin/cms/save.ts:48-51, functions/api/admin/cms/publish.ts:49-51
Conclusion
Media Asset Administration provides the essential link between the Backblaze B2 storage layer and the Cloudflare D1 application database. By utilizing deterministic hashing for unique identification and implementing idempotent ingestion scripts, the system maintains a consistent and audit-ready inventory of all site assets. The administrative UI further empowers authorized users to monitor ingestion status and manage content lifecycle states from draft to publication.
Sources: scripts/d1_media_ingest.js:10-25, src/app/admin/media-assets/page.tsx:103-125