diff options
| author | Adam Soltys <[email protected]> | 2024-10-31 09:29:04 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-10-31 09:34:42 -0700 |
| commit | aa4cd39c943b67169def224e224bd07b815b70ec (patch) | |
| tree | 2af857ac971705f4d20eb017864f0365d0b57ea6 /lib/upload.ts | |
| parent | bc9c04f6519f32d3b444d4df0b276eba960480a9 (diff) | |
| download | coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.tar.gz coinos-server-aa4cd39c943b67169def224e224bd07b815b70ec.zip | |
biome lint
Diffstat (limited to 'lib/upload.ts')
| -rw-r--r-- | lib/upload.ts | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/upload.ts b/lib/upload.ts index 2be55a35..bc358ede 100644 --- a/lib/upload.ts +++ b/lib/upload.ts @@ -8,24 +8,28 @@ const sharp = require("sharp"); export default async (req, res) => { try { - let { + const { params: { type }, } = req; - let data = await req.file(); + const data = await req.file(); let buf = await data.toBuffer(); - let [format, ext] = (await fileTypeFromBuffer(buf)).mime.split("/"); + const [format, ext] = (await fileTypeFromBuffer(buf)).mime.split("/"); if (format !== "image" && !["jpg", "jpeg", "png"].includes(ext)) fail("unsupported file type"); - let w = type === "banner" ? 1920 : 240; - buf = await sharp(buf, { failOnError: false }).rotate().resize(w).webp().toBuffer(); + const w = type === "banner" ? 1920 : 240; + buf = await sharp(buf, { failOnError: false }) + .rotate() + .resize(w) + .webp() + .toBuffer(); - let hash = createHash("sha256").update(buf).digest("hex"); + const hash = createHash("sha256").update(buf).digest("hex"); - let filePath = `/home/bun/app/data/uploads/${hash}.webp`; + const filePath = `/home/bun/app/data/uploads/${hash}.webp`; writeFileSync(filePath, buf); res.send({ hash }); |
