Merge pull request #42 from DragoSpiro98/master

Feat: Route reference for file manager to create a new empty file
This commit is contained in:
unitwk 2022-11-29 20:01:02 +08:00 committed by GitHub
commit e1928741a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -47,6 +47,18 @@ routerApp.on("file/status", (ctx, data) => {
}
});
// Create a new file
routerApp.on("file/touch", (ctx, data) => {
try {
const target = data.target;
const fileManager = getFileManager(data.instanceUuid);
fileManager.newFile(target);
protocol.response(ctx, true);
} catch (error) {
protocol.responseError(ctx, error);
}
});
// Create a directory
routerApp.on("file/mkdir", (ctx, data) => {
try {

View File

@ -109,6 +109,12 @@ export default class FileManager {
return await fs.writeFile(absPath, buf);
}
async newFile(fileName: string){
const target = this.toAbsolutePath(fileName)
console.log(target)
fs.createFile(target)
}
async copy(target1: string, target2: string) {
if (!this.checkPath(target2) || !this.check(target1)) throw new Error(ERROR_MSG_01);
const targetPath = this.toAbsolutePath(target1);