forked from mirror/MCSM-Daemon
Feat: add chmod file func
This commit is contained in:
parent
427556f004
commit
fd7ee790c7
@ -7,6 +7,7 @@ import InstanceSubsystem from "../service/system_instance";
|
|||||||
import { getFileManager } from "../service/file_router_service";
|
import { getFileManager } from "../service/file_router_service";
|
||||||
import { globalConfiguration, globalEnv } from "../entity/config";
|
import { globalConfiguration, globalEnv } from "../entity/config";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
|
|
||||||
// Some routers operate router authentication middleware
|
// Some routers operate router authentication middleware
|
||||||
routerApp.use((event, ctx, data, next) => {
|
routerApp.use((event, ctx, data, next) => {
|
||||||
if (event.startsWith("file/")) {
|
if (event.startsWith("file/")) {
|
||||||
@ -34,6 +35,18 @@ routerApp.on("file/list", (ctx, data) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// File chmod (only Linux)
|
||||||
|
routerApp.on("file/chmod", async (ctx, data) => {
|
||||||
|
try {
|
||||||
|
const fileManager = getFileManager(data.instanceUuid);
|
||||||
|
const { chmod, target, isDeep } = data;
|
||||||
|
await fileManager.chmod(target, chmod, isDeep);
|
||||||
|
protocol.response(ctx, true);
|
||||||
|
} catch (error) {
|
||||||
|
protocol.responseError(ctx, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Query the status of the file management system
|
// Query the status of the file management system
|
||||||
routerApp.on("file/status", (ctx, data) => {
|
routerApp.on("file/status", (ctx, data) => {
|
||||||
try {
|
try {
|
||||||
|
@ -6,6 +6,7 @@ import fs from "fs-extra";
|
|||||||
import { compress, decompress } from "../common/compress";
|
import { compress, decompress } from "../common/compress";
|
||||||
import iconv from "iconv-lite";
|
import iconv from "iconv-lite";
|
||||||
import { globalConfiguration } from "../entity/config";
|
import { globalConfiguration } from "../entity/config";
|
||||||
|
import { processWrapper } from "../common/process_tools";
|
||||||
|
|
||||||
const ERROR_MSG_01 = $t("system_file.illegalAccess");
|
const ERROR_MSG_01 = $t("system_file.illegalAccess");
|
||||||
const MAX_EDIT_SIZE = 1024 * 1024 * 4;
|
const MAX_EDIT_SIZE = 1024 * 1024 * 4;
|
||||||
@ -92,6 +93,17 @@ export default class FileManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async chmod(fileName: string, chmodValue: number, deep: boolean) {
|
||||||
|
if (!this.check(fileName) || isNaN(parseInt(chmodValue as any))) throw new Error(ERROR_MSG_01);
|
||||||
|
const defaultPath = "/bin/chmod";
|
||||||
|
let file = "chmod";
|
||||||
|
if (fs.existsSync(defaultPath)) file = defaultPath;
|
||||||
|
const params: string[] = [];
|
||||||
|
if (deep) params.push("-R");
|
||||||
|
params.push(String(chmodValue));
|
||||||
|
return await new processWrapper(file, params, ".", 60 * 10).start();
|
||||||
|
}
|
||||||
|
|
||||||
async readFile(fileName: string) {
|
async readFile(fileName: string) {
|
||||||
if (!this.check(fileName)) throw new Error(ERROR_MSG_01);
|
if (!this.check(fileName)) throw new Error(ERROR_MSG_01);
|
||||||
const absPath = this.toAbsolutePath(fileName);
|
const absPath = this.toAbsolutePath(fileName);
|
||||||
|
Loading…
Reference in New Issue
Block a user