Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions assets/electron/template/app/src/handlers/fs/write-base64.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// @ts-check

import { mkdir, writeFile } from 'node:fs/promises'
import { dirname } from 'node:path'

/**
* @param {{url: string, correlationId?: string, body: {path: string, base64Data: string, flag?: string}}} json
* @param {import('ws').WebSocket} ws
*/
export default async (json, ws) => {
const destDirName = dirname(json.body.path)
await mkdir(destDirName, { recursive: true })

// Decode base64 string to buffer
const buffer = Buffer.from(json.body.base64Data, 'base64')

await writeFile(json.body.path, buffer, {
flag: json.body.flag
})

/**
* @type {{url: string, correlationId?: string, body: {success: boolean}}}
*/
const writeFileResult = {
correlationId: json.correlationId,
url: json.url,
body: {
success: true
}
}
ws.send(JSON.stringify(writeFileResult))
}
5 changes: 5 additions & 0 deletions assets/electron/template/app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import userFolder from './handlers/user/folder.js'

// fs
import fsWrite from './handlers/fs/write.js'
import fsWriteBase64 from './handlers/fs/write-base64.js'
import fsRead from './handlers/fs/read.js'
import fsReadBinary from './handlers/fs/read-binary.js'
import fsFolderCreate from './handlers/fs/folder-create.js'
Expand Down Expand Up @@ -368,6 +369,10 @@ const createAppServer = (mainWindow, serveStatic = true) => {
await fsWrite(json, ws)
break

case '/fs/file/write-base64':
await fsWriteBase64(json, ws)
break

case '/fs/file/read':
await fsRead(json, ws)
break
Expand Down
9 changes: 7 additions & 2 deletions src/shared/libs/plugin-poki/export.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createAction, createActionRunner, createPathParam, createStringParam, runWithLiveLogs } from '@pipelab/plugin-core'
import { dirname } from 'node:path'

export const ID = 'poki-upload'

Expand Down Expand Up @@ -42,8 +43,8 @@ export const uploadToPoki = createAction({

export const uploadToPokiRunner = createActionRunner<typeof uploadToPoki>(
async ({ log, inputs, paths, abortSignal, cwd }) => {
const { join } = await import('node:path')
const { writeFile , cp, mkdir } = await import('node:fs/promises')
const { join, basename, delimiter } = await import('node:path')
const { writeFile, cp, mkdir } = await import('node:fs/promises')
const { shell } = await import('electron')

const { unpack } = paths
Expand Down Expand Up @@ -82,6 +83,10 @@ export const uploadToPokiRunner = createActionRunner<typeof uploadToPoki>(
['upload', '--name', inputs.name, '--notes', inputs.notes],
{
cwd,
env: {
// DEBUG: '*',
PATH: `${dirname(poki)}${delimiter}${process.env.PATH}`,
},
cancelSignal: abortSignal,
},
log,
Expand Down
Loading