Changes to make previews download faster - scale them and refresh the

url in the json
This commit is contained in:
Kuba Orlik 2022-07-15 09:34:58 +02:00
parent beea325ebf
commit 012bf1056f
5 changed files with 12 additions and 6 deletions

View File

@ -49,6 +49,7 @@ RUN python3 -m pip install --upgrade Pillow
RUN apk add zip RUN apk add zip
RUN apk add xclip RUN apk add xclip
RUN apk add curl RUN apk add curl
RUN apk add vips
COPY . /opt COPY . /opt
CMD /opt/prepare-firefox.sh CMD /opt/prepare-firefox.sh

View File

@ -20,7 +20,7 @@ if [ "$PREVIEW" = "TRUE" ];
then then
(while true; do (while true; do
grab_screen_to_public $ID grab_screen_to_public $ID
sleep 1 sleep 0.7
done) & done) &
refresher_pid=$!; refresher_pid=$!;
fi fi

View File

@ -66,12 +66,17 @@ quicktype(){
grab_screen_to_public(){ grab_screen_to_public(){
id=$1 id=$1
filepath="/opt/static/$id/preview.png" format="jpg"
tempfile="/opt/static/$id/temp.png" 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" mkdir -p "/opt/static/$id"
rm -f "$tempfile" rm -f "$tempfile"
scrot "$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(){ keycombo(){

View File

@ -81,7 +81,7 @@ router.get("/", async (ctx) => {
do { do {
response = await (await fetch(\`/api/requests/\${id}\`)).json(); response = await (await fetch(\`/api/requests/\${id}\`)).json();
output.innerHTML = JSON.stringify(response, null, " ").replace( output.innerHTML = JSON.stringify(response, null, " ").replace(
/\\/(static|api)\\/.*(.png|all-screenshots)/g, /\\/(static|api)\\/.*(.png|all-screenshots|v=[0-9]+)/g,
'<a href="$&">$&</a>' '<a href="$&">$&</a>'
); );
stdout.innerHTML = response.output.replace( stdout.innerHTML = response.output.replace(

View File

@ -90,7 +90,7 @@ export default class ScreenshotRequest {
this.status === "finished" this.status === "finished"
? `/api/requests/${this.id}/all-screenshots` ? `/api/requests/${this.id}/all-screenshots`
: null, : null,
preview: `/static/${this.id}/preview.png`, preview: `/static/${this.id}/preview.jpg?v=${Date.now()}`,
}; };
} }