Feat: new file route

This commit is contained in:
Giovanni Palma 2022-11-28 12:43:24 +01:00
parent 236ec53d40
commit efeb8394c3
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 // Create a directory
routerApp.on("file/mkdir", (ctx, data) => { routerApp.on("file/mkdir", (ctx, data) => {
try { try {

View File

@ -109,6 +109,12 @@ export default class FileManager {
return await fs.writeFile(absPath, buf); 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) { async copy(target1: string, target2: string) {
if (!this.checkPath(target2) || !this.check(target1)) throw new Error(ERROR_MSG_01); if (!this.checkPath(target2) || !this.check(target1)) throw new Error(ERROR_MSG_01);
const targetPath = this.toAbsolutePath(target1); const targetPath = this.toAbsolutePath(target1);