From efeb8394c3e8efef52c62d9ef0d766dde04da5c7 Mon Sep 17 00:00:00 2001 From: Giovanni Palma <33783684+DragoSpiro98@users.noreply.github.com> Date: Mon, 28 Nov 2022 12:43:24 +0100 Subject: [PATCH] Feat: new file route --- src/routers/file_router.ts | 12 ++++++++++++ src/service/system_file.ts | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/routers/file_router.ts b/src/routers/file_router.ts index 4c469e6..67ad4f3 100755 --- a/src/routers/file_router.ts +++ b/src/routers/file_router.ts @@ -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 { diff --git a/src/service/system_file.ts b/src/service/system_file.ts index 64ad8cc..b012f4c 100755 --- a/src/service/system_file.ts +++ b/src/service/system_file.ts @@ -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);