Skip to content

Commit 3aa1930

Browse files
authored
Merge pull request #16 from fxhash/dev
update prod
2 parents 75ef5b7 + 61e0ce2 commit 3aa1930

File tree

4 files changed

+274
-1475
lines changed

4 files changed

+274
-1475
lines changed

.github/workflows/build_lambda.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Create zip bundle
1919
run: |
2020
zip -r deploy.zip . -x "*yarn.lock*" -x "*.git*" -x "*.gitignore*" -x "*deploy.sh*" -x "*package-lock.json*"
21-
- uses: actions/upload-artifact@v3
21+
- uses: actions/upload-artifact@v4
2222
with:
2323
name: deploy-${{ github.sha }}
2424
path: deploy.zip
@@ -42,7 +42,7 @@ jobs:
4242
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_PRD }}
4343
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PRD }}
4444
aws-region: ${{ secrets.AWS_REGION }}
45-
- uses: actions/download-artifact@v3
45+
- uses: actions/download-artifact@v4
4646
with:
4747
name: deploy-${{ github.sha }}
4848
- name: "Upload dev deployment file"

index.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,34 @@ const extractFeatures = async page => {
299299
}
300300
}
301301

302+
let sharp = null
303+
const resizeCanvas = async (image, resX, resY) => {
304+
if (!sharp) sharp = require("sharp")
305+
const sharpImage = sharp(image)
306+
307+
/**
308+
* TODO: we should eventually get the canvas width/height from the page context
309+
* when running captureCanvas() - can bypass sharp if the image is small enough
310+
*/
311+
// get current image dimensions to check if resize is needed
312+
const metadata = await sharpImage.metadata()
313+
const currentWidth = metadata.width
314+
const currentHeight = metadata.height
315+
316+
// check if current resolution is already <= target resolution
317+
if (currentWidth <= resX && currentHeight <= resY) {
318+
// no resize needed, return original image
319+
return image
320+
}
321+
322+
return sharpImage.resize(resX, resY, { fit: "inside" }).toBuffer()
323+
}
302324
const performCapture = async (
303325
mode,
304326
page,
305327
canvasSelector,
328+
resX,
329+
resY,
306330
gif,
307331
frameCount,
308332
captureInterval,
@@ -318,14 +342,16 @@ const performCapture = async (
318342
// if the mode is canvas, we need to execute som JS on the client to select
319343
// the canvas and generate a dataURL to bridge it in here
320344
else if (mode === "CANVAS") {
321-
return captureCanvas(
345+
const canvas = await captureCanvas(
322346
page,
323347
canvasSelector,
324348
gif,
325349
frameCount,
326350
captureInterval,
327351
playbackFps
328352
)
353+
if (resX && resY) return resizeCanvas(canvas, resX, resY)
354+
return canvas
329355
}
330356
}
331357

@@ -647,6 +673,8 @@ exports.handler = async (event, context) => {
647673
mode,
648674
page,
649675
canvasSelector,
676+
resX,
677+
resY,
650678
gif,
651679
frameCount,
652680
captureInterval,

0 commit comments

Comments
 (0)