diff options
| author | Adam Soltys <[email protected]> | 2022-09-02 07:16:59 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2022-09-02 07:17:01 -0700 |
| commit | 4ce441443b13e3cece375595f764f10e7ac0564a (patch) | |
| tree | cf853807fafc13d7b15788f8e5781ce5fb7fbe93 /lib | |
| parent | 3bb9af967d972617179d666060c4f50180199bf9 (diff) | |
| download | coinos-server-4ce441443b13e3cece375595f764f10e7ac0564a.tar.gz coinos-server-4ce441443b13e3cece375595f764f10e7ac0564a.zip | |
refactor upload endpoint
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/upload.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/upload.js b/lib/upload.js new file mode 100644 index 00000000..452bf5c9 --- /dev/null +++ b/lib/upload.js @@ -0,0 +1,33 @@ +const multer = require("multer"); + +const storage = multer.diskStorage({ + destination: (req, file, cb) => { + cb(null, "uploads"); + }, + filename: async (req, file, cb) => { + const parts = file.originalname.split("."); + const ext = parts.length > 1 ? parts[parts.length - 1] : "bin"; + cb(null, `${req.user.username}-${file.fieldname}.${ext}`); + } +}); + +upload = multer({ + storage, + onFileUploadStart: (file, req, res) => { + console.log("CHECKING SIZE") + const maxSize = 32 * 1000 * 1000; + if (req.files.file.length > maxSize) { + return false; + } + } +}); + +app.post( + "/profile", + auth, + upload.single("squirt"), + ah(async (req, res) => { + let { filename } = req.file; + res.send({ filename }); + }) +); |
