-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
994 lines (952 loc) · 23.9 KB
/
main.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
/*
name: Server-Side of Virus Notificator
author: TonyHe
link: https://www.ouorz.com
last Update: 6-2-2020
*/
const express = require("express");
const request = require("request");
const mongo = require("mongodb").MongoClient;
const nodemailer = require("nodemailer");
const schedule = require("node-schedule");
const bodyParser = require("body-parser");
const Feed = require("feed").Feed;
const mailFunc = require("./mail");
var databaseUrl = process.env.MONGODB_URL;
//新建 Express 实例
var app = express();
//处理 POST 请求
app.use(
bodyParser.urlencoded({
extended: false,
})
);
//控制台输出模板
var consoleMessage = function (title, type) {
switch (type) {
case "start":
var sendDate = new Date();
console.log("\n");
console.log(
"-----------" + sendDate.toLocaleTimeString() + "-----------"
);
console.log("----------" + title + "-----------");
console.log("\n");
break;
case "end":
var sendDate = new Date();
console.log("\n");
console.log(
"-----------" + sendDate.toLocaleTimeString() + "-----------"
);
console.log("----------" + title + "-----------");
console.log("\n");
break;
}
};
/*
name: 取得 PHP 爬取数据
*/
consoleMessage("开始请求最新数据", "start");
request("https://files.snapaper.com/virus", function (error, response, data) {
if (!error && response.statusCode == 200) {
global.dataObject = JSON.parse(data.toString()); //获取
global.requestStatus = true;
console.log("数据请求成功");
global.feedData = getFeed();
} else {
global.requestStatus = false;
console.log("数据请求失败");
}
consoleMessage("结束请求最新数据", "end");
});
var getFeed = function () {
/* RSS Feed 生成 */
const feed = new Feed({
title: "COVID-19 疫情数据",
description: "COVID-19 疫情数据实时更新推送",
id: "https://virus-notificator-vue.onrender.com/",
link: "https://virus-notificator-vue.onrender.com/",
image: "https://i.loli.net/2020/02/05/b3adxQsVHX6voY4.jpg",
favicon: "https://virus-notificator-vue.onrender.com/favicon.ico",
copyright: "All rights reserved 2019, TonyHe",
feedLinks: {
json: "https://node.ouorz.com/json",
atom: "https://node.ouorz.com/atom",
},
author: {
name: "TonyHe",
email: "[email protected]",
link: "https://www.ouorz.com",
},
});
feed.addItem({
title: "全国数据",
id: "全国数据",
link: "https://node.ouorz.com/api/all",
description: "全国数据",
author: [
{
name: "TonyHe",
email: "[email protected]",
link: "https://www.ouorz.com",
},
],
contributor: [
{
name: "丁香园·丁香医生",
email: "[email protected]",
link: "https://ncov.dxy.cn/ncovh5/view/pneumonia",
},
],
date: new Date(),
image: "https://i.loli.net/2020/02/05/b3adxQsVHX6voY4.jpg",
content:
`<h3>全国数据</h3>
<ul>
<li>确诊:` +
global.dataObject.total_confirmed +
`</li>
<li>死亡:` +
global.dataObject.total_death +
`</li>
<li>治愈:` +
global.dataObject.total_cured +
`</li>
</ul>`,
});
//添加省份
Object.values(global.dataObject.provinces_data).forEach((pro) => {
global.feedProvinceCities = ""; //城市数据,加入到省份内容中
//添加城市
Object.values(pro.citiesName).forEach((city) => {
global.feedProvinceCities +=
`<h3>` +
city +
`数据</h3>
<ul>
<li>确诊:` +
global.dataObject.cities_data[city].confirmed +
`</li>
<li>死亡:` +
global.dataObject.cities_data[city].death +
`</li>
<li>治愈:` +
global.dataObject.cities_data[city].cured +
`</li>
</ul>`;
});
feed.addItem({
title: pro.provinceName + "数据",
id: pro.provinceName + "数据",
link: "https://node.ouorz.com/api/all",
description: pro.provinceName + "数据",
author: [
{
name: "TonyHe",
email: "[email protected]",
link: "https://www.ouorz.com",
},
],
contributor: [
{
name: "丁香园·丁香医生",
email: "[email protected]",
link: "https://ncov.dxy.cn/ncovh5/view/pneumonia",
},
],
date: new Date(),
image: "https://i.loli.net/2020/02/05/b3adxQsVHX6voY4.jpg",
content:
`<h3>` +
pro.provinceName +
`数据</h3>
<ul>
<li>总确诊:` +
pro.confirmed +
`</li>
<li>总死亡:` +
pro.death +
`</li>
<li>总治愈:` +
pro.cured +
`</li>
</ul>` +
global.feedProvinceCities,
});
});
feed.addCategory("Data");
feed.addContributor({
name: "丁香园·丁香医生",
email: "[email protected]",
link: "https://ncov.dxy.cn/ncovh5/view/pneumonia",
});
/* RSS Feed 生成 */
return feed;
};
/* RSS Feed 路由 */
app.get("/rss", function (req, res) {
res.set("Content-Type", "text/xml");
res.send(global.feedData.rss2());
});
/* RSS Feed 路由 */
/*
name: 跨域允许设置
*/
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Cache-Control", "No-store");
next();
});
/* 数据获取及 API Section */
/*
name: 全部数据获取
route: /api/all
*/
app.get("/api/all", function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
if (global.requestStatus) {
returnArray.code = 103;
returnArray.data = global.dataObject;
returnArray.status = true;
res.json(returnArray);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "Service is Unavailable";
res.json(returnArray);
}
});
/*
name: 省份数据获取
route: /api/province/:province
*/
app.get("/api/province/:province", function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
//获取请求参数
const params = req.params;
//建立参数对象
var paramsObject = {
province: "四川",
};
//保存参数
paramsObject.province = req.params.province;
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
if (global.requestStatus) {
returnArray.data = global.dataObject.provinces_data[paramsObject.province];
returnArray.code = 101;
returnArray.status = true;
res.json(returnArray);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "Service is Unavailable";
res.json(returnArray);
}
});
/*
name: 城市数据获取
route: /api/city/:city
*/
app.get("/api/city/:city", function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
//获取请求参数
const params = req.params;
//建立参数对象
var paramsObject = {
city: "成都",
};
//保存参数
paramsObject.city = req.params.city;
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
if (global.requestStatus) {
returnArray.data = global.dataObject.cities_data[paramsObject.city];
returnArray.code = 102;
returnArray.status = true;
res.json(returnArray);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "Service is Unavailable";
res.json(returnArray);
}
});
/* 数据获取及 API Section */
/* 用户订阅 Section */
/*
name: 邮件发送模板
*/
var sendEmail = function (titleContent, textContent, htmlContent, receiver) {
consoleMessage("准备开始发送欢迎邮件", "start");
let mailer = nodemailer.createTransport({
host: "smtp.163.com",
port: 465,
secure: true,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
});
let message = {
from: process.env.SMTP_USER,
to: receiver,
subject: titleContent,
text: textContent,
html: htmlContent,
};
mailer.sendMail(message, function (err, msg) {
if (err) {
console.log(err);
} else {
console.log("已接收到邮件: " + msg.accepted);
consoleMessage("发送欢迎邮件任务结束", "end");
}
});
};
/*
name: 邮箱或短信订阅
route: /subscribe/mail
params: email
*/
app.post("/subscribe/mail", function (req, res) {
res.header(
"Access-Control-Allow-Origin",
"https://virus-notificator-vue.onrender.com"
);
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
//获取请求参数
const params = req.body;
//建立参数对象
var paramsObject = {
email: "[email protected]",
};
//电子邮件地址验证
var emailTest =
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (emailTest.test(params.email)) {
//保存参数
paramsObject.email = params.email;
if (global.requestStatus) {
//连接 MongoDB 数据库
mongo.connect(
databaseUrl,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
function (err, db) {
if (err) {
console.log(err);
return;
} else {
var coll = db.db("notificator");
//数据查重
coll
.collection("mail_users")
.find({
email: paramsObject.email,
})
.toArray(function (err, result) {
if (err) {
console.log(err);
} else {
if (result.length) {
console.log("有重复数据");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 106;
returnArray.msg = "邮箱地址已订阅";
returnArray.status = false;
res.json(returnArray);
db.close();
} else {
coll
.collection("mail_users")
.insertOne(paramsObject, function (err, result) {
if (err) {
console.log(err);
} else {
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
console.log("没有重复数据");
//发送欢迎邮件
sendEmail(
"关于新型冠状病毒疫情数据推送的订阅通知",
"感谢你订阅新型冠状病毒疫情数据动态每日推送服务,你将在每天的23:00收到我们为您准备的包括全国数据与你所关注的省份/城市数据报表。湖北加油,中国加油。",
`感谢你订阅新型冠状病毒疫情数据动态每日推送服务,你将在每天的 <b>23:00</b> 收到我们为您准备的包括 <b>全国数据</b> 与你所关注的 <b>省份/城市</b> 数据报表。<br/>湖北加油,中国加油。`,
paramsObject.email
);
returnArray.code = 105;
returnArray.msg = "邮件推送订阅成功";
returnArray.status = true;
res.json(returnArray);
db.close();
}
});
}
}
});
}
}
);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "服务器错误,请联系管理员";
res.json(returnArray);
}
} else {
returnArray.code = 104;
returnArray.msg = "电子邮件地址错误";
returnArray.status = false;
console.log(global.dataObject.test_data);
res.json(returnArray);
}
});
/*
name: 取消订阅
route: /unsubscribe/mail
params: email
*/
app.post("/unsubscribe/mail", function (req, res) {
res.header(
"Access-Control-Allow-Origin",
"https://virus-notificator-vue.onrender.com"
);
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
//获取请求参数
const params = req.body;
//建立参数对象
var paramsObject = {
email: "[email protected]",
};
//电子邮件地址验证
var emailTest =
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (emailTest.test(params.email)) {
//保存参数
paramsObject.email = params.email;
if (global.requestStatus) {
//连接 MongoDB 数据库
mongo.connect(
databaseUrl,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
function (err, db) {
if (err) {
console.log(err);
return;
} else {
var coll = db.db("notificator");
//数据查重
coll
.collection("mail_users")
.find({
email: paramsObject.email,
})
.toArray(function (err, result) {
if (err) {
console.log(err);
} else {
if (result.length) {
console.log("有重复数据");
//删除数据
coll.collection("mail_users").deleteOne(
{
email: paramsObject.email,
},
function (err) {
if (err) {
console.log(err);
} else {
let returnArray = {
status: true,
code: 0,
data: [],
msg: null,
};
returnArray.code = 105;
returnArray.msg = "你已成功取消订阅";
returnArray.status = true;
res.json(returnArray);
db.close();
}
}
);
} else {
console.log("没有可以删除的数据");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 106;
returnArray.msg = "邮箱地址未订阅";
returnArray.status = false;
res.json(returnArray);
db.close();
}
}
});
}
}
);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "服务器错误,请联系管理员";
res.json(returnArray);
}
} else {
returnArray.code = 104;
returnArray.msg = "电子邮件地址错误";
returnArray.status = false;
console.log(global.dataObject.test_data);
res.json(returnArray);
}
});
/*
name: 邮箱订阅邮箱地址修改
route: /subscribe/mail/edit
params: original_email/current_email/province/city
*/
app.post("/subscribe/mail/edit", function (req, res) {
res.header(
"Access-Control-Allow-Origin",
"https://virus-notificator-vue.onrender.com"
);
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
//获取请求参数
const params = req.body;
//建立参数对象
var paramsObject = {
currentEmail: "[email protected]",
originEmail: "[email protected]",
};
//电子邮件地址验证
var emailTest =
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (
emailTest.test(params.original_email) &&
emailTest.test(params.current_email)
) {
//保存参数
paramsObject.originEmail = params.original_email;
paramsObject.currentEmail = params.current_email;
if (global.requestStatus) {
//连接 MongoDB 数据库
mongo.connect(
databaseUrl,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
function (err, db) {
if (err) {
console.log(err);
return;
} else {
var coll = db.db("notificator");
//数据查重
coll
.collection("mail_users")
.find({
email: paramsObject.originEmail,
})
.toArray(function (err, result) {
if (err) {
console.log(err);
} else {
if (result.length) {
//源邮箱存在记录
coll
.collection("mail_users")
.find({
email: paramsObject.currentEmail,
})
.toArray(function (err, result) {
if (err) {
console.log(err);
} else {
if (result.length) {
//现邮箱存在记录
console.log("修改后的邮箱已订阅");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 106;
returnArray.msg = "无法修改至已订阅邮箱";
returnArray.status = false;
res.json(returnArray);
db.close();
} else {
//更新数据
coll.collection("mail_users").updateOne(
{
email: paramsObject.originEmail,
},
{
$set: {
email: paramsObject.currentEmail,
},
},
function (err) {
if (err) {
console.log(err);
} else {
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 105;
returnArray.msg = "邮件地址修改成功";
returnArray.status = true;
res.json(returnArray);
db.close();
}
}
);
}
}
});
} else {
console.log("邮件并未订阅");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 106;
returnArray.msg = "原邮箱并未订阅";
returnArray.status = false;
res.json(returnArray);
db.close();
}
}
});
}
}
);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "服务器错误,请联系管理员";
res.json(returnArray);
}
} else {
returnArray.code = 104;
returnArray.msg = "邮箱地址不正确";
returnArray.status = false;
res.json(returnArray);
}
});
/*
name: 邮箱订阅省份城市修改
route: /subscribe/mail/edit/info/
params: email/province/city
*/
app.post("/subscribe/mail/edit/info", function (req, res) {
res.header(
"Access-Control-Allow-Origin",
"https://virus-notificator-vue.onrender.com"
);
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
//获取请求参数
const params = req.body;
//建立参数对象
var paramsObject = {
email: "[email protected]",
pro: "四川省",
city: "成都",
};
//电子邮件地址验证
var emailTest =
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (emailTest.test(params.email)) {
//保存参数
paramsObject.email = params.email;
paramsObject.pro = params.province;
paramsObject.city = params.city;
if (
global.dataObject.provinces_data[paramsObject.pro.toString()] !==
undefined &&
(global.dataObject.cities_data[paramsObject.city.toString()] !==
undefined ||
paramsObject.city.toString() == "无城市")
) {
if (global.requestStatus) {
//连接 MongoDB 数据库
mongo.connect(
databaseUrl,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
function (err, db) {
if (err) {
console.log(err);
return;
} else {
var coll = db.db("notificator");
//数据查重
coll
.collection("mail_users")
.find({
email: paramsObject.email,
})
.toArray(function (err, result) {
if (err) {
console.log(err);
} else {
if (result.length) {
//源邮箱存在记录
//更新数据
coll.collection("mail_users").updateOne(
{
email: paramsObject.email,
},
{
$set: {
pro: paramsObject.pro,
city: paramsObject.city,
},
},
function (err) {
if (err) {
console.log(err);
} else {
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 105;
returnArray.msg = "数据源修改成功";
returnArray.status = true;
res.json(returnArray);
db.close();
}
}
);
} else {
console.log("没有存在邮箱数据");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 106;
returnArray.msg = "邮箱并未订阅";
returnArray.status = false;
res.json(returnArray);
db.close();
}
}
});
}
}
);
} else {
returnArray.code = 100;
returnArray.status = false;
returnArray.msg = "服务器错误,请联系管理员";
res.json(returnArray);
}
} else {
returnArray.code = 107;
returnArray.msg = "省份或城市信息错误";
returnArray.status = false;
res.json(returnArray);
}
} else {
returnArray.code = 104;
returnArray.msg = "邮箱地址错误";
returnArray.status = false;
res.json(returnArray);
}
});
/* 订阅判断 Section */
/*
name: 判断邮箱是否订阅
route: /verify/mail/exist/:email
*/
app.get("/verify/mail/exist/:email", function (req, res) {
res.header(
"Access-Control-Allow-Origin",
"https://virus-notificator-vue.onrender.com"
);
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
//获取请求参数
const params = req.params;
//建立参数对象
var paramsObject = {
email: "[email protected]",
};
//电子邮件地址验证
var emailTest =
/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
if (emailTest.test(params.email)) {
//保存参数
paramsObject.email = params.email;
//连接 MongoDB 数据库
mongo.connect(
databaseUrl,
{
useNewUrlParser: true,
useUnifiedTopology: true,
},
function (err, db) {
if (err) {
console.log(err);
return;
} else {
var coll = db.db("notificator");
//数据查重
coll
.collection("mail_users")
.find({
email: paramsObject.email,
})
.toArray(function (err, result) {
if (err) {
console.log(err);
} else {
if (result.length) {
//源邮箱存在记录
let returnArray = {
status: false,
code: 0,
data: {},
msg: null,
};
returnArray.code = 105;
returnArray.msg = "Subscriber";
returnArray.status = true;
returnArray.data = {
email: result[0]["email"],
province: result[0]["pro"],
city: result[0]["city"],
};
res.json(returnArray);
db.close();
} else {
console.log("没有存在邮箱数据");
let returnArray = {
status: false,
code: 0,
data: [],
msg: null,
};
returnArray.code = 106;
returnArray.msg = "Visitor";
returnArray.status = false;
res.json(returnArray);
db.close();
}
}
});
}
}
);
} else {
returnArray.code = 104;
returnArray.msg = "Email Address is Invalid";
returnArray.status = false;
res.json(returnArray);
}
});
/* 订阅判断 Section */
/* 用户订阅 Section */
/* 服务部署 Section */
/* 定时作业 Section */
function scheduleTasks() {
schedule.scheduleJob("* /1 * * * *", function () {
mailFunc();
});
schedule.scheduleJob("30 * * * * *", function () {
consoleMessage("开始请求最新数据", "start");
request(
"https://files.snapaper.com/virus",
function (error, response, data) {
if (!error && response.statusCode == 200) {
global.dataObject = JSON.parse(data.toString()); //获取
global.requestStatus = true;
console.log("数据请求成功");
global.feedData = getFeed();
} else {
global.requestStatus = false;
console.log("数据请求失败");
}
consoleMessage("结束请求最新数据", "end");
}
);
});
}
scheduleTasks();
/* 定时作业 Section */
app.listen(process.env.PORT || 2333, function () {
console.log("app is listening at port 2333");
});
/* 服务部署 Section */