Skip to content

Commit 822e045

Browse files
authored
WriteBase64, Poki Upload (#55)
* Added write base64 file * Fix Poki upload
1 parent 9adcf26 commit 822e045

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// @ts-check
2+
3+
import { mkdir, writeFile } from 'node:fs/promises'
4+
import { dirname } from 'node:path'
5+
6+
/**
7+
* @param {{url: string, correlationId?: string, body: {path: string, base64Data: string, flag?: string}}} json
8+
* @param {import('ws').WebSocket} ws
9+
*/
10+
export default async (json, ws) => {
11+
const destDirName = dirname(json.body.path)
12+
await mkdir(destDirName, { recursive: true })
13+
14+
// Decode base64 string to buffer
15+
const buffer = Buffer.from(json.body.base64Data, 'base64')
16+
17+
await writeFile(json.body.path, buffer, {
18+
flag: json.body.flag
19+
})
20+
21+
/**
22+
* @type {{url: string, correlationId?: string, body: {success: boolean}}}
23+
*/
24+
const writeFileResult = {
25+
correlationId: json.correlationId,
26+
url: json.url,
27+
body: {
28+
success: true
29+
}
30+
}
31+
ws.send(JSON.stringify(writeFileResult))
32+
}

assets/electron/template/app/src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import userFolder from './handlers/user/folder.js'
1717

1818
// fs
1919
import fsWrite from './handlers/fs/write.js'
20+
import fsWriteBase64 from './handlers/fs/write-base64.js'
2021
import fsRead from './handlers/fs/read.js'
2122
import fsReadBinary from './handlers/fs/read-binary.js'
2223
import fsFolderCreate from './handlers/fs/folder-create.js'
@@ -368,6 +369,10 @@ const createAppServer = (mainWindow, serveStatic = true) => {
368369
await fsWrite(json, ws)
369370
break
370371

372+
case '/fs/file/write-base64':
373+
await fsWriteBase64(json, ws)
374+
break
375+
371376
case '/fs/file/read':
372377
await fsRead(json, ws)
373378
break

src/shared/libs/plugin-poki/export.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createAction, createActionRunner, createPathParam, createStringParam, runWithLiveLogs } from '@pipelab/plugin-core'
2+
import { dirname } from 'node:path'
23

34
export const ID = 'poki-upload'
45

@@ -42,8 +43,8 @@ export const uploadToPoki = createAction({
4243

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

4950
const { unpack } = paths
@@ -82,6 +83,10 @@ export const uploadToPokiRunner = createActionRunner<typeof uploadToPoki>(
8283
['upload', '--name', inputs.name, '--notes', inputs.notes],
8384
{
8485
cwd,
86+
env: {
87+
// DEBUG: '*',
88+
PATH: `${dirname(poki)}${delimiter}${process.env.PATH}`,
89+
},
8590
cancelSignal: abortSignal,
8691
},
8792
log,

0 commit comments

Comments
 (0)