aboutsummaryrefslogtreecommitdiffstats
path: root/lib/upload.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-01 11:36:35 -0800
committerAdam Soltys <[email protected]>2023-12-01 11:36:35 -0800
commit7709c1efde9a1f3078171ee56985cd25511d6f7b (patch)
treecd996eaaa860cdb3d7da688e0ad4c5ec7bae1a0c /lib/upload.js
parent826c7b361c93905c4725755038d398221530051d (diff)
downloadcoinos-server-7709c1efde9a1f3078171ee56985cd25511d6f7b.tar.gz
coinos-server-7709c1efde9a1f3078171ee56985cd25511d6f7b.zip
biome formatter
Diffstat (limited to 'lib/upload.js')
-rw-r--r--lib/upload.js14
1 files changed, 4 insertions, 10 deletions
diff --git a/lib/upload.js b/lib/upload.js
index e07b9b1a..39c4a07f 100644
--- a/lib/upload.js
+++ b/lib/upload.js
@@ -14,7 +14,7 @@ async function getSha256Hash(stream) {
stream.pipe(hash);
let hashValue;
- hash.on("data", data => {
+ hash.on("data", (data) => {
hashValue = data.toString("hex");
});
@@ -42,16 +42,10 @@ export default async (req, res) => {
if (format !== "image" && !["jpg", "jpeg", "png"].includes(ext))
throw new Error("unsupported file type");
- let t = sharp()
- .rotate()
- .resize(width)
- .webp();
+ let t = sharp().rotate().resize(width).webp();
let processedBuffer = await streamToBuffer(s2.pipe(t));
- let hash = crypto
- .createHash("sha256")
- .update(processedBuffer)
- .digest("hex");
+ let hash = crypto.createHash("sha256").update(processedBuffer).digest("hex");
let filePath = `/app/data/uploads/${hash}.webp`;
fs.writeFileSync(filePath, processedBuffer);
@@ -62,7 +56,7 @@ export default async (req, res) => {
function streamToBuffer(stream) {
return new Promise((resolve, reject) => {
const chunks = [];
- stream.on("data", chunk => chunks.push(chunk));
+ stream.on("data", (chunk) => chunks.push(chunk));
stream.on("end", () => resolve(Buffer.concat(chunks)));
stream.on("error", reject);
});