-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrouter.js
More file actions
77 lines (55 loc) · 2.16 KB
/
router.js
File metadata and controls
77 lines (55 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var express = require('express');
var router = express.Router();
var bodyParser = require("body-parser");
var urlencodedParser = bodyParser.urlencoded({
extended: false
});
var helper = require('./helper');
router.get('/', urlencodedParser, (req, res) => {
var visitorId = req.headers.visitorid;
// console.log(visitorId);
helper.getAllScraps().then(async (scraps) => {
var scraps = Object.keys(scraps).map((key) => {
return scraps[key];
})
await scraps.sort((a, b) => {
return new Date(b.createdAt) - new Date(a.createdAt);
});
await scraps.forEach(x => {
helper.decideAttachmentType(x).then((x) => {
helper.replaceURLWithHTMLLinks(x).then((x) => {
helper.generateLikeCountMessage(x, visitorId).then((x) => {
// console.log(x);
});
});
});
});
metadata = {
title: "Inovus Scrapbook",
description: "Inovus Scrapbook is an exclusive social network for Inovus Fellows for scrapbooking and sharing scrapbooking content. It's more like a daily diary for them to scribble about their self-learning endeavors & DIY projects",
image: "https://user-images.githubusercontent.com/44474792/182791904-7241eafc-c8a2-42c1-a0aa-c54b4de8bc16.png",
url: process.env.BASE_URL
}
res.render('home', { scraps, metadata });
})
});
router.get('/scrap/:id', (req, res) => {
helper.getScrapById(req.params.id).then((scrap) => {
helper.decideAttachmentType(scrap).then((scrap) => {
helper.generateScrapMetaData(scrap).then((metadata) => {
res.render('scrap', { scrap, metadata });
}).catch((err) => {
console.log(err);
})
}).catch((err) => {
console.log(err);
})
})
});
router.post('/scrap/:id/like', (req, res) => {
helper.postScrapLikesCounter(req.body).then(async (totalLikes) => {
res.json(totalLikes);
// console.log(totalLikes);
})
});
module.exports = router;