-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (72 loc) · 2.4 KB
/
index.js
File metadata and controls
80 lines (72 loc) · 2.4 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
78
79
80
const express = require("express");
const path = require("path");
const fs = require("fs");
const { convertVideoToGif } = require("./src/ffemeng.js");
const { MarkdownToHtml } = require("./src/markdown-to-html/index.js");
const { PlayVideo, DownloadVideo } = require("./src/video/index.js");
const app = express();
const PORT = process.env.PORT || 5050;
const { createProxyMiddleware } = require("http-proxy-middleware");
const { sendEmail } = require("./src/email-server/index.js");
const {
getQrCode,
ScanAuthlogin,
checkAuth,
} = require("./src/scan_code_login/index.js");
// 暂时注释掉数据库相关功能,避免连接错误
// const {
// getAllData,
// getUserById,
// createUser,
// updataUser,
// deleteUser,
// } = require("./src/dao/service.js");
const {
upload,
uploadFile,
mergeFile,
} = require("./src/upload-file/upload-file.js");
app.use(express.json());
// app.use(
// "/api",
// createProxyMiddleware({
// target: "http://localhost:3000", // 目标服务器
// changeOrigin: true, // 修改请求头中的 host
// pathRewrite: { "^/api": "" }, // 可选:去掉前缀 /api
// }),
// );
app.get("/", (req, res) => {
res.send("Hello, JavaScript and Express!");
});
app.get("/gif", async (req, res) => {
try {
const mp4Path = path.join(__dirname, "test.mp4"); // 改后缀 mp4
const buffer = await convertVideoToGif(mp4Path);
res.setHeader("Content-Type", "image/gif");
res.send(buffer);
} catch (err) {
console.error(err);
res.status(500).send("转换失败: " + err.message);
}
});
app.get("/play-video", PlayVideo);
// express 支持range响应,实现分片下载/请求,后续看一下
app.get("/download", DownloadVideo);
app.get("/markdown-to-html", MarkdownToHtml);
app.get("/send-email", sendEmail);
// 暂时注释掉数据库相关路由
// app.get("/all-user", getAllData);
// app.get("/user/:id", getUserById);
// app.post("/create", createUser);
// app.post("/update", updataUser);
// app.post("/delete", deleteUser);
// 文件上传路由
app.post("/upload-file", upload.single("file"), uploadFile);
app.post("/merge-file", mergeFile);
// scan code login
app.get("/get-qrcode", getQrCode);
app.post("/scan-auth-login/:userId", ScanAuthlogin);
app.get("/check-auth", checkAuth);
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});