Skip to content

Commit 419347c

Browse files
authored
Merge pull request #171 from TG1999/development
Functionality to add image in a post
2 parents 17d4fff + 6b122ce commit 419347c

File tree

13 files changed

+37
-9
lines changed

13 files changed

+37
-9
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ typings/
7979

8080
# Config files
8181
credential.js
82-
secret.js
82+
secret.js
83+
84+
views/images/uploads

controller/profile.controller.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ const user = require('../schema/user.js');
22
const proj = require('../schema/project.js');
33
const expressValidator = require('express-validator');
44
const { check, validationResult } = require('express-validator/check');
5-
5+
// var multer = require('multer');
6+
// var storage = multer.diskStorage({
7+
// destination: (req, file, cb) => {
8+
// cb(null, 'public/images/uploads')
9+
// },
10+
// filename: (req, file, cb) => {
11+
// cb(null, file.fieldname + '-' + Date.now())
12+
// }
13+
// });
14+
// var upload = multer({storage: storage});
615
module.exports = {
716
SubmitprojectForm:function(req,res){
817
res.render('projectForm')
@@ -35,6 +44,7 @@ module.exports = {
3544
]).sort({createdAt:-1}).then((da)=>{
3645
console.log(req.user);
3746
user.findOne({ Eid: req.params.sd }).then(function (use) {
47+
console.log(da)
3848
res.render('other-landing', { use: use, ques: da, sign: req.user});
3949
})
4050
})
@@ -62,7 +72,8 @@ module.exports = {
6272
content: req.body.cont,
6373
upvote: '',
6474
downvote: '',
65-
proid: Math.floor(Math.random() * 100000)
75+
proid: Math.floor(Math.random() * 100000),
76+
image:'/images/uploads/'+req.file.filename
6677
})
6778
.save()
6879
.then(function() {

routes/profile.routes.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ const auth = function(req, res, next) {
1313
next();
1414
}
1515
};
16-
16+
var multer = require('multer');
17+
var storage = multer.diskStorage({
18+
destination: (req, file, cb) => {
19+
cb(null, 'views/images/uploads')
20+
},
21+
filename: (req, file, cb) => {
22+
cb(null, file.fieldname + '-' + Date.now())
23+
}
24+
});
25+
var upload = multer({storage: storage});
1726
route.get('/submitProject',auth,profileController.SubmitprojectForm)
1827
route.get('/search', url, jsonParser, profileController.search);
1928

@@ -23,7 +32,7 @@ route.get('/profile/:id', auth, profileController.profileId);
2332

2433
route.get('/profileview/:sd', auth, url, profileController.profileViewSd);
2534

26-
route.post('/publish', auth, url, profileController.publish);
35+
route.post('/publish', auth, url,upload.single('image'), profileController.publish);
2736

2837
route.post('/upDownVote', auth,url, jsonParser,profileController.upDownVote);
2938

schema/project.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ createdAt:{
4141
endAt:{
4242
type:Date
4343
},
44-
44+
image:{
45+
type:String
46+
}
4547
});
4648

4749
const proj=mongoose.model('project',project);

views/.DS_Store

8 KB
Binary file not shown.
26.4 KB
Binary file not shown.
26.4 KB
Binary file not shown.
24.2 KB
Binary file not shown.

views/main-landing.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
<a class="nav-link" href="#">User Name</a>
5555
</li>
5656
<li class="nav-item flex-center">
57-
<a class="nav-link" href="">Logout</a>
57+
<a class="nav-link" href="/auth/logout">Logout</a>
5858
</li>
5959
<!-- Dropdown -->
6060
<li class="nav-item flex-center dropdown">

0 commit comments

Comments
 (0)