Skip to content

Commit b2928ad

Browse files
committed
Use base64 encoding from external lib
Signed-off-by: Trung Nguyen <[email protected]>
1 parent 1a81dac commit b2928ad

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/extension/ui/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extension/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@mui/material": "6.4.5",
1313
"@tanstack/react-query": "^5.69.0",
1414
"ansi-to-html": "^0.7.2",
15+
"js-base64": "^3.7.7",
1516
"json-schema-library": "^10.0.0-rc7",
1617
"lodash-es": "^4.17.21",
1718
"react": "^18.2.0",

src/extension/ui/src/FileUtils.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
import { v1 } from "@docker/extension-api-client-types"
66
import { ExecResult } from "@docker/extension-api-client-types/dist/v0"
7+
import { encode } from 'js-base64';
8+
79
import { BUSYBOX } from "./Constants"
810

911
export const tryRunImageSync = async (client: v1.DockerDesktopClient, args: string[], ignoreError = false) => {
@@ -45,7 +47,7 @@ export const writeToPromptsVolume = async (client: v1.DockerDesktopClient, filen
4547
BUSYBOX,
4648
"/bin/sh",
4749
"-c",
48-
`'echo "${encodeBase64(content)}" | base64 -d > ${filename}'`,
50+
`'echo "${encode(content)}" | base64 -d > ${filename}'`,
4951
]);
5052
}
5153

@@ -57,12 +59,6 @@ export const writeToMount = async (client: v1.DockerDesktopClient, mount: string
5759
BUSYBOX,
5860
"/bin/sh",
5961
"-c",
60-
`'echo "${encodeBase64(content)}" | base64 -d > ${filename}'`,
62+
`'echo "${encode(content)}" | base64 -d > ${filename}'`,
6163
]);
6264
}
63-
64-
const encodeBase64 = (input: string): string => {
65-
const utf8Bytes = new TextEncoder().encode(input);
66-
const binary = Array.from(utf8Bytes).map(byte => String.fromCharCode(byte)).join('');
67-
return btoa(binary);
68-
};

0 commit comments

Comments
 (0)