Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • add opengraph images for templates, blogs, and updated existing opengraph image for all other pages

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 19, 2025 2:48am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 19, 2025

Greptile Summary

This PR implements OpenGraph image generation for template pages to improve social media sharing. When users save templates, the system captures a workflow preview and uploads it as an OG image.

Key Changes:

  • Added html-to-image library to capture workflow previews as PNG images (1200x630)
  • Created OG capture infrastructure with retry logic, filtering, and validation
  • Added ogImageUrl column to templates table for storing pre-generated images
  • Implemented PUT/DELETE API endpoints at /api/templates/[id]/og-image with PNG validation
  • Extended storage configuration to support og-images context for S3/Azure Blob
  • Updated template page metadata to use custom OG images with fallback to logo
  • Modified homepage metadata to use logo instead of removed custom OG images

Implementation Notes:

  • OG capture happens asynchronously after template save, so users see success immediately
  • Hidden off-screen container renders workflow preview at exact OG dimensions
  • Uses double requestAnimationFrame to ensure DOM rendering before capture
  • Public file serving extended to include og-images context alongside profile-pictures

Confidence Score: 4/5

  • This PR is safe to merge with minor timing considerations around async capture
  • Implementation is solid with proper validation, authentication, and error handling. The async capture approach keeps UX smooth. Previous review comments about timing brittleness and race conditions have been acknowledged by the team as acceptable edge cases. PNG validation and storage integration follow established patterns.
  • Pay attention to apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/template/template.tsx for the async OG capture flow and timing assumptions

Important Files Changed

Filename Overview
apps/sim/lib/og/capture-preview.ts Core OG image capture logic using html-to-image library with retry mechanism, filtering, and upload functionality
apps/sim/app/api/templates/[id]/og-image/route.ts API endpoint for uploading/deleting template OG images with PNG validation and proper authentication
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/template/template.tsx Template deployment with async OG capture after save; uses hidden off-screen container with workflow preview
packages/db/schema.ts Added nullable ogImageUrl text column to templates table for storing pre-generated preview images
apps/sim/lib/uploads/config.ts Added og-images storage context with S3/Azure Blob configs that fallback to general storage config

Sequence Diagram

sequenceDiagram
    participant User
    participant DeployModal as Template Deploy Modal
    participant WorkflowStore as Workflow Store
    participant OGCapture as OG Capture Container
    participant CaptureLib as capture-preview.ts
    participant API as /api/templates/[id]/og-image
    participant Storage as Storage Service
    participant DB as Database

    User->>DeployModal: Save template
    DeployModal->>DB: Create/update template record
    DB-->>DeployModal: Template saved (templateId)
    
    Note over DeployModal: onDeploymentComplete() called immediately
    DeployModal->>User: Show success state
    
    par Async OG Image Capture
        DeployModal->>DeployModal: setIsCapturing(true)
        DeployModal->>DeployModal: requestAnimationFrame x2
        Note over DeployModal: Wait ~2 frames for DOM render
        
        DeployModal->>OGCapture: Render hidden container
        OGCapture->>WorkflowStore: Get workflow state (blocks, edges, loops)
        WorkflowStore-->>OGCapture: Current workflow state
        OGCapture->>OGCapture: Render WorkflowPreview off-screen
        
        DeployModal->>CaptureLib: captureWorkflowPreview(element)
        CaptureLib->>CaptureLib: html-to-image.toPng()
        Note over CaptureLib: Retry up to 3 times if needed
        CaptureLib-->>DeployModal: Base64 PNG data
        
        DeployModal->>CaptureLib: uploadOGImage(templateId, imageData)
        CaptureLib->>API: PUT /api/templates/{id}/og-image
        
        API->>API: Validate session & template ownership
        API->>API: Decode base64 & validate PNG magic bytes
        API->>API: Check file size < 5MB
        
        API->>Storage: uploadFile(buffer, og-images context)
        Storage-->>API: Upload result with path
        
        API->>DB: Update templates.ogImageUrl
        DB-->>API: Success
        
        API-->>CaptureLib: { ogImageUrl }
        CaptureLib-->>DeployModal: OG image URL
        
        DeployModal->>DeployModal: setIsCapturing(false)
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24 files reviewed, 5 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1 waleedlatif1 merged commit a2f14ca into staging Dec 19, 2025
11 checks passed
@waleedlatif1 waleedlatif1 deleted the feat/opengraph branch December 19, 2025 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants