Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use s3 to storage images #4

Merged
merged 4 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ MESSAGE_FROM=''
BCC=''
RECEIVER=

TINAPTIC_WEB_URL=""

AWS_ID=""
AWS_SECRET=""

#Image storage
AZURE_STORAGE_CONNECTION_STRING=''
CONTAINER_NAME=""
IMAGES_BUCKET_NAME=""
126 changes: 126 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"aws-sdk": "^2.709.0",
"azure-storage": "^2.10.3",
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
Expand All @@ -33,6 +34,7 @@
"jwt-decode": "^2.2.0",
"mongoose": "^5.9.13",
"multer": "^1.4.2",
"multer-s3": "^2.9.0",
"newrelic": "^6.7.0",
"nodemailer": "^6.4.6",
"rand-token": "^1.0.1",
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/answer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ exports.create = (req, res) => {
.then(data => {
examProvider.updateExamAnswers(examId, data._id).then(
(data) => {
eventEmitter.emit("notify_teacher_new_exam", examId, answer);
if (data.notify) {
eventEmitter.emit("notify_teacher_new_exam", examId, answer);
}
res.send(data);
});
})
Expand Down
59 changes: 30 additions & 29 deletions src/controllers/image.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ const imageProvider = require('../providers/image.provider');

exports.create = (req, res) => {
try {
imageProvider.create(req.file, req.user.id).then((data) => {
if (!data) {
res.status(500).send({
message: 'Some error occurred while creating the Image.',
});
} else {
res.send({
uuid: data.filename,
});
}
const { key } = req.file;
res.send({
uuid: key,
});
} catch (e) {
res.status(500).send({
Expand All @@ -22,32 +15,40 @@ exports.create = (req, res) => {

exports.findOne = (req, res) => {
const blobName = req.params.id;
imageProvider.findOne(blobName, res).then(res => {
res.end();
}).catch(res => {
res.end();
});
imageProvider.findOne(blobName, res)
.then((object) => {
res.set("Content-Type", object.ContentType);
res.send(object.Body);
})
.catch(e => {
res.status(500).send({
message: e.message,
e: JSON.stringify(e),
});
});
};

exports.findAll = (req, res) => {

imageProvider.findAll().then(images => {

res.send(images);
});
imageProvider.findAll()
.then(images => {
res.send(images);
})
.catch(e => {
res.status(500).send({
message: e.message,
});
});
};

exports.delete = (req, res) => {
imageProvider.delete(req.params.id, (err) => {
if (err) {
imageProvider.delete(req.params.id)
.then(() => {
res.send();
})
.catch(err => {
res.status(500).send({
message:
err.message || 'Some error occurred while deleting the Image.',
err.message || "Some error occurred while deleting the Image.",
});
return;
}
res.send({});
});

});
};

4 changes: 4 additions & 0 deletions src/models/exam.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ module.exports = mongoose => {
notify: {
type: Boolean,
default: true
},
random: {
type: Boolean,
default: false
}
},
{ timestamps: true },
Expand Down
Loading