Skip to content

Commit 5a3f9ad

Browse files
committed
ack PR comments
1 parent c1a5c2c commit 5a3f9ad

File tree

3 files changed

+28
-12
lines changed
  • apps/sim
    • app
      • api/templates/[id]/og-image
      • workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/template
    • lib/uploads/utils

3 files changed

+28
-12
lines changed

apps/sim/app/api/templates/[id]/og-image/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { generateRequestId } from '@/lib/core/utils/request'
77
import { getBaseUrl } from '@/lib/core/utils/urls'
88
import { createLogger } from '@/lib/logs/console/logger'
99
import { uploadFile } from '@/lib/uploads/core/storage-service'
10+
import { isValidPng } from '@/lib/uploads/utils/validation'
1011

1112
const logger = createLogger('TemplateOGImageAPI')
1213

@@ -50,6 +51,10 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<{
5051
const base64Data = imageData.includes(',') ? imageData.split(',')[1] : imageData
5152
const imageBuffer = Buffer.from(base64Data, 'base64')
5253

54+
if (!isValidPng(imageBuffer)) {
55+
return NextResponse.json({ error: 'Invalid PNG image data' }, { status: 400 })
56+
}
57+
5358
const maxSize = 5 * 1024 * 1024
5459
if (imageBuffer.length > maxSize) {
5560
return NextResponse.json({ error: 'Image too large. Maximum size is 5MB.' }, { status: 400 })

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/deploy/components/deploy-modal/components/template/template.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,22 @@ export function TemplateDeploy({
232232
logger.info(`Template ${existingTemplate ? 'updated' : 'created'} successfully`)
233233

234234
setIsCapturing(true)
235-
setTimeout(async () => {
236-
try {
237-
if (ogCaptureRef.current) {
238-
const ogUrl = await captureAndUploadOGImage(ogCaptureRef.current, templateId)
239-
if (ogUrl) {
240-
logger.info(`OG image uploaded for template ${templateId}: ${ogUrl}`)
235+
requestAnimationFrame(() => {
236+
requestAnimationFrame(async () => {
237+
try {
238+
if (ogCaptureRef.current) {
239+
const ogUrl = await captureAndUploadOGImage(ogCaptureRef.current, templateId)
240+
if (ogUrl) {
241+
logger.info(`OG image uploaded for template ${templateId}: ${ogUrl}`)
242+
}
241243
}
244+
} catch (ogError) {
245+
logger.warn('Failed to capture/upload OG image:', ogError)
246+
} finally {
247+
setIsCapturing(false)
242248
}
243-
} catch (ogError) {
244-
logger.warn('Failed to capture/upload OG image:', ogError)
245-
} finally {
246-
setIsCapturing(false)
247-
}
248-
}, 100)
249+
})
250+
})
249251

250252
onDeploymentComplete?.()
251253
} catch (error) {

apps/sim/lib/uploads/utils/validation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ export function isSupportedVideoExtension(extension: string): extension is Suppo
192192
/**
193193
* Validate if an audio/video file type is supported for STT processing
194194
*/
195+
const PNG_MAGIC_BYTES = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
196+
197+
/**
198+
* Validate that a buffer contains valid PNG data by checking magic bytes
199+
*/
200+
export function isValidPng(buffer: Buffer): boolean {
201+
return buffer.length >= 8 && buffer.subarray(0, 8).equals(PNG_MAGIC_BYTES)
202+
}
203+
195204
export function validateMediaFileType(
196205
fileName: string,
197206
mimeType: string

0 commit comments

Comments
 (0)