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

Function processImage

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

Source from the content-addressed store, hash-verified

130
131// Process image with Sharp (resize to 30x30 PNG)
132async function processImage(
133 buffer: Buffer,
134 originalUrl?: string,
135 contentType?: string,
136): Promise<Buffer> {
137 // If it's an ICO file, just return it as-is (no conversion needed)
138 if (originalUrl && isIcoFile(originalUrl, contentType)) {
139 logger.debug(
140 { originalUrl, bufferSize: buffer.length },
141 'Serving ICO file directly',
142 );
143 return buffer;
144 }
145
146 if (originalUrl && isSvgFile(originalUrl, contentType)) {
147 logger.debug(
148 { originalUrl, bufferSize: buffer.length },
149 'Serving SVG file directly',
150 );
151 return buffer;
152 }
153
154 // If buffer isnt to big just return it as well
155 if (buffer.length < 5000) {
156 logger.debug(
157 { originalUrl, bufferSize: buffer.length },
158 'Serving image directly without processing',
159 );
160 return buffer;
161 }
162
163 try {
164 // For other formats, process with Sharp
165 return await sharp(buffer)
166 .resize(30, 30, {
167 fit: 'cover',
168 })
169 .png()
170 .toBuffer();
171 } catch (error) {
172 logger.warn(
173 {
174 err: error,
175 originalUrl,
176 bufferSize: buffer.length,
177 },
178 'Sharp failed to process image, trying fallback',
179 );
180
181 throw error;
182 }
183}
184
185// Process OG image with Sharp (resize to 300px width)
186async function processOgImage(

Callers 1

getFaviconFunction · 0.85

Calls 4

isIcoFileFunction · 0.85
isSvgFileFunction · 0.85
debugMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected