-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revamped logic for more secure barter system
- Loading branch information
1 parent
fa48eac
commit 2d73a9f
Showing
8 changed files
with
416 additions
and
667 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const proofsDir = path.join(__dirname, `../../debtor-proofs`); | ||
if (!fs.existsSync(proofsDir)) { | ||
fs.mkdirSync(proofsDir, { recursive: true }); | ||
} | ||
|
||
const storage = multer.diskStorage({ | ||
destination: function (req, file, cb) { | ||
cb(null, proofsDir); | ||
}, | ||
filename: function (req, res, file) { | ||
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1e9); | ||
cb(null, file.fieldname + '-' + uniqueSuffix + path.extname(file.originalname)); | ||
}, | ||
}); | ||
|
||
// setup multer | ||
|
||
const upload = multer({ | ||
storage: storage, | ||
limits: 10 * 1024 * 1024, | ||
fileFilter: function (req, res, cb) { | ||
const fileTypes = /jpg|jpeg|png|pdf/; | ||
const mimetype = fileTypes.test(file.mimetype); | ||
const extname = fileTypes.test(path.extname(file.originalname).toLocaleLowerCase()); | ||
|
||
if (mimetype && extname) { | ||
return cb(null, true); | ||
} else { | ||
cb(new Error('Only images and PDFs are allowed!')); | ||
} | ||
}, | ||
}); | ||
|
||
module.exports = upload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters