-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
155 lines (132 loc) · 5 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
var config = require('./config');
var createError = require('http-errors');
var express = require('express');
var path = require('path');
const bodyParser = require('body-parser');
var logger = require('morgan');
const mongoose = require('mongoose');
const GoogleMeet = require('./google-meet');
const MeetSchedule = require('./Model/meetSchedule');
mongoose.Promise = require('bluebird');
const connect = mongoose.connect(config.MONGO_SRV, {
useMongoClient: true,
/* other options */
});
var app = express();
app.disable('etag');
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(express.json());
app.use(bodyParser.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public'), { index: ["index.html", "index.htm"] }));
app.get('/list', (req, res) => {
MeetSchedule.find({}).then(meetSchedule => {
res.json({ "meetSchedule": meetSchedule })
})
});
app.post('/postlink', (req, res) => {
MeetSchedule.create(req.body)
.then(url => {
app.get('/', (req, res) => {
res.render('index', { url, email, password })
});
app.post('/postlink', (req, res) => {
MeetSchedule.create(req.body)
.then(meetSchedule => {
if (meetSchedule) {
res.statusCode = 200;
} else {
res.statusCode = 500;
}
}).catch((err) => {
console.log("Couldn't create a new URl instance");
console.log(err);
})
res.redirect("/");
});
}).catch((err) => {
console.log("Couldn't create a new URl instance");
console.log(err);
});
});
app.get('/Cancel/:ScheduleID', (req, res, next) => {
MeetSchedule.findById(req.params.ScheduleID).then(meetSchedule => {
if (meetSchedule.joined == true) {
meetSchedule.endTime = Date.now();
meetSchedule.save();
}
else {
console.log("TRYING TO CANCEL: " + req.params.ScheduleID);
MeetSchedule.findByIdAndRemove(req.params.ScheduleID).then((resp) => {
res.statusCode = 200;
}, (err) => next(err))
.catch((err) => next(err));
}
})
})
app.use(function (req, res, next) {
next(createError(404));
});
app.use(function (err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
const port = 3000;
// Values
let email = config.EMAIL;
let password = config.PASSWORD;
let head = config.head;
let strict = config.strict;
obj = new GoogleMeet(email, password, head, strict);
connect.then(() => {
console.log("Connected correctly to server");
let isRunning = false;
setInterval(() => {
if (isRunning) {
console.log("Sad")
} else {
isRunning = true;
console.log("Checking After 5 Sec")
MeetSchedule.find({}).then(meetSchedule => {
let flag = true;
console.log(meetSchedule);
for (let i = 0; i < meetSchedule.length; i++) {
if (meetSchedule[i].joined !== true) {
console.log("Aint Joined this " + i)
if (meetSchedule[i].startTime < Date.now()) {
console.log(`Request for joining meet ${meetSchedule[i].meetLink}`);
flag = false;
obj.schedule(meetSchedule[i].meetLink);
MeetSchedule.findOneAndUpdate({ _id: meetSchedule[i]._id }, { $set: { joined: true } }, { new: true }).then(meetSchedule => {
console.log("Updated in DB");
isRunning = false;
});
}
} else {
console.log(" Joined " + i)
if (meetSchedule[i].endTime < Date.now()) {
console.log(`Request for leaving meet ${meetSchedule[i].meetLink}`);
flag = false;
obj.end();
MeetSchedule.deleteOne({ _id: meetSchedule[i]._id }).then(err => {
console.log("Deleted From DB")
isRunning = false;
})
}
}
}
if (flag)
isRunning = false;
});
}
}, 5000)
app.listen(port, () => {
console.log("SERVER CONNECTED at port " + port);
});
}, (err) => { console.log(err); });