MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / processOgImage

Function processOgImage

apps/api/src/controllers/misc.controller.ts:186–221  ·  view source on GitHub ↗
(
  buffer: Buffer,
  originalUrl?: string,
  contentType?: string,
)

Source from the content-addressed store, hash-verified

184
185// Process OG image with Sharp (resize to 300px width)
186async function processOgImage(
187 buffer: Buffer,
188 originalUrl?: string,
189 contentType?: string,
190): Promise<Buffer> {
191 // If buffer is small enough, return it as-is
192 if (buffer.length < 10000) {
193 logger.debug(
194 { originalUrl, bufferSize: buffer.length },
195 'Serving OG image directly without processing',
196 );
197 return buffer;
198 }
199
200 try {
201 // For OG images, process with Sharp to 300px width, maintaining aspect ratio
202 return await sharp(buffer)
203 .resize(300, null, {
204 fit: 'inside',
205 withoutEnlargement: true,
206 })
207 .png()
208 .toBuffer();
209 } catch (error) {
210 logger.warn(
211 {
212 err: error,
213 originalUrl,
214 bufferSize: buffer.length,
215 },
216 'Sharp failed to process OG image, trying fallback',
217 );
218
219 throw error;
220 }
221}
222
223// Check if URL is a direct image
224function isDirectImage(url: URL): boolean {

Callers 1

getOgImageFunction · 0.85

Calls 2

debugMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected