-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
371 lines (332 loc) · 10.7 KB
/
app.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const mongoose = require("mongoose");
const _ = require("lodash");
const multer = require('multer');
var fs = require('fs');
var path = require('path');
const {spawn} = require('child_process');
// const upload = multer({dest: __dirname + '/uploads/images'});
// const fileUpload = require('express-fileupload');
const methodOverride = require('method-override');
const homeStartingContent = "This is a collabarative site for developers and coders who often and obviously get stuck at a point during their development journey.This platform can help those who are seeking answers and those who are able to give correct answers."
const aboutContent = "Hac habitasse platea dictumst vestibulum rhoncus est pellentesque. Dictumst vestibulum rhoncus est pellentesque elit ullamcorper. Non diam phasellus vestibulum lorem sed. Platea dictumst quisque sagittis purus sit. Egestas sed sed risus pretium quam vulputate dignissim suspendisse. Mauris in aliquam sem fringilla. Semper risus in hendrerit gravida rutrum quisque non tellus orci. Amet massa vitae tortor condimentum lacinia quis vel eros. Enim ut tellus elementum sagittis vitae. Mauris ultrices eros in cursus turpis massa tincidunt dui.";
const contactContent = "Scelerisque eleifend donec pretium vulputate sapien. Rhoncus urna neque viverra justo nec ultrices. Arcu dui vivamus arcu felis bibendum. Consectetur adipiscing elit duis tristique. Risus viverra adipiscing at in tellus integer feugiat. Sapien nec sagittis aliquam malesuada bibendum arcu vitae. Consequat interdum varius sit amet mattis. Iaculis nunc sed augue lacus. Interdum posuere lorem ipsum dolor sit amet consectetur adipiscing elit. Pulvinar elementum integer enim neque. Ultrices gravida dictum fusce ut placerat orci nulla. Mauris in aliquam sem fringilla ut morbi tincidunt. Tortor posuere ac ut consequat semper viverra nam libero.";
const app = express();
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({extended: false}));
app.use(methodOverride('_method'));
app.use(express.static("public"));
// app.use(fileUpload());
mongoose.connect('mongodb+srv://admin-yash:[email protected]/LostFound', {useNewUrlParser: true, useUnifiedTopology: true});
const lostSchema = {
name: String,
email: String,
phone: String,
category: String,
props: String
}
const foundSchema = {
name: String,
email: String,
phone: String,
image:{
type: String,
default: 'placeholder.jpg',
},
category: String,
props: String
}
const Lost = mongoose.model("Lost", lostSchema);
const Found = mongoose.model("Found", foundSchema);
const Electronics = mongoose.model("Electronics", lostSchema);
const Vehicle = mongoose.model("Vehicle", lostSchema);
const Wallet = mongoose.model("Wallet", lostSchema);
const Briefcase = mongoose.model("Briefcase", lostSchema);
const Card = mongoose.model("Card", lostSchema);
const Other = mongoose.model("Other", lostSchema);
app.get("/", function(req, res){
res.render("carousel");
});
app.get("/lostForm", function(req, res){
res.render("lostForm");
});
app.get("/manual", function(req, res){
res.render("manual");
});
app.get("/lost", function(req, res){
Lost.find({}, function(err, lostItems){
res.render("lostItems", {personBuy: lostItems});
});
});
app.get("/found", function(req, res){
Found.find({}, function(err, foundItems){
res.render("foundItems", {personBuy: foundItems});
});
});
app.get("/foundForm", function(req, res){
res.render("foundForm");
});
app.get("/category", function(req, res){
res.render("category");
});
app.get("/electronics", function(req, res){
Electronics.find({}, function(err, electronics){
res.render("categoryDetail", {
item: electronics,
number: electronics.length,
name: "ELECTRONICS"
});
});
});
app.get("/vehicles", function(req, res){
Vehicle.find({}, function(err, vehicles){
res.render("categoryDetail", {
item: vehicles,
number: vehicles.length,
name: "VEHICLES"
});
});
});
app.get("/wallets", function(req, res){
Wallet.find({}, function(err, wallets){
res.render("categoryDetail", {
item: wallets,
number: wallets.length,
name: "WALLETS"
});
});
});
app.get("/briefcases", function(req, res){
Briefcase.find({}, function(err, briefcases){
res.render("categoryDetail", {
item: briefcases,
number: briefcases.length,
name: "BRIEFCASES"
});
});
});
app.get("/cards", function(req, res){
Card.find({}, function(err, cards){
res.render("categoryDetail", {
item: cards,
number: cards.length,
name: "CARDS"
});
});
});
app.get("/others", function(req, res){
Other.find({}, function(err, others){
res.render("categoryDetail", {
item: others,
number: others.length,
name: "OTHER PRODUCTS"
});
});
});
let num=0;
app.post("/lostForm", function(req, res){
const type = req.body.category;
const lostItem = new Lost({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
Found.find({}, function(err, foundItems){
const proc= spawn('python', ['NLTK similarity.py',"red wallet", 'redmi note6']);
proc.stdout.on("data", (data) => {
num = parseFloat(data.toString());
console.log(data.toString());
});
//console.log(pyProg);
});
lostItem.save(function(err){
if(!err){
console.log("success");
}
});
if(type == "electronics"){
const electronics = new Electronics({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
electronics.save(function(err){
if(!err){
console.log("success");
}
})
} else if(type == "vehicles"){
const vehicle = new Vehicle({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
vehicle.save(function(err){
if(!err){
console.log(Vehicle);
}
})
} else if(type == "wallets"){
const wallet = new Wallet({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
wallet.save(function(err){
if(!err){
console.log(Wallet);
}
})
} else if(type == "briefcases"){
const briefcase = new Briefcase({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
briefcase.save(function(err){
if(!err){
console.log(Briefcase);
}
})
} else if(type == "cards"){
const card = new Card({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
card.save(function(err){
if(!err){
console.log(Card);
}
})
} else {
const other = new Other({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
category: req.body.category,
props: req.body.props
});
other.save(function(err){
if(!err){
console.log(Other);
}
})
}
res.redirect("/");
});
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, './uploads/images')
},
filename: (req, file, cb) => {
cb(null, Date.now()+ file.originalname);
}
});
// var upload = multer({ dest: 'uploads/' })
const upload = multer({ storage: storage ,
limits: { fieldSize: 10 * 1024 * 1024 }
});
app.post("/foundForm",upload.single("profile"),function(req, res){
console.log(req.file);
const found = new Found({
name: req.body.personName,
email: req.body.PersonEmail,
phone: req.body.personPhone,
image:req.file.filename,
category: req.body.category,
props: req.body.props
});
try {
found.save();
res.redirect("/");
} catch (error) {
console.log(error);
}
});
app.post("/search", function(req, res){
const requestedItem = _.lowerCase(req.body.search);
let x = 0;
let string = "";
let count = 0;
Lost.find({}, function(err, lostItems){
lostItems.forEach(function(item){
const storedTitle = _.lowerCase(item.category);
if (storedTitle === requestedItem) {
if(storedTitle === "electronics"){
Electronics.find({}, function(err, electronics){
res.render("categoryDetail", {
name: "ELECTRONICS",
number: electronics.length
});
})
} else if(storedTitle === "vehicles") {
Vehicle.find({}, function(err, vehicles){
res.render("categoryDetail", {
name: "VEHICLES",
number: vehicles.length
});
})
} else if(storedTitle === "wallets") {
Wallet.find({}, function(err, wallets){
res.render("categoryDetail", {
name: "WALLETS",
number: wallets.length
});
})
} else if(storedTitle === "briefcases") {
Briefcase.find({}, function(err, briefcases){
res.render("categoryDetail", {
name: "BRIEFCASES",
number: briefcases.length
});
})
} else if(storedTitle === "cards") {
Card.find({}, function(err, cards){
res.render("categoryDetail", {
name: "CARDS",
number: cards.length
});
})
} else {
Other.find({}, function(err, others){
res.render("categoryDetail", {
name: "OTHER PRODUCTS",
number: others.length
});
})
}
x=1;
}
});
if(x==0) {
Other.find({}, function(err, others){
res.render("categoryDetail", {
name: "OTHER PRODUCTS",
number: others.length
});
});
}
});
});
let port = process.env.PORT;
if (port == null || port == "") {
port = 3000;
}
app.listen(port, function() {
console.log("Server has started successfully");
});