Skip to content

Commit

Permalink
add electron support for checking file existance
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Jan 14, 2025
1 parent e6207d0 commit 449ab44
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
37 changes: 37 additions & 0 deletions assets/electron/template/app/src/handlers/fs/exist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// @ts-check

import { access } from 'node:fs/promises'

/**
* @param {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageExistFile, 'input'>} json
* @param {import('ws').WebSocket} ws
*/
export default async (json, ws) => {
try {
await access(json.body.path)

/**
* @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageExistFile, 'output'>}
*/
const existResult = {
correlationId: json.correlationId,
url: json.url,
body: {
success: true
}
}
ws.send(JSON.stringify(existResult))
} catch (e) {
/**
* @type {import('@pipelab/core').MakeInputOutput<import('@pipelab/core').MessageExistFile, 'output'>}
*/
const existResult = {
correlationId: json.correlationId,
url: json.url,
body: {
success: false
}
}
ws.send(JSON.stringify(existResult))
}
}
4 changes: 3 additions & 1 deletion assets/electron/template/app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import fsReadBinary from './handlers/fs/read-binary.js'
import fsFolderCreate from './handlers/fs/folder-create.js'
import fsList from './handlers/fs/list.js'
import fsFileSize from './handlers/fs/file-size.js'
import fsExist from './handlers/fs/exist.js'

// window
import windowMaximize from './handlers/window/maximize.js'
Expand Down Expand Up @@ -241,7 +242,8 @@ const createAppServer = (mainWindow, serveStatic = true) => {
case '/fs/delete':
throw new Error('Not implemented')
case '/fs/exist':
throw new Error('Not implemented')
await fsExist(json, ws)
break
case '/fs/file/append':
throw new Error('Not implemented')
case '/fs/list':
Expand Down

0 comments on commit 449ab44

Please sign in to comment.