Spaces:
Sleeping
Sleeping
Update lib/converter.js
Browse files- lib/converter.js +14 -14
lib/converter.js
CHANGED
@@ -2,23 +2,23 @@ import sharp from "sharp";
|
|
2 |
import fetch from "node-fetch";
|
3 |
|
4 |
async function convertWebpToPng(input) {
|
5 |
-
return new
|
6 |
try {
|
7 |
-
if(typeof input
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
} else if(typeof input
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
}
|
18 |
-
} catch(e) {
|
19 |
reject(e.message);
|
20 |
}
|
21 |
-
})
|
22 |
}
|
23 |
|
24 |
-
export { convertWebpToPng }
|
|
|
2 |
import fetch from "node-fetch";
|
3 |
|
4 |
async function convertWebpToPng(input) {
|
5 |
+
return new Promise((resolve, reject) => {
|
6 |
try {
|
7 |
+
if (typeof input === "string") {
|
8 |
+
const response = await fetch(input);
|
9 |
+
const images = await response.buffer();
|
10 |
+
const converting = await sharp(images);
|
11 |
+
const converted = converting.toFormat('png').png({ quality: 90 }).toBuffer();
|
12 |
+
resolve(converted);
|
13 |
+
} else if (typeof input === "object") {
|
14 |
+
const converting = await sharp(input);
|
15 |
+
const converted = converting.toFormat('png').png({ quality: 90 }).toBuffer();
|
16 |
+
resolve(converted);
|
17 |
}
|
18 |
+
} catch (e) {
|
19 |
reject(e.message);
|
20 |
}
|
21 |
+
});
|
22 |
}
|
23 |
|
24 |
+
export { convertWebpToPng };
|