n8n-nodes-daytona-tool 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,4 +19,5 @@ export declare const startSandbox: (sandbox: any) => Promise<any>;
19
19
  export declare const stopSandbox: (sandbox: any) => Promise<any>;
20
20
  export declare const createSandboxFile: (content: string, name: string, contentType?: string) => Readable;
21
21
  export declare const uploadSandboxFile: (sandbox: any, remotePath: string, file: any) => Promise<any>;
22
+ export declare const uploadSandboxFileFromContent: (sandbox: any, remotePath: string, content: string, fileName: string) => Promise<any>;
22
23
  export {};
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadSandboxFile = exports.createSandboxFile = exports.stopSandbox = exports.startSandbox = exports.disposeSandbox = exports.runNodeCode = exports.getSandboxByName = exports.getSandbox = exports.createSandbox = exports.createDaytonaClient = void 0;
6
+ exports.uploadSandboxFileFromContent = exports.uploadSandboxFile = exports.createSandboxFile = exports.stopSandbox = exports.startSandbox = exports.disposeSandbox = exports.runNodeCode = exports.getSandboxByName = exports.getSandbox = exports.createSandbox = exports.createDaytonaClient = void 0;
4
7
  const sdk_1 = require("@daytonaio/sdk");
5
8
  const node_stream_1 = require("node:stream");
9
+ const promises_1 = __importDefault(require("node:fs/promises"));
10
+ const node_os_1 = __importDefault(require("node:os"));
11
+ const node_path_1 = __importDefault(require("node:path"));
6
12
  const getCreateFn = (client) => { var _a, _b; return (_a = client === null || client === void 0 ? void 0 : client.create) !== null && _a !== void 0 ? _a : (_b = client === null || client === void 0 ? void 0 : client.sandbox) === null || _b === void 0 ? void 0 : _b.create; };
7
13
  const getFetchFn = (client) => { var _a, _b, _c, _d; return (_c = (_a = client === null || client === void 0 ? void 0 : client.get) !== null && _a !== void 0 ? _a : (_b = client === null || client === void 0 ? void 0 : client.sandbox) === null || _b === void 0 ? void 0 : _b.get) !== null && _c !== void 0 ? _c : (_d = client === null || client === void 0 ? void 0 : client.sandbox) === null || _d === void 0 ? void 0 : _d.connect; };
8
14
  const getDisposeFn = (sandbox) => { var _a, _b; return (_b = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.dispose) !== null && _a !== void 0 ? _a : sandbox === null || sandbox === void 0 ? void 0 : sandbox.destroy) !== null && _b !== void 0 ? _b : sandbox === null || sandbox === void 0 ? void 0 : sandbox.remove; };
@@ -113,3 +119,26 @@ const uploadSandboxFile = async (sandbox, remotePath, file) => {
113
119
  return uploadFn.call(fsApi, remotePath, file);
114
120
  };
115
121
  exports.uploadSandboxFile = uploadSandboxFile;
122
+ const writeTempFile = async (content, fileName) => {
123
+ const dir = await promises_1.default.mkdtemp(node_path_1.default.join(node_os_1.default.tmpdir(), 'daytona-'));
124
+ const filePath = node_path_1.default.join(dir, fileName);
125
+ await promises_1.default.writeFile(filePath, content, 'utf8');
126
+ return { dir, filePath };
127
+ };
128
+ const uploadSandboxFileFromContent = async (sandbox, remotePath, content, fileName) => {
129
+ var _a, _b;
130
+ const fsApi = (_a = sandbox === null || sandbox === void 0 ? void 0 : sandbox.fs) !== null && _a !== void 0 ? _a : sandbox;
131
+ const uploadFn = (_b = fsApi === null || fsApi === void 0 ? void 0 : fsApi.uploadFile) !== null && _b !== void 0 ? _b : fsApi === null || fsApi === void 0 ? void 0 : fsApi.upload;
132
+ if (!uploadFn) {
133
+ throw new Error('Daytona SDK: upload file method not found.');
134
+ }
135
+ const { dir, filePath } = await writeTempFile(content, fileName);
136
+ try {
137
+ return await uploadFn.call(fsApi, filePath, remotePath);
138
+ }
139
+ finally {
140
+ await promises_1.default.unlink(filePath).catch(() => undefined);
141
+ await promises_1.default.rmdir(dir).catch(() => undefined);
142
+ }
143
+ };
144
+ exports.uploadSandboxFileFromContent = uploadSandboxFileFromContent;
@@ -98,13 +98,11 @@ class UploadFile {
98
98
  const identifierType = this.getNodeParameter('identifierType', i);
99
99
  const remotePath = this.getNodeParameter('remotePath', i);
100
100
  const fileName = this.getNodeParameter('fileName', i);
101
- const contentType = this.getNodeParameter('contentType', i);
102
101
  const content = this.getNodeParameter('content', i);
103
102
  const sandbox = identifierType === 'name'
104
103
  ? await (0, daytonaClient_1.getSandboxByName)(client, identifier)
105
104
  : await (0, daytonaClient_1.getSandbox)(client, identifier);
106
- const file = (0, daytonaClient_1.createSandboxFile)(content, fileName, contentType);
107
- const result = await (0, daytonaClient_1.uploadSandboxFile)(sandbox, remotePath, file);
105
+ const result = await (0, daytonaClient_1.uploadSandboxFileFromContent)(sandbox, remotePath, content, fileName);
108
106
  returnData.push({
109
107
  json: {
110
108
  identifier,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-daytona-tool",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "n8n community nodes for running code in Daytona sandboxes.",
5
5
  "keywords": [
6
6
  "n8n-community-node-package",