Skip to content

Commit

Permalink
fix: avoid concurrent webp converting (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-yechao authored Jul 24, 2023
1 parent db96c75 commit 58d29f4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.3 (July 24, 2023)

- fix: avoid concurrent webp converting

## 0.9.2 (July 24, 2023)

- fix: convert to webp using query params
Expand Down
11 changes: 10 additions & 1 deletion api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ app.use(cookieParser());
app.use(express.json({ limit: env.maxUploadSize }));
app.use(express.urlencoded({ extended: true, limit: env.maxUploadSize }));

// Tasks of converting webp
const webpTasks = {};

// Convert images to webp on the fly
// eslint-disable-next-line consistent-return
app.use('/uploads/:filename', (req, res, next) => {
Expand Down Expand Up @@ -54,7 +57,13 @@ app.use('/uploads/:filename', (req, res, next) => {
}

// do the convert
any2webp(srcPath, destPath)
webpTasks[destPath] ??= any2webp(srcPath, destPath).finally(() => {
setTimeout(() => {
delete webpTasks[destPath];
}, 1000);
});

webpTasks[destPath]
.then(() => {
logger.info(`Converted ${srcPath} to webp`);
res.sendFile(destPath, { maxAge: '356d', immutable: true });
Expand Down
2 changes: 1 addition & 1 deletion blocklet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: image-bin
version: 0.9.2
version: 0.9.3
title: Image Bin
description: Paste and share your images
keywords:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "image-bin",
"version": "0.9.2",
"version": "0.9.3",
"scripts": {
"dev": "blocklet dev",
"build": "vite build",
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.2
0.9.3

0 comments on commit 58d29f4

Please sign in to comment.