mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-02-23 16:09:37 +08:00
Feat: panel support file upload
This commit is contained in:
parent
6e0be288f8
commit
51cbdd5696
@ -123,7 +123,14 @@ _ / / / / /___ ____/ /_ / / / / /_/ /_ / / / /_/ /_ /_/ // __/ /
|
||||
app.use(
|
||||
koaBody({
|
||||
multipart: true,
|
||||
parsedMethods: ["POST", "PUT", "DELETE", "GET"]
|
||||
parsedMethods: ["POST", "PUT", "DELETE", "GET"],
|
||||
formidable: {
|
||||
maxFieldsSize: Number.MAX_VALUE,
|
||||
maxFileSize: Number.MAX_VALUE
|
||||
},
|
||||
onError(err, ctx) {
|
||||
logger.error("koaBody Lib Error:", err);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
|
@ -6,6 +6,9 @@ import { saveSystemConfig, systemConfig } from "../../setting";
|
||||
import { logger } from "../../service/log";
|
||||
import { i18next } from "../../i18n";
|
||||
import userSystem from "../../service/system_user";
|
||||
import { v4 } from "uuid";
|
||||
import path from "path";
|
||||
import * as fs from "fs-extra";
|
||||
import {
|
||||
getFrontendLayoutConfig,
|
||||
resetFrontendLayoutConfig,
|
||||
@ -86,4 +89,16 @@ router.delete("/layout", permission({ level: 10 }), async (ctx) => {
|
||||
ctx.body = true;
|
||||
});
|
||||
|
||||
router.post("/upload_assets", permission({ level: 10 }), async (ctx) => {
|
||||
const tmpFiles = ctx.request.files.file;
|
||||
if (!tmpFiles || tmpFiles instanceof Array) throw new Error("The body is incorrect");
|
||||
if (!tmpFiles.path || !fs.existsSync(tmpFiles.path)) throw new Error("The file does not exist");
|
||||
const tmpFile = tmpFiles;
|
||||
const newFileName = v4() + path.extname(tmpFile.name);
|
||||
const saveDirPath = path.join(process.cwd(), "public/upload_files/");
|
||||
if (!fs.existsSync(saveDirPath)) fs.mkdirsSync(saveDirPath);
|
||||
await fs.move(tmpFile.path, path.join(saveDirPath, newFileName));
|
||||
ctx.body = newFileName;
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
Loading…
Reference in New Issue
Block a user