Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bskyogcard/src/components/Img.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'

// @NOTE satori does not currently support webp, see vercel/satori#273
function detectMime(buf: Buffer): string {
if (buf[0] === 0xff && buf[1] === 0xd8) return 'image/jpeg'
if (buf[0] === 0x89 && buf[1] === 0x50) return 'image/png'
Expand Down
14 changes: 10 additions & 4 deletions bskyogcard/src/routes/starter-pack.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import assert from 'node:assert'

import React from 'react'
import {AppBskyGraphDefs, AtUri} from '@atproto/api'
import {type AppBskyGraphDefs, AtUri} from '@atproto/api'
import resvg from '@resvg/resvg-js'
import {Express} from 'express'
import {type Express} from 'express'
import satori from 'satori'

import {
StarterPack,
STARTERPACK_HEIGHT,
STARTERPACK_WIDTH,
} from '../components/StarterPack.js'
import {AppContext} from '../context.js'
import {type AppContext} from '../context.js'
import {httpLogger} from '../logger.js'
import {loadEmojiAsSvg} from '../util.js'
import {handler, originVerifyMiddleware} from './util.js'
Expand Down Expand Up @@ -83,12 +83,18 @@ export default function (ctx: AppContext, app: Express) {
}

async function getImage(url: string) {
const response = await fetch(url)
const response = await fetch(ensureJpeg(url))
const arrayBuf = await response.arrayBuffer() // must drain body even if it will be discarded
if (response.status !== 200) return null
return Buffer.from(arrayBuf)
}

// CDN URLs end with @jpeg, @webp, or no extension (which may default to webp).
// We want to ensure the image URLs we use are for jpegs, required for compat with satori.
function ensureJpeg(url: string) {
return url.replace(/(@[a-z]{3,5})?$/, '@jpeg')
}

const hideAvatarLabels = new Set([
'!hide',
'!warn',
Expand Down
Loading