-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cfedf51
commit 1ce4adb
Showing
16 changed files
with
809 additions
and
429 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
const api = require('../../utils/api.js'); | ||
const auth = require('../../utils/authenticate'); | ||
const logger = require('../../utils/logging'); | ||
|
||
const bodyParser = require('body-parser'); | ||
const multer = require('multer'); | ||
const fs = require('fs'); | ||
|
||
const storage = multer.diskStorage({ | ||
destination: function (req, file, cb) { | ||
const dir = './src/dist/uploads'; | ||
if (!fs.existsSync(dir)){ | ||
fs.mkdirSync(dir); | ||
} | ||
cb(null, dir); | ||
}, | ||
filename: function (req, file, cb) { | ||
cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname)) | ||
} | ||
}); | ||
|
||
const upload = multer({ storage: storage }); | ||
const path = require('path'); | ||
|
||
module.exports = (app) => { | ||
app.use(bodyParser.json()); | ||
app.options('/v1/uploadImage', auth.cors); | ||
|
||
app.put('/v1/uploadImage', auth.cors, upload.single('image'), async (req, res) => { | ||
logger.verbose('image upload handler starts'); | ||
|
||
try { | ||
const body = { | ||
url: `http://127.0.0.1:3000/uploads/${req.file.filename}` | ||
} | ||
return api.sendCreated(res, api.createResponse(body)); | ||
|
||
} catch (err) { | ||
logger.error('Request failed', err); | ||
return api.sendInternalError(res, api.createError('Failed to upload image', 'sign-in.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
Oops, something went wrong.