From 012bf1056ff3a2ba19826cd186d9c9242a5f657f Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Fri, 15 Jul 2022 09:34:58 +0200 Subject: [PATCH] Changes to make previews download faster - scale them and refresh the url in the json --- Docker/Dockerfile | 1 + Docker/run-analysis.sh | 2 +- Docker/utils.sh | 11 ++++++++--- src/index.ts | 2 +- src/request.ts | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Docker/Dockerfile b/Docker/Dockerfile index d4db82b..3c732e8 100644 --- a/Docker/Dockerfile +++ b/Docker/Dockerfile @@ -49,6 +49,7 @@ RUN python3 -m pip install --upgrade Pillow RUN apk add zip RUN apk add xclip RUN apk add curl +RUN apk add vips COPY . /opt CMD /opt/prepare-firefox.sh diff --git a/Docker/run-analysis.sh b/Docker/run-analysis.sh index eccc1ae..66ac252 100755 --- a/Docker/run-analysis.sh +++ b/Docker/run-analysis.sh @@ -20,7 +20,7 @@ if [ "$PREVIEW" = "TRUE" ]; then (while true; do grab_screen_to_public $ID - sleep 1 + sleep 0.7 done) & refresher_pid=$!; fi diff --git a/Docker/utils.sh b/Docker/utils.sh index 4041a98..b7023f7 100644 --- a/Docker/utils.sh +++ b/Docker/utils.sh @@ -66,12 +66,17 @@ quicktype(){ grab_screen_to_public(){ id=$1 - filepath="/opt/static/$id/preview.png" - tempfile="/opt/static/$id/temp.png" + format="jpg" + filepath="/opt/static/$id/preview.$format" + tempfile="/opt/static/$id/temp.$format" + croppedfile="/opt/static/$id/temp-cropped.$format" + scaledfile="/opt/static/$id/temp-cropped-scaled.$format" mkdir -p "/opt/static/$id" rm -f "$tempfile" scrot "$tempfile" - mv -f "$tempfile" "$filepath" + vips crop "$tempfile" "$croppedfile" 0 24 2856 1564 + vips resize "$croppedfile" "$scaledfile" 0.2 + mv -f "$scaledfile" "$filepath" } keycombo(){ diff --git a/src/index.ts b/src/index.ts index 0164eab..f8ddc7f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ router.get("/", async (ctx) => { do { response = await (await fetch(\`/api/requests/\${id}\`)).json(); output.innerHTML = JSON.stringify(response, null, " ").replace( - /\\/(static|api)\\/.*(.png|all-screenshots)/g, + /\\/(static|api)\\/.*(.png|all-screenshots|v=[0-9]+)/g, '$&' ); stdout.innerHTML = response.output.replace( diff --git a/src/request.ts b/src/request.ts index 523bbce..3a64d43 100644 --- a/src/request.ts +++ b/src/request.ts @@ -90,7 +90,7 @@ export default class ScreenshotRequest { this.status === "finished" ? `/api/requests/${this.id}/all-screenshots` : null, - preview: `/static/${this.id}/preview.png`, + preview: `/static/${this.id}/preview.jpg?v=${Date.now()}`, }; }