diff --git a/README-zh.md b/README-zh.md
index e1ac472..b3f2581 100644
--- a/README-zh.md
+++ b/README-zh.md
@@ -4,17 +4,17 @@
-
- English |
- 中文
-
-
+
+ English |
+ 中文
+
+
## 支持系统 💻
| Linux | MacOS | Windows |
@@ -79,4 +79,4 @@
## 其他文档 📖
-[Contribution Guide](./CONTRIBUTING.md) | [Security Policy](./SECURITY.md) | [Update Log](./CHANGELOG.md) | [Licence](./LICENSE)
+[贡献指南](./CONTRIBUTING.md) | [安全策略](./SECURITY.md) | [更新日志](./CHANGELOG.md) | [许可证](./LICENSE)
diff --git a/README.md b/README.md
index 88bd202..05df782 100755
--- a/README.md
+++ b/README.md
@@ -4,17 +4,17 @@
-
- English |
- 中文
-
-
+
+ English |
+ 中文
+
+
## Support System 💻
| Liunx | MacOS | Windows |
@@ -79,4 +79,4 @@
## Other Docs 📖
-[贡献指南](./CONTRIBUTING.md) | [安全策略](./SECURITY.md) | [更新日志](./CHANGELOG.md) | [许可证](./LICENSE)
+[Contribution Guide](./CONTRIBUTING.md) | [Security Policy](./SECURITY.md) | [Update Log](./CHANGELOG.md) | [Licence](./LICENSE)
diff --git a/index.js b/index.js
index 90eb979..6bc417d 100755
--- a/index.js
+++ b/index.js
@@ -1,62 +1,32 @@
// app.js
const Koa = require("koa");
-const { koaBody } = require("koa-body");
-const path = require("path");
-const fs = require("fs");
const sequelize = require("./utils/dbInstance");
const filesRouter = require("./routers/files");
const usersRouter = require("./routers/users");
const redisClient = require("./redis");
const authenticateToken = require("./middleware/authenticateToken");
-const cors = require("@koa/cors");
+const koaBody = require("./middleware/koaBody");
+const cors = require("./middleware/cors");
+const createInitDir = require("./utils/createInitDir");
+
require("./models");
require("./schedules/fileRecover");
require("dotenv").config({ path: ".env.local" });
const app = new Koa();
-app.use(
- cors({
- origin: "http://localhost:5173/", // 允许的来源
- allowMethods: ["GET", "POST"], // 允许的方法
- })
-);
-
-app.use(require("koa-static")(path.join(__dirname, "public")));
-
-const createDirectories = () => {
- const dirs = [
- path.join(__dirname, "provisional"),
- path.join(__dirname, "resource"),
- ];
- dirs.forEach((dir) => {
- if (!fs.existsSync(dir)) {
- fs.mkdirSync(dir, { recursive: true });
- }
- });
-};
-
-createDirectories();
+app.use(cors());
app.use(authenticateToken);
-app.use(
- koaBody({
- multipart: true,
- // 解决 DELETE 没法获取ids的问题
- parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
- formidable: {
- uploadDir: path.join(__dirname, "provisional"), // 临时上传目录
- keepExtensions: true, // 保留文件扩展名
- },
- })
-);
+app.use(koaBody());
// 挂载文件路由
app.use(usersRouter.routes()).use(usersRouter.allowedMethods());
app.use(filesRouter.routes()).use(filesRouter.allowedMethods());
app.listen(process.env.SERVER_PORT, async () => {
+ createInitDir();
await redisClient.connect();
await sequelize.sync();
console.log(`Server is running on ${process.env.INTERNAL_NETWORK_DOMAIN}`);
diff --git a/middleware/cors.js b/middleware/cors.js
new file mode 100644
index 0000000..55348f5
--- /dev/null
+++ b/middleware/cors.js
@@ -0,0 +1,7 @@
+const cors = require("@koa/cors");
+
+module.exports = () =>
+ cors({
+ origin: "http://localhost:5173/", // 允许的来源
+ allowMethods: ["GET", "POST"], // 允许的方法
+ });
diff --git a/middleware/koaBody.js b/middleware/koaBody.js
new file mode 100644
index 0000000..0bd79d9
--- /dev/null
+++ b/middleware/koaBody.js
@@ -0,0 +1,13 @@
+const { koaBody } = require("koa-body");
+const path = require("path");
+
+module.exports = () =>
+ koaBody({
+ multipart: true,
+ // 解决 DELETE 没法获取ids的问题
+ parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
+ formidable: {
+ uploadDir: path.join(__dirname, "..", "provisional"), // 临时上传目录
+ keepExtensions: true, // 保留文件扩展名
+ },
+ });
diff --git a/public/index.html b/public/index.html
deleted file mode 100755
index e22a6c8..0000000
--- a/public/index.html
+++ /dev/null
@@ -1,241 +0,0 @@
-
-
-
-
-
-
- 批量上传文件和图床
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/utils/createInitDir.js b/utils/createInitDir.js
new file mode 100644
index 0000000..88e1c34
--- /dev/null
+++ b/utils/createInitDir.js
@@ -0,0 +1,14 @@
+const path = require("path");
+const fs = require("fs");
+
+module.exports = () => {
+ const dirs = [
+ path.join(__dirname, "..", "provisional"),
+ path.join(__dirname, "..", "resource"),
+ ];
+ dirs.forEach((dir) => {
+ if (!fs.existsSync(dir)) {
+ fs.mkdirSync(dir, { recursive: true });
+ }
+ });
+};