-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
138 lines (119 loc) · 4.16 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
//===----------------------------------------------------------------------===//
//
// Violet API Server
//
//===----------------------------------------------------------------------===//
//
// Copyright (C) 2020-2021. violet-team. All Rights Reserved.
//
//===----------------------------------------------------------------------===//
const config = require("config");
const AWS = require("aws-sdk");
AWS.config.loadFromPath(__dirname + "/./config/s3.json");
const express = require("express");
const createError = require("http-errors");
const expressDefend = require("express-defend");
const blacklist = require("express-blacklist");
const rateLimit = require("express-rate-limit");
const r_cur_ts = require("./routes/cur_ts");
const r_community = require("./routes/community/routes");
const r_backup = require("./routes/backup/upload");
const r_excomment = require("./routes/excomment/routes");
const r_search = require("./routes/search/routes");
const r_record = require("./routes/record/routes");
const r_index = require("./routes/index");
const r_query = require("./routes/query");
const r_top = require("./routes/top");
const r_top_ts = require("./routes/top_ts");
const r_top_recent = require("./routes/top_recent");
const r_upload = require("./routes/upload");
const r_restore = require("./routes/restore");
const r_bookmarks = require("./routes/bookmarks/routes");
const r_view = require("./routes/view");
const r_view_close = require("./routes/view_close");
const r_view_report = require("./routes/view_report");
// const t_1144 = require('./routes/test1144');
// const t_1145 = require('./routes/test1145');
const p = require("./pages/status");
const app = express();
const bots = require("./bot/bots");
const swaggerUi = require("swagger-ui-express");
const YAML = require("yamljs");
const swaggerDocument = YAML.load("./swagger.yaml");
app.disable("x-powered-by");
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use(express.json({ limit: "500mb" }));
app.use(express.urlencoded({ limit: "50mb", extended: false }));
// Ban ip address
app.use(blacklist.blockRequests("blacklist.txt"));
app.use(
expressDefend.protect({
maxAttempts: 1,
dropSuspiciousRequest: true,
onMaxAttemptsReached: function (ipAddress, url) {
blacklist.addAddress(ipAddress);
},
})
);
// Limit Request
const limiter = rateLimit({
windowMs: 1000 * 60,
max: 5 * 6 * 3 * 100,
});
app.use(limiter);
app.use("/cur_ts", r_cur_ts);
app.use("/community", r_community);
// app.use("/fupload", r_backup);
app.use("/excomment", r_excomment);
app.use("/search", r_search);
app.use("/query", r_query);
app.use("/top", r_top);
app.use("/top_ts", r_top_ts);
app.use("/top_recent", r_top_recent);
app.use("/record", r_record);
app.post("/upload", r_upload);
app.get("/restore", r_restore);
// app.get('/bookmarks2', r_bookmarks);
app.use("/bookmarks", r_bookmarks);
app.post("/view", r_view);
app.get("/view", function (req, res, next) {
res.status(405).type("html").send(p.p405);
});
app.post("/view_close", r_view_close);
app.get("/view_close", function (req, res, next) {
res.status(405).type("html").send(p.p405);
});
app.post("/view_report", r_view_report);
app.get("/view_report", function (req, res, next) {
res.status(405).type("html").send(p.p405);
});
// app.use('/1144', t_1144);
// const r_auth = require("./auth/auth");
const { S3Client } = require("@aws-sdk/client-s3");
const aws_s3_new = require("./api/aws-s3-new");
const s3 = new AWS.S3();
const multer = require("multer");
const multerS3 = require("multer-s3");
const upload = multer({
storage: multerS3({
s3: s3,
bucket: "violet-user-data-backup",
contentType: multerS3.AUTO_CONTENT_TYPE,
key: function (req, file, cb) {
cb(null, `${Date.now().toString()}_${file.originalname}`);
},
acl: "public-read",
}),
});
app.post("/fupload", upload.single("file"), function (req, res, next) {
console.log(req.file);
res.send();
});
app.get("/", function (req, res) {
res.redirect("/api-docs");
});
// Since it is filtered by nginx, the routing below should not be valid.
app.use(function (req, res, next) {
res.status(404).type("html").send(p.p404);
});
module.exports = app;