forked from mirror/MCSM-Daemon
Auto Update
This commit is contained in:
parent
25890488c6
commit
5f3e1e9937
@ -36,9 +36,11 @@ const config = globalConfiguration.config;
|
||||
|
||||
// 初始化 Koa 框架
|
||||
const koaApp = new Koa();
|
||||
koaApp.use(koaBody({
|
||||
multipart: true,
|
||||
}))
|
||||
koaApp.use(
|
||||
koaBody({
|
||||
multipart: true
|
||||
})
|
||||
);
|
||||
|
||||
// 装载 HTTP 服务路由
|
||||
import koaRouter from "./routers/http_router";
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: Copyright 2021 Suwings
|
||||
* @Date: 2021-07-14 16:13:18
|
||||
* @LastEditTime: 2021-07-14 17:10:50
|
||||
* @LastEditTime: 2021-07-14 17:30:21
|
||||
* @Description:
|
||||
*/
|
||||
import Router from "@koa/router";
|
||||
@ -10,7 +10,6 @@ import path from "path";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
|
||||
// 定义 HTTP 首页展示路由
|
||||
router.all("/", async (ctx) => {
|
||||
ctx.body = "Copyright(c) 2021 MCSManager | Status: OK.";
|
||||
@ -18,9 +17,9 @@ router.all("/", async (ctx) => {
|
||||
});
|
||||
|
||||
// 文件下载路由
|
||||
router.all("/download/:id/:name", async (ctx) => {
|
||||
router.get("/download/:id/:name", async (ctx) => {
|
||||
try {
|
||||
const target = "D:/文件上传/test.zip"
|
||||
const target = "D:/文件上传/test.zip";
|
||||
const ext = path.extname(target);
|
||||
ctx.type = ext;
|
||||
console.log("正在下载:", ext);
|
||||
@ -39,14 +38,13 @@ router.post("/upload/:id", async (ctx) => {
|
||||
// 确认文件夹名和后缀
|
||||
const fullFileName = file.name as string;
|
||||
const fullFileNameArray = fullFileName.split(".");
|
||||
const ext = fullFileNameArray.pop() || ""
|
||||
const fileName = fullFileNameArray.join(".")
|
||||
const ext = fullFileNameArray.pop() || "";
|
||||
const fileName = fullFileNameArray.join(".");
|
||||
const fileSavePath = `upload/${fileName}.${ext}`;
|
||||
|
||||
// 特殊字符过滤
|
||||
const blackKeys = ["/", "\\", "|", "?", "*", ">", "<", ";", "\"", "'"];
|
||||
for (const ch of blackKeys)
|
||||
if (fileName.includes(ch)) throw new Error("0x044");
|
||||
const blackKeys = ["/", "\\", "|", "?", "*", ">", "<", ";", '"', "'"];
|
||||
for (const ch of blackKeys) if (fileName.includes(ch)) throw new Error("0x044");
|
||||
|
||||
// 将文件从临时文件夹复制到指定目录
|
||||
const reader = fs.createReadStream(file.path);
|
||||
|
Loading…
Reference in New Issue
Block a user