All files / web/src/lib/song-share renderPreviewCover.tsx

0% Statements 0/25
0% Branches 0/1
0% Functions 0/1
0% Lines 0/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                                   
/**
 * Renders the still cover frame for a shared song's preview MP4 as PNG bytes.
 *
 * Wraps the shared `SongPreviewArtwork` JSX in `next/og`'s `ImageResponse`,
 * consumes its body as an ArrayBuffer, and returns a Node Buffer that the
 * ffmpeg pipeline (`buildPreviewVideo`) feeds as a still-image input.
 *
 * Same visual as the OG link-unfurl PNG by design — the iMessage preview's
 * video track is just the unfurl artwork held for the duration of the audio.
 */

import { ImageResponse } from 'next/og'
import type { SharedSongPayload } from './getSharedSong'
import { SONG_PREVIEW_SIZE, SongPreviewArtwork } from './SongPreviewArtwork'
import { getOgFontConfig } from './ogFont'

export async function renderPreviewCover(payload: SharedSongPayload | null): Promise<Buffer> {
  const { fonts, displayFont } = await getOgFontConfig()
  const response = new ImageResponse(
    <SongPreviewArtwork payload={payload} displayFont={displayFont} />,
    { ...SONG_PREVIEW_SIZE, fonts }
  )
  const arrayBuffer = await response.arrayBuffer()
  return Buffer.from(arrayBuffer)
}