[Discussion] Notion To MD v4: Media Handler Technical Details #115
souvikinator
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Media Handler Technical Documentation
Overview
The Media Handler module serves as a crucial component in the notion-to-md pipeline, processing and managing all media-related content after the Block Fetcher completes its work. With the introduction of the builder pattern in v4, the configuration and setup have become more intuitive and flexible while maintaining the core functionality.
High Level Overview
flowchart LR A[Receive Block] --> B[Detect Media] B --> C{Media Type Check} C -->|Notion Asset| D1[Apply Strategy] C -->|External URL| D2[Check Preservation] D1 --> E[Process Media] D2 -->|Preserve| F1[Keep Original] D2 -->|Transform| F2[Apply Strategy] F2 --> E E --> G[Update Manifest] G --> H[Return Updated Block]Core Responsibilities
Configuration Using Builder Pattern
The new builder pattern provides a more intuitive way to configure media handling. Here's how the configuration system is structured:
Base Configuration
Media Strategy Configuration
The builder pattern introduces three distinct methods for configuring media handling strategies:
Strategy Requirements
Each strategy has specific requirements that must be met:
Downloadstrategy requires:outputPath: Destination directory for media filestransformPath: Function to customize media URLspreserveExternalUrls: Boolean to control external URL handlingUploadstrategy requires:uploadHandler: Async function to handle media uploadscleanupHandler: Function to manage file cleanuptransformPath: Function to modify URLs post-uploadpreserveExternalUrls: Boolean to control external URL handlingDirectstrategy (useNotionUrls):Low Level Design
flowchart TD Start[Receive Block] --> DetectMedia{Contains Media?} DetectMedia -->|No| ReturnUnchanged[Return Block] DetectMedia -->|Yes| LoadManifest[Load Media Manifest] LoadManifest --> CheckType{Check Media Type} CheckType -->|Notion| StrategyCheck{Check Strategy} CheckType -->|External| PreserveCheck{Preserve URLs?} PreserveCheck -->|Yes| KeepURL[Keep Original URL] PreserveCheck -->|No| StrategyCheck StrategyCheck -->|Download| DownloadProcess[Download Media] StrategyCheck -->|Upload| UploadProcess[Upload to Storage] StrategyCheck -->|Direct| UseNotionURL[Use Notion URL] DownloadProcess --> UpdateManifest[Update Manifest] UploadProcess --> UpdateManifest UseNotionURL --> UpdateManifest KeepURL --> UpdateManifest UpdateManifest --> CleanupCheck{Need Cleanup?} CleanupCheck -->|Yes| RunCleanup[Remove Unused Files] CleanupCheck -->|No| UpdateBlock[Update Block URLs] RunCleanup --> UpdateBlock UpdateBlock --> End[Return Updated Block]Media Manifest System
The Media Handler maintains a manifest file for each page to track media assets and their relationships to blocks. The manifest helps with:
Manifest Structure
{ "block_456": { "lastEdited": "2024-01-02T15:00:00Z", "mediaPath": "/static/images/page-123/image2.jpg", "mediaType": "notion", "strategy": "download" } }Implementation Examples
1. Static Site Generator Implementation
2. Cloud Storage Implementation
3. Preview/Temporary Content Implementation
Beta Was this translation helpful? Give feedback.
All reactions