@frogbotai/piece-file-helper 0.21.0 → 0.23.0
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.
- package/README.md +23 -0
- package/dist/actions.d.ts +286 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +185 -0
- package/dist/actions.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +14 -0
- package/dist/config.js.map +1 -0
- package/dist/files.d.ts +27 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +72 -0
- package/dist/files.js.map +1 -0
- package/dist/index.d.ts +265 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -38
- package/dist/index.js.map +1 -1
- package/package.json +10 -7
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# `@frogbotai/piece-file-helper`
|
|
2
|
+
|
|
3
|
+
Create, inspect, convert, compress, and extract files stored by FrogBot.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createFileHelper } from '@frogbotai/piece-file-helper';
|
|
9
|
+
|
|
10
|
+
export const fileHelper = createFileHelper();
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Actions
|
|
14
|
+
|
|
15
|
+
| Upstream action slug | Previous wrapper export | Native action | Notes |
|
|
16
|
+
| ---------------------- | ----------------------- | -------------------- | ------------------------------------------ |
|
|
17
|
+
| `read_file` | `readFile` | `readFile` | Reads text or Base64 from a FrogBot file. |
|
|
18
|
+
| `createFile` | `createFile` | `createFile` | |
|
|
19
|
+
| `change_file_encoding` | `changeFileEncoding` | `changeFileEncoding` | |
|
|
20
|
+
| `checkFileType` | `checkFileType` | `checkFileType` | |
|
|
21
|
+
| `zipFiles` | `zipFiles` | `zipFiles` | Supports ZipCrypto and AES-256 passwords. |
|
|
22
|
+
| `unzipFile` | `unzipFile` | `unzipFile` | Stores each extracted non-directory entry. |
|
|
23
|
+
| `get_file_name` | `getFileName` | `getFileName` | |
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import type { PieceRunArgs } from 'frogbot/pieces';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { savedFile } from './files.js';
|
|
4
|
+
type RunArgs<T extends z.ZodType> = PieceRunArgs<z.output<T>, object, undefined>;
|
|
5
|
+
declare const createFileInput: z.ZodObject<{
|
|
6
|
+
content: z.ZodString;
|
|
7
|
+
fileName: z.ZodString;
|
|
8
|
+
encoding: z.ZodDefault<z.ZodEnum<{
|
|
9
|
+
ascii: "ascii";
|
|
10
|
+
utf8: "utf8";
|
|
11
|
+
utf16le: "utf16le";
|
|
12
|
+
ucs2: "ucs2";
|
|
13
|
+
base64: "base64";
|
|
14
|
+
base64url: "base64url";
|
|
15
|
+
latin1: "latin1";
|
|
16
|
+
binary: "binary";
|
|
17
|
+
hex: "hex";
|
|
18
|
+
}>>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
declare const readFileInput: z.ZodObject<{
|
|
21
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
22
|
+
format: z.ZodEnum<{
|
|
23
|
+
base64: "base64";
|
|
24
|
+
text: "text";
|
|
25
|
+
}>;
|
|
26
|
+
}, z.core.$strip>;
|
|
27
|
+
declare const getFileNameInput: z.ZodObject<{
|
|
28
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
declare const checkFileTypeInput: z.ZodObject<{
|
|
31
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
32
|
+
mimeType: z.ZodString;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
declare const changeFileEncodingInput: z.ZodObject<{
|
|
35
|
+
inputFile: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
36
|
+
inputEncoding: z.ZodEnum<{
|
|
37
|
+
ascii: "ascii";
|
|
38
|
+
utf8: "utf8";
|
|
39
|
+
utf16le: "utf16le";
|
|
40
|
+
ucs2: "ucs2";
|
|
41
|
+
base64: "base64";
|
|
42
|
+
base64url: "base64url";
|
|
43
|
+
latin1: "latin1";
|
|
44
|
+
binary: "binary";
|
|
45
|
+
hex: "hex";
|
|
46
|
+
}>;
|
|
47
|
+
outputFileName: z.ZodString;
|
|
48
|
+
outputEncoding: z.ZodEnum<{
|
|
49
|
+
ascii: "ascii";
|
|
50
|
+
utf8: "utf8";
|
|
51
|
+
utf16le: "utf16le";
|
|
52
|
+
ucs2: "ucs2";
|
|
53
|
+
base64: "base64";
|
|
54
|
+
base64url: "base64url";
|
|
55
|
+
latin1: "latin1";
|
|
56
|
+
binary: "binary";
|
|
57
|
+
hex: "hex";
|
|
58
|
+
}>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
declare const zipFilesInput: z.ZodObject<{
|
|
61
|
+
files: z.ZodArray<z.ZodObject<{
|
|
62
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
63
|
+
filePath: z.ZodOptional<z.ZodString>;
|
|
64
|
+
}, z.core.$strip>>;
|
|
65
|
+
outputFileName: z.ZodString;
|
|
66
|
+
usePassword: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
67
|
+
passwordOptions: z.ZodOptional<z.ZodObject<{
|
|
68
|
+
password: z.ZodString;
|
|
69
|
+
encryptionMethod: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
70
|
+
zipcrypto: "zipcrypto";
|
|
71
|
+
"aes-256": "aes-256";
|
|
72
|
+
}>>>;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
declare const unzipFileInput: z.ZodObject<{
|
|
76
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
77
|
+
maxResults: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
78
|
+
usePassword: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
79
|
+
passwordOptions: z.ZodPipe<z.ZodOptional<z.ZodObject<{
|
|
80
|
+
password: z.ZodString;
|
|
81
|
+
encryptionMethod: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
82
|
+
zipcrypto: "zipcrypto";
|
|
83
|
+
"aes-256": "aes-256";
|
|
84
|
+
}>>>;
|
|
85
|
+
}, z.core.$strip>>, z.ZodTransform<{
|
|
86
|
+
password: string;
|
|
87
|
+
} | undefined, {
|
|
88
|
+
password: string;
|
|
89
|
+
encryptionMethod?: "zipcrypto" | "aes-256" | undefined;
|
|
90
|
+
} | undefined>>;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
export declare const createFile: {
|
|
93
|
+
slug: string;
|
|
94
|
+
label: string;
|
|
95
|
+
description: string;
|
|
96
|
+
input: z.ZodObject<{
|
|
97
|
+
content: z.ZodString;
|
|
98
|
+
fileName: z.ZodString;
|
|
99
|
+
encoding: z.ZodDefault<z.ZodEnum<{
|
|
100
|
+
ascii: "ascii";
|
|
101
|
+
utf8: "utf8";
|
|
102
|
+
utf16le: "utf16le";
|
|
103
|
+
ucs2: "ucs2";
|
|
104
|
+
base64: "base64";
|
|
105
|
+
base64url: "base64url";
|
|
106
|
+
latin1: "latin1";
|
|
107
|
+
binary: "binary";
|
|
108
|
+
hex: "hex";
|
|
109
|
+
}>>;
|
|
110
|
+
}, z.core.$strip>;
|
|
111
|
+
output: z.ZodObject<{
|
|
112
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
113
|
+
filename: z.ZodString;
|
|
114
|
+
url: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$strip>;
|
|
116
|
+
run({ input, req }: RunArgs<typeof createFileInput>): Promise<{
|
|
117
|
+
url?: string | undefined;
|
|
118
|
+
id: string | number;
|
|
119
|
+
filename: string;
|
|
120
|
+
}>;
|
|
121
|
+
};
|
|
122
|
+
export declare const readFile: {
|
|
123
|
+
slug: string;
|
|
124
|
+
label: string;
|
|
125
|
+
description: string;
|
|
126
|
+
input: z.ZodObject<{
|
|
127
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
128
|
+
format: z.ZodEnum<{
|
|
129
|
+
base64: "base64";
|
|
130
|
+
text: "text";
|
|
131
|
+
}>;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
output: z.ZodUnion<readonly [z.ZodObject<{
|
|
134
|
+
text: z.ZodString;
|
|
135
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
136
|
+
base64: z.ZodString;
|
|
137
|
+
base64WithMimeType: z.ZodString;
|
|
138
|
+
}, z.core.$strip>]>;
|
|
139
|
+
run({ input, req }: RunArgs<typeof readFileInput>): Promise<{
|
|
140
|
+
text: string;
|
|
141
|
+
base64?: undefined;
|
|
142
|
+
base64WithMimeType?: undefined;
|
|
143
|
+
} | {
|
|
144
|
+
base64: string;
|
|
145
|
+
base64WithMimeType: string;
|
|
146
|
+
text?: undefined;
|
|
147
|
+
}>;
|
|
148
|
+
};
|
|
149
|
+
export declare const getFileName: {
|
|
150
|
+
slug: string;
|
|
151
|
+
label: string;
|
|
152
|
+
description: string;
|
|
153
|
+
input: z.ZodObject<{
|
|
154
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
output: z.ZodObject<{
|
|
157
|
+
fileName: z.ZodString;
|
|
158
|
+
}, z.core.$strip>;
|
|
159
|
+
run({ input, req }: RunArgs<typeof getFileNameInput>): Promise<{
|
|
160
|
+
fileName: string;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
export declare const checkFileType: {
|
|
164
|
+
slug: string;
|
|
165
|
+
label: string;
|
|
166
|
+
description: string;
|
|
167
|
+
input: z.ZodObject<{
|
|
168
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
169
|
+
mimeType: z.ZodString;
|
|
170
|
+
}, z.core.$strip>;
|
|
171
|
+
output: z.ZodObject<{
|
|
172
|
+
mimeType: z.ZodString;
|
|
173
|
+
isMatch: z.ZodBoolean;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
run({ input, req }: RunArgs<typeof checkFileTypeInput>): Promise<{
|
|
176
|
+
mimeType: string;
|
|
177
|
+
isMatch: boolean;
|
|
178
|
+
}>;
|
|
179
|
+
};
|
|
180
|
+
export declare const changeFileEncoding: {
|
|
181
|
+
slug: string;
|
|
182
|
+
label: string;
|
|
183
|
+
description: string;
|
|
184
|
+
input: z.ZodObject<{
|
|
185
|
+
inputFile: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
186
|
+
inputEncoding: z.ZodEnum<{
|
|
187
|
+
ascii: "ascii";
|
|
188
|
+
utf8: "utf8";
|
|
189
|
+
utf16le: "utf16le";
|
|
190
|
+
ucs2: "ucs2";
|
|
191
|
+
base64: "base64";
|
|
192
|
+
base64url: "base64url";
|
|
193
|
+
latin1: "latin1";
|
|
194
|
+
binary: "binary";
|
|
195
|
+
hex: "hex";
|
|
196
|
+
}>;
|
|
197
|
+
outputFileName: z.ZodString;
|
|
198
|
+
outputEncoding: z.ZodEnum<{
|
|
199
|
+
ascii: "ascii";
|
|
200
|
+
utf8: "utf8";
|
|
201
|
+
utf16le: "utf16le";
|
|
202
|
+
ucs2: "ucs2";
|
|
203
|
+
base64: "base64";
|
|
204
|
+
base64url: "base64url";
|
|
205
|
+
latin1: "latin1";
|
|
206
|
+
binary: "binary";
|
|
207
|
+
hex: "hex";
|
|
208
|
+
}>;
|
|
209
|
+
}, z.core.$strip>;
|
|
210
|
+
output: z.ZodObject<{
|
|
211
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
212
|
+
filename: z.ZodString;
|
|
213
|
+
url: z.ZodOptional<z.ZodString>;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
run({ input, req }: RunArgs<typeof changeFileEncodingInput>): Promise<{
|
|
216
|
+
url?: string | undefined;
|
|
217
|
+
id: string | number;
|
|
218
|
+
filename: string;
|
|
219
|
+
}>;
|
|
220
|
+
};
|
|
221
|
+
export declare const zipFiles: {
|
|
222
|
+
slug: string;
|
|
223
|
+
label: string;
|
|
224
|
+
description: string;
|
|
225
|
+
input: z.ZodObject<{
|
|
226
|
+
files: z.ZodArray<z.ZodObject<{
|
|
227
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
228
|
+
filePath: z.ZodOptional<z.ZodString>;
|
|
229
|
+
}, z.core.$strip>>;
|
|
230
|
+
outputFileName: z.ZodString;
|
|
231
|
+
usePassword: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
232
|
+
passwordOptions: z.ZodOptional<z.ZodObject<{
|
|
233
|
+
password: z.ZodString;
|
|
234
|
+
encryptionMethod: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
235
|
+
zipcrypto: "zipcrypto";
|
|
236
|
+
"aes-256": "aes-256";
|
|
237
|
+
}>>>;
|
|
238
|
+
}, z.core.$strip>>;
|
|
239
|
+
}, z.core.$strip>;
|
|
240
|
+
output: z.ZodObject<{
|
|
241
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
242
|
+
filename: z.ZodString;
|
|
243
|
+
url: z.ZodOptional<z.ZodString>;
|
|
244
|
+
}, z.core.$strip>;
|
|
245
|
+
run({ input, req }: RunArgs<typeof zipFilesInput>): Promise<{
|
|
246
|
+
url?: string | undefined;
|
|
247
|
+
id: string | number;
|
|
248
|
+
filename: string;
|
|
249
|
+
}>;
|
|
250
|
+
};
|
|
251
|
+
export declare const unzipFile: {
|
|
252
|
+
slug: string;
|
|
253
|
+
label: string;
|
|
254
|
+
description: string;
|
|
255
|
+
input: z.ZodObject<{
|
|
256
|
+
file: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
257
|
+
maxResults: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
258
|
+
usePassword: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
259
|
+
passwordOptions: z.ZodPipe<z.ZodOptional<z.ZodObject<{
|
|
260
|
+
password: z.ZodString;
|
|
261
|
+
encryptionMethod: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
262
|
+
zipcrypto: "zipcrypto";
|
|
263
|
+
"aes-256": "aes-256";
|
|
264
|
+
}>>>;
|
|
265
|
+
}, z.core.$strip>>, z.ZodTransform<{
|
|
266
|
+
password: string;
|
|
267
|
+
} | undefined, {
|
|
268
|
+
password: string;
|
|
269
|
+
encryptionMethod?: "zipcrypto" | "aes-256" | undefined;
|
|
270
|
+
} | undefined>>;
|
|
271
|
+
}, z.core.$strip>;
|
|
272
|
+
output: z.ZodArray<z.ZodObject<{
|
|
273
|
+
file: z.ZodObject<{
|
|
274
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
275
|
+
filename: z.ZodString;
|
|
276
|
+
url: z.ZodOptional<z.ZodString>;
|
|
277
|
+
}, z.core.$strip>;
|
|
278
|
+
filePath: z.ZodString;
|
|
279
|
+
}, z.core.$strip>>;
|
|
280
|
+
run({ input, req }: RunArgs<typeof unzipFileInput>): Promise<{
|
|
281
|
+
file: z.output<typeof savedFile>;
|
|
282
|
+
filePath: string;
|
|
283
|
+
}[]>;
|
|
284
|
+
};
|
|
285
|
+
export {};
|
|
286
|
+
//# sourceMappingURL=actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAoB,SAAS,EAAY,MAAM,YAAY,CAAC;AAEnE,KAAK,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,IAAI,YAA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CAyBxE,CAAC"}
|
package/dist/actions.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { BlobReader, BlobWriter, getMimeType, ZipReader, ZipWriter } from '@zip.js/zip.js';
|
|
2
|
+
import { lookup } from 'mime-types';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { encoding } from './config.js';
|
|
5
|
+
import { fileId, loadFile, savedFile, saveFile } from './files.js';
|
|
6
|
+
const passwordOptions = z
|
|
7
|
+
.object({
|
|
8
|
+
password: z.string().min(1).meta({ label: 'Password' }),
|
|
9
|
+
encryptionMethod: z.enum(['zipcrypto', 'aes-256']).default('zipcrypto').optional(),
|
|
10
|
+
})
|
|
11
|
+
.optional();
|
|
12
|
+
const createFileInput = z.object({
|
|
13
|
+
content: z.string().meta({ label: 'Content' }),
|
|
14
|
+
fileName: z.string().min(1).meta({ label: 'File name' }),
|
|
15
|
+
encoding: encoding.default('utf8').meta({ label: 'Encoding' }),
|
|
16
|
+
});
|
|
17
|
+
const readFileInput = z.object({
|
|
18
|
+
file: fileId.meta({ label: 'File' }),
|
|
19
|
+
format: z.enum(['text', 'base64']).meta({ label: 'Output format' }),
|
|
20
|
+
});
|
|
21
|
+
const getFileNameInput = z.object({ file: fileId.meta({ label: 'File' }) });
|
|
22
|
+
const checkFileTypeInput = z.object({
|
|
23
|
+
file: fileId.meta({ label: 'File to check' }),
|
|
24
|
+
mimeType: z.string().min(1).meta({ label: 'MIME type' }),
|
|
25
|
+
});
|
|
26
|
+
const changeFileEncodingInput = z.object({
|
|
27
|
+
inputFile: fileId.meta({ label: 'Source file' }),
|
|
28
|
+
inputEncoding: encoding.meta({ label: 'Source encoding' }),
|
|
29
|
+
outputFileName: z.string().min(1).meta({ label: 'Output file name' }),
|
|
30
|
+
outputEncoding: encoding.meta({ label: 'Output encoding' }),
|
|
31
|
+
});
|
|
32
|
+
const zipFilesInput = z.object({
|
|
33
|
+
files: z.array(z.object({ file: fileId, filePath: z.string().min(1).optional() })).min(1),
|
|
34
|
+
outputFileName: z.string().min(1).meta({ label: 'Name of zipped file' }),
|
|
35
|
+
usePassword: z.boolean().default(false).optional(),
|
|
36
|
+
passwordOptions,
|
|
37
|
+
});
|
|
38
|
+
const unzipFileInput = z.object({
|
|
39
|
+
file: fileId.meta({ label: 'ZIP file' }),
|
|
40
|
+
maxResults: z.number().int().nonnegative().default(0).optional(),
|
|
41
|
+
usePassword: z.boolean().default(false).optional(),
|
|
42
|
+
passwordOptions: passwordOptions.transform((value) => value ? { password: value.password } : undefined),
|
|
43
|
+
});
|
|
44
|
+
export const createFile = {
|
|
45
|
+
slug: 'createFile',
|
|
46
|
+
label: 'Create file',
|
|
47
|
+
description: 'Create a file from content',
|
|
48
|
+
input: createFileInput,
|
|
49
|
+
output: savedFile,
|
|
50
|
+
async run({ input, req }) {
|
|
51
|
+
const data = Buffer.from(input.content, input.encoding);
|
|
52
|
+
return saveFile({ req, data, filename: input.fileName });
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export const readFile = {
|
|
56
|
+
slug: 'readFile',
|
|
57
|
+
label: 'Read file',
|
|
58
|
+
description: 'Read a file as text or Base64',
|
|
59
|
+
input: readFileInput,
|
|
60
|
+
output: z.union([
|
|
61
|
+
z.object({ text: z.string() }),
|
|
62
|
+
z.object({ base64: z.string(), base64WithMimeType: z.string() }),
|
|
63
|
+
]),
|
|
64
|
+
async run({ input, req }) {
|
|
65
|
+
const file = await loadFile({ req, id: input.file });
|
|
66
|
+
if (input.format === 'text')
|
|
67
|
+
return { text: file.data.toString('utf8') };
|
|
68
|
+
const base64 = file.data.toString('base64');
|
|
69
|
+
return { base64, base64WithMimeType: `data:${file.mimeType};base64,${base64}` };
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
export const getFileName = {
|
|
73
|
+
slug: 'getFileName',
|
|
74
|
+
label: 'Get file name',
|
|
75
|
+
description: 'Get the name of a file',
|
|
76
|
+
input: getFileNameInput,
|
|
77
|
+
output: z.object({ fileName: z.string() }),
|
|
78
|
+
async run({ input, req }) {
|
|
79
|
+
const file = await loadFile({ req, id: input.file });
|
|
80
|
+
return { fileName: file.filename };
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
export const checkFileType = {
|
|
84
|
+
slug: 'checkFileType',
|
|
85
|
+
label: 'Check file type',
|
|
86
|
+
description: 'Check whether a file matches a MIME type',
|
|
87
|
+
input: checkFileTypeInput,
|
|
88
|
+
output: z.object({ mimeType: z.string(), isMatch: z.boolean() }),
|
|
89
|
+
async run({ input, req }) {
|
|
90
|
+
const file = await loadFile({ req, id: input.file });
|
|
91
|
+
const mimeType = lookup(file.filename) || 'application/octet-stream';
|
|
92
|
+
return { mimeType, isMatch: mimeType === input.mimeType };
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
export const changeFileEncoding = {
|
|
96
|
+
slug: 'changeFileEncoding',
|
|
97
|
+
label: 'Change file encoding',
|
|
98
|
+
description: 'Change the encoding of a file',
|
|
99
|
+
input: changeFileEncodingInput,
|
|
100
|
+
output: savedFile,
|
|
101
|
+
async run({ input, req }) {
|
|
102
|
+
const file = await loadFile({ req, id: input.inputFile });
|
|
103
|
+
const decoded = file.data.toString(input.inputEncoding);
|
|
104
|
+
const data = Buffer.from(decoded, input.outputEncoding);
|
|
105
|
+
return saveFile({ req, data, filename: input.outputFileName });
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
export const zipFiles = {
|
|
109
|
+
slug: 'zipFiles',
|
|
110
|
+
label: 'Zip files',
|
|
111
|
+
description: 'Create a compressed ZIP file from one or more files',
|
|
112
|
+
input: zipFilesInput,
|
|
113
|
+
output: savedFile,
|
|
114
|
+
async run({ input, req }) {
|
|
115
|
+
const writer = new BlobWriter('application/zip');
|
|
116
|
+
const zip = new ZipWriter(writer);
|
|
117
|
+
const options = {};
|
|
118
|
+
if (input.usePassword) {
|
|
119
|
+
if (!input.passwordOptions?.password)
|
|
120
|
+
throw new Error('A password is required.');
|
|
121
|
+
options.password = input.passwordOptions.password;
|
|
122
|
+
if (input.passwordOptions.encryptionMethod === 'aes-256')
|
|
123
|
+
options.encryptionStrength = 3;
|
|
124
|
+
else
|
|
125
|
+
options.zipCrypto = true;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
for (const item of input.files) {
|
|
129
|
+
const file = await loadFile({ req, id: item.file });
|
|
130
|
+
const path = item.filePath ?? file.filename;
|
|
131
|
+
await zip.add(path, new BlobReader(new Blob([file.data])), options);
|
|
132
|
+
}
|
|
133
|
+
await zip.close();
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
await zip.close().catch(() => undefined);
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
const data = Buffer.from(await (await writer.getData()).arrayBuffer());
|
|
140
|
+
return saveFile({ req, data, filename: input.outputFileName, mimeType: 'application/zip' });
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
export const unzipFile = {
|
|
144
|
+
slug: 'unzipFile',
|
|
145
|
+
label: 'Unzip file',
|
|
146
|
+
description: 'Extract files from a compressed ZIP file',
|
|
147
|
+
input: unzipFileInput,
|
|
148
|
+
output: z.array(z.object({ file: savedFile, filePath: z.string() })),
|
|
149
|
+
async run({ input, req }) {
|
|
150
|
+
const file = await loadFile({ req, id: input.file });
|
|
151
|
+
const reader = new ZipReader(new BlobReader(new Blob([file.data])));
|
|
152
|
+
try {
|
|
153
|
+
const entries = await reader.getEntries();
|
|
154
|
+
const maxResults = input.maxResults ?? 0;
|
|
155
|
+
if (maxResults !== 0 && entries.length > maxResults) {
|
|
156
|
+
throw new Error(`Zip file contains more entries than allowed: ${entries.length}`);
|
|
157
|
+
}
|
|
158
|
+
if (input.usePassword && !input.passwordOptions?.password) {
|
|
159
|
+
throw new Error('A password is required.');
|
|
160
|
+
}
|
|
161
|
+
const results = [];
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
if (entry.directory)
|
|
164
|
+
continue;
|
|
165
|
+
const blob = await entry.getData(new BlobWriter(getMimeType(entry.filename)), {
|
|
166
|
+
password: input.usePassword ? input.passwordOptions?.password : undefined,
|
|
167
|
+
});
|
|
168
|
+
const data = Buffer.from(await blob.arrayBuffer());
|
|
169
|
+
const filename = entry.filename.split('/').pop() || entry.filename;
|
|
170
|
+
const saved = await saveFile({
|
|
171
|
+
req,
|
|
172
|
+
data,
|
|
173
|
+
filename,
|
|
174
|
+
mimeType: getMimeType(entry.filename),
|
|
175
|
+
});
|
|
176
|
+
results.push({ file: saved, filePath: entry.filename });
|
|
177
|
+
}
|
|
178
|
+
return results;
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
await reader.close();
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3F,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAInE,MAAM,eAAe,GAAG,CAAC;KACtB,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IACvD,gBAAgB,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE;CACnF,CAAC;KACD,QAAQ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AAS;oBAAE,SAAS;gBAE9B,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE;oBAC5E,QAAQ,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;iBAC1E,CAAC,CAAC;gBACH,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;gBACnD,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,KAAK,CAAC,QAAQ,CAAC;gBACnE,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC;oBAC3B,GAAG;oBACH,IAAI;oBACJ,QAAQ;oBACR,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC;iBACtC,CAAC,CAAC;gBAEH,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC1D,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;CACF,CAAC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const encodings: readonly ["ascii", "utf8", "utf16le", "ucs2", "base64", "base64url", "latin1", "binary", "hex"];
|
|
3
|
+
export declare const encoding: z.ZodEnum<{
|
|
4
|
+
ascii: "ascii";
|
|
5
|
+
utf8: "utf8";
|
|
6
|
+
utf16le: "utf16le";
|
|
7
|
+
ucs2: "ucs2";
|
|
8
|
+
base64: "base64";
|
|
9
|
+
base64url: "base64url";
|
|
10
|
+
latin1: "latin1";
|
|
11
|
+
binary: "binary";
|
|
12
|
+
hex: "hex";
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,SAAS,iGAUZ,CAAC;AAEX,eAAO,MAAM,QAAQ;;;;;;;;;;EAAoB,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO;IACP,MAAM;IACN,SAAS;IACT,MAAM;IACN,QAAQ;IACR,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,KAAK;CACG,CAAC;AAEX,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC"}
|
package/dist/files.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { FrogbotRequest } from 'frogbot';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const fileId: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
4
|
+
export declare const savedFile: z.ZodObject<{
|
|
5
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
6
|
+
filename: z.ZodString;
|
|
7
|
+
url: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export declare function loadFile({ req, id }: {
|
|
10
|
+
req: FrogbotRequest;
|
|
11
|
+
id: string | number;
|
|
12
|
+
}): Promise<{
|
|
13
|
+
data: Buffer;
|
|
14
|
+
filename: string;
|
|
15
|
+
mimeType: string;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function saveFile({ req, data, filename, mimeType, }: {
|
|
18
|
+
req: FrogbotRequest;
|
|
19
|
+
data: Buffer;
|
|
20
|
+
filename: string;
|
|
21
|
+
mimeType?: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
url?: string | undefined;
|
|
24
|
+
id: string | number;
|
|
25
|
+
filename: string;
|
|
26
|
+
}>;
|
|
27
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,MAAM,iDAAoC,CAAC;AAExD,eAAO,MAAM,SAAS;;;;iBAIpB,CAAC;AAUH,wBAAsB,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE;IAAE,GAAG,EAAE,cAAc,CAAC;IAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE;;;;GA6CvF;AAED,wBAAsB,QAAQ,CAAC,EAC7B,GAAG,EACH,IAAI,EACJ,QAAQ,EACR,QAAQ,GACT,EAAE;IACD,GAAG,EAAE,cAAc,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;;;;GAsBA"}
|
package/dist/files.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { lookup } from 'mime-types';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export const fileId = z.union([z.string(), z.number()]);
|
|
4
|
+
export const savedFile = z.object({
|
|
5
|
+
id: z.union([z.string(), z.number()]),
|
|
6
|
+
filename: z.string(),
|
|
7
|
+
url: z.string().optional(),
|
|
8
|
+
});
|
|
9
|
+
function resolveMimeType(value, filename) {
|
|
10
|
+
if (typeof value === 'string' && value)
|
|
11
|
+
return value;
|
|
12
|
+
const detected = lookup(filename);
|
|
13
|
+
return typeof detected === 'string' ? detected : 'application/octet-stream';
|
|
14
|
+
}
|
|
15
|
+
export async function loadFile({ req, id }) {
|
|
16
|
+
const collection = req.frogbot.config.files?.slug;
|
|
17
|
+
if (!collection)
|
|
18
|
+
throw new Error('File Helper requires a configured files collection.');
|
|
19
|
+
const doc = await req.frogbot.findByID({
|
|
20
|
+
collection,
|
|
21
|
+
id,
|
|
22
|
+
depth: 0,
|
|
23
|
+
req,
|
|
24
|
+
overrideAccess: false,
|
|
25
|
+
});
|
|
26
|
+
if (typeof doc.url !== 'string')
|
|
27
|
+
throw new Error(`File '${id}' is unavailable.`);
|
|
28
|
+
const config = await req.frogbot.config._internal.payloadConfig;
|
|
29
|
+
const base = new URL(config.serverURL || req.url);
|
|
30
|
+
const url = new URL(doc.url, base);
|
|
31
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password) {
|
|
32
|
+
throw new Error('Invalid file URL.');
|
|
33
|
+
}
|
|
34
|
+
const headers = new Headers();
|
|
35
|
+
if (url.origin === base.origin) {
|
|
36
|
+
for (const name of ['authorization', 'cookie']) {
|
|
37
|
+
const value = req.headers.get(name);
|
|
38
|
+
if (value)
|
|
39
|
+
headers.set(name, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const response = await fetch(url, {
|
|
43
|
+
headers,
|
|
44
|
+
signal: req.signal ?? undefined,
|
|
45
|
+
redirect: 'error',
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok)
|
|
48
|
+
throw new Error(`File '${id}' is unavailable (${response.status}).`);
|
|
49
|
+
const filename = String(doc.filename ?? 'file');
|
|
50
|
+
const mimeType = resolveMimeType(doc.mimeType, filename);
|
|
51
|
+
return { data: Buffer.from(await response.arrayBuffer()), filename, mimeType };
|
|
52
|
+
}
|
|
53
|
+
export async function saveFile({ req, data, filename, mimeType, }) {
|
|
54
|
+
const collection = req.frogbot.config.files?.slug;
|
|
55
|
+
if (!collection)
|
|
56
|
+
throw new Error('File Helper requires a configured files collection.');
|
|
57
|
+
req.signal?.throwIfAborted();
|
|
58
|
+
const resolvedMimeType = resolveMimeType(mimeType, filename);
|
|
59
|
+
const doc = await req.frogbot.create({
|
|
60
|
+
collection,
|
|
61
|
+
data: {},
|
|
62
|
+
req,
|
|
63
|
+
overrideAccess: false,
|
|
64
|
+
file: { data, name: filename, mimetype: resolvedMimeType, size: data.length },
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
id: doc.id,
|
|
68
|
+
filename,
|
|
69
|
+
...(typeof doc.url === 'string' ? { url: doc.url } : {}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../src/files.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACrC,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;IACpB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC3B,CAAC,CAAC;AAEH,SAAS,eAAe,CAAC,KAAc,EAAE,QAAgB;IACvD,IAAI,OAAO,KAAK,KAAK,QAA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,CAAC;IAE7B,MAAM,gBAAgB,GAAG,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAE7D,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC;QACnC,UAAU;QACV,IAAI,EAAE,EAAE;QACR,GAAG;QACH,cAAc,EAAE,KAAK;QACrB,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;KAC9E,CAAC,CAAC;IAEH,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,QAAQ;QACR,GAAG,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,266 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
export declare const createFileHelper: import("frogbot").PieceFactory<{
|
|
2
|
+
readonly slug: "file-helper";
|
|
3
|
+
readonly label: "Files Helper";
|
|
4
|
+
readonly admin: {
|
|
5
|
+
readonly description: "Create, inspect, convert, compress, and extract files";
|
|
6
|
+
readonly group: "Core";
|
|
7
|
+
};
|
|
8
|
+
readonly actions: readonly [{
|
|
9
|
+
slug: string;
|
|
10
|
+
label: string;
|
|
11
|
+
description: string;
|
|
12
|
+
input: import("zod").ZodObject<{
|
|
13
|
+
file: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
14
|
+
format: import("zod").ZodEnum<{
|
|
15
|
+
base64: "base64";
|
|
16
|
+
text: "text";
|
|
17
|
+
}>;
|
|
18
|
+
}, import("zod/v4/core").$strip>;
|
|
19
|
+
output: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
|
|
20
|
+
text: import("zod").ZodString;
|
|
21
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
22
|
+
base64: import("zod").ZodString;
|
|
23
|
+
base64WithMimeType: import("zod").ZodString;
|
|
24
|
+
}, import("zod/v4/core").$strip>]>;
|
|
25
|
+
run({ input, req }: {
|
|
26
|
+
input: {
|
|
27
|
+
file: string | number;
|
|
28
|
+
format: "base64" | "text";
|
|
29
|
+
};
|
|
30
|
+
client: undefined;
|
|
31
|
+
options: object;
|
|
32
|
+
req: import("frogbot").FrogbotRequest;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
text: string;
|
|
35
|
+
base64?: undefined;
|
|
36
|
+
base64WithMimeType?: undefined;
|
|
37
|
+
} | {
|
|
38
|
+
base64: string;
|
|
39
|
+
base64WithMimeType: string;
|
|
40
|
+
text?: undefined;
|
|
41
|
+
}>;
|
|
42
|
+
}, {
|
|
43
|
+
slug: string;
|
|
44
|
+
label: string;
|
|
45
|
+
description: string;
|
|
46
|
+
input: import("zod").ZodObject<{
|
|
47
|
+
content: import("zod").ZodString;
|
|
48
|
+
fileName: import("zod").ZodString;
|
|
49
|
+
encoding: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
50
|
+
ascii: "ascii";
|
|
51
|
+
utf8: "utf8";
|
|
52
|
+
utf16le: "utf16le";
|
|
53
|
+
ucs2: "ucs2";
|
|
54
|
+
base64: "base64";
|
|
55
|
+
base64url: "base64url";
|
|
56
|
+
latin1: "latin1";
|
|
57
|
+
binary: "binary";
|
|
58
|
+
hex: "hex";
|
|
59
|
+
}>>;
|
|
60
|
+
}, import("zod/v4/core").$strip>;
|
|
61
|
+
output: import("zod").ZodObject<{
|
|
62
|
+
id: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
63
|
+
filename: import("zod").ZodString;
|
|
64
|
+
url: import("zod").ZodOptional<import("zod").ZodString>;
|
|
65
|
+
}, import("zod/v4/core").$strip>;
|
|
66
|
+
run({ input, req }: {
|
|
67
|
+
input: {
|
|
68
|
+
content: string;
|
|
69
|
+
fileName: string;
|
|
70
|
+
encoding: "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
71
|
+
};
|
|
72
|
+
client: undefined;
|
|
73
|
+
options: object;
|
|
74
|
+
req: import("frogbot").FrogbotRequest;
|
|
75
|
+
}): Promise<{
|
|
76
|
+
url?: string | undefined;
|
|
77
|
+
id: string | number;
|
|
78
|
+
filename: string;
|
|
79
|
+
}>;
|
|
80
|
+
}, {
|
|
81
|
+
slug: string;
|
|
82
|
+
label: string;
|
|
83
|
+
description: string;
|
|
84
|
+
input: import("zod").ZodObject<{
|
|
85
|
+
inputFile: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
86
|
+
inputEncoding: import("zod").ZodEnum<{
|
|
87
|
+
ascii: "ascii";
|
|
88
|
+
utf8: "utf8";
|
|
89
|
+
utf16le: "utf16le";
|
|
90
|
+
ucs2: "ucs2";
|
|
91
|
+
base64: "base64";
|
|
92
|
+
base64url: "base64url";
|
|
93
|
+
latin1: "latin1";
|
|
94
|
+
binary: "binary";
|
|
95
|
+
hex: "hex";
|
|
96
|
+
}>;
|
|
97
|
+
outputFileName: import("zod").ZodString;
|
|
98
|
+
outputEncoding: import("zod").ZodEnum<{
|
|
99
|
+
ascii: "ascii";
|
|
100
|
+
utf8: "utf8";
|
|
101
|
+
utf16le: "utf16le";
|
|
102
|
+
ucs2: "ucs2";
|
|
103
|
+
base64: "base64";
|
|
104
|
+
base64url: "base64url";
|
|
105
|
+
latin1: "latin1";
|
|
106
|
+
binary: "binary";
|
|
107
|
+
hex: "hex";
|
|
108
|
+
}>;
|
|
109
|
+
}, import("zod/v4/core").$strip>;
|
|
110
|
+
output: import("zod").ZodObject<{
|
|
111
|
+
id: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
112
|
+
filename: import("zod").ZodString;
|
|
113
|
+
url: import("zod").ZodOptional<import("zod").ZodString>;
|
|
114
|
+
}, import("zod/v4/core").$strip>;
|
|
115
|
+
run({ input, req }: {
|
|
116
|
+
input: {
|
|
117
|
+
inputFile: string | number;
|
|
118
|
+
inputEncoding: "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
119
|
+
outputFileName: string;
|
|
120
|
+
outputEncoding: "ascii" | "utf8" | "utf16le" | "ucs2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
121
|
+
};
|
|
122
|
+
client: undefined;
|
|
123
|
+
options: object;
|
|
124
|
+
req: import("frogbot").FrogbotRequest;
|
|
125
|
+
}): Promise<{
|
|
126
|
+
url?: string | undefined;
|
|
127
|
+
id: string | number;
|
|
128
|
+
filename: string;
|
|
129
|
+
}>;
|
|
130
|
+
}, {
|
|
131
|
+
slug: string;
|
|
132
|
+
label: string;
|
|
133
|
+
description: string;
|
|
134
|
+
input: import("zod").ZodObject<{
|
|
135
|
+
file: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
136
|
+
mimeType: import("zod").ZodString;
|
|
137
|
+
}, import("zod/v4/core").$strip>;
|
|
138
|
+
output: import("zod").ZodObject<{
|
|
139
|
+
mimeType: import("zod").ZodString;
|
|
140
|
+
isMatch: import("zod").ZodBoolean;
|
|
141
|
+
}, import("zod/v4/core").$strip>;
|
|
142
|
+
run({ input, req }: {
|
|
143
|
+
input: {
|
|
144
|
+
file: string | number;
|
|
145
|
+
mimeType: string;
|
|
146
|
+
};
|
|
147
|
+
client: undefined;
|
|
148
|
+
options: object;
|
|
149
|
+
req: import("frogbot").FrogbotRequest;
|
|
150
|
+
}): Promise<{
|
|
151
|
+
mimeType: string;
|
|
152
|
+
isMatch: boolean;
|
|
153
|
+
}>;
|
|
154
|
+
}, {
|
|
155
|
+
slug: string;
|
|
156
|
+
label: string;
|
|
157
|
+
description: string;
|
|
158
|
+
input: import("zod").ZodObject<{
|
|
159
|
+
files: import("zod").ZodArray<import("zod").ZodObject<{
|
|
160
|
+
file: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
161
|
+
filePath: import("zod").ZodOptional<import("zod").ZodString>;
|
|
162
|
+
}, import("zod/v4/core").$strip>>;
|
|
163
|
+
outputFileName: import("zod").ZodString;
|
|
164
|
+
usePassword: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
165
|
+
passwordOptions: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
166
|
+
password: import("zod").ZodString;
|
|
167
|
+
encryptionMethod: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
168
|
+
zipcrypto: "zipcrypto";
|
|
169
|
+
"aes-256": "aes-256";
|
|
170
|
+
}>>>;
|
|
171
|
+
}, import("zod/v4/core").$strip>>;
|
|
172
|
+
}, import("zod/v4/core").$strip>;
|
|
173
|
+
output: import("zod").ZodObject<{
|
|
174
|
+
id: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
175
|
+
filename: import("zod").ZodString;
|
|
176
|
+
url: import("zod").ZodOptional<import("zod").ZodString>;
|
|
177
|
+
}, import("zod/v4/core").$strip>;
|
|
178
|
+
run({ input, req }: {
|
|
179
|
+
input: {
|
|
180
|
+
files: {
|
|
181
|
+
file: string | number;
|
|
182
|
+
filePath?: string | undefined;
|
|
183
|
+
}[];
|
|
184
|
+
outputFileName: string;
|
|
185
|
+
usePassword?: boolean | undefined;
|
|
186
|
+
passwordOptions?: {
|
|
187
|
+
password: string;
|
|
188
|
+
encryptionMethod?: "zipcrypto" | "aes-256" | undefined;
|
|
189
|
+
} | undefined;
|
|
190
|
+
};
|
|
191
|
+
client: undefined;
|
|
192
|
+
options: object;
|
|
193
|
+
req: import("frogbot").FrogbotRequest;
|
|
194
|
+
}): Promise<{
|
|
195
|
+
url?: string | undefined;
|
|
196
|
+
id: string | number;
|
|
197
|
+
filename: string;
|
|
198
|
+
}>;
|
|
199
|
+
}, {
|
|
200
|
+
slug: string;
|
|
201
|
+
label: string;
|
|
202
|
+
description: string;
|
|
203
|
+
input: import("zod").ZodObject<{
|
|
204
|
+
file: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
205
|
+
maxResults: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
|
|
206
|
+
usePassword: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
207
|
+
passwordOptions: import("zod").ZodPipe<import("zod").ZodOptional<import("zod").ZodObject<{
|
|
208
|
+
password: import("zod").ZodString;
|
|
209
|
+
encryptionMethod: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
210
|
+
zipcrypto: "zipcrypto";
|
|
211
|
+
"aes-256": "aes-256";
|
|
212
|
+
}>>>;
|
|
213
|
+
}, import("zod/v4/core").$strip>>, import("zod").ZodTransform<{
|
|
214
|
+
password: string;
|
|
215
|
+
} | undefined, {
|
|
216
|
+
password: string;
|
|
217
|
+
encryptionMethod?: "zipcrypto" | "aes-256" | undefined;
|
|
218
|
+
} | undefined>>;
|
|
219
|
+
}, import("zod/v4/core").$strip>;
|
|
220
|
+
output: import("zod").ZodArray<import("zod").ZodObject<{
|
|
221
|
+
file: import("zod").ZodObject<{
|
|
222
|
+
id: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
223
|
+
filename: import("zod").ZodString;
|
|
224
|
+
url: import("zod").ZodOptional<import("zod").ZodString>;
|
|
225
|
+
}, import("zod/v4/core").$strip>;
|
|
226
|
+
filePath: import("zod").ZodString;
|
|
227
|
+
}, import("zod/v4/core").$strip>>;
|
|
228
|
+
run({ input, req }: {
|
|
229
|
+
input: {
|
|
230
|
+
file: string | number;
|
|
231
|
+
passwordOptions: {
|
|
232
|
+
password: string;
|
|
233
|
+
} | undefined;
|
|
234
|
+
maxResults?: number | undefined;
|
|
235
|
+
usePassword?: boolean | undefined;
|
|
236
|
+
};
|
|
237
|
+
client: undefined;
|
|
238
|
+
options: object;
|
|
239
|
+
req: import("frogbot").FrogbotRequest;
|
|
240
|
+
}): Promise<{
|
|
241
|
+
file: import("zod").infer<typeof import("./files.js").savedFile>;
|
|
242
|
+
filePath: string;
|
|
243
|
+
}[]>;
|
|
244
|
+
}, {
|
|
245
|
+
slug: string;
|
|
246
|
+
label: string;
|
|
247
|
+
description: string;
|
|
248
|
+
input: import("zod").ZodObject<{
|
|
249
|
+
file: import("zod").ZodUnion<readonly [import("zod").ZodString, import("zod").ZodNumber]>;
|
|
250
|
+
}, import("zod/v4/core").$strip>;
|
|
251
|
+
output: import("zod").ZodObject<{
|
|
252
|
+
fileName: import("zod").ZodString;
|
|
253
|
+
}, import("zod/v4/core").$strip>;
|
|
254
|
+
run({ input, req }: {
|
|
255
|
+
input: {
|
|
256
|
+
file: string | number;
|
|
257
|
+
};
|
|
258
|
+
client: undefined;
|
|
259
|
+
options: object;
|
|
260
|
+
req: import("frogbot").FrogbotRequest;
|
|
261
|
+
}): Promise<{
|
|
262
|
+
fileName: string;
|
|
263
|
+
}>;
|
|
264
|
+
}];
|
|
265
|
+
}>;
|
|
20
266
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgB3B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,39 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export const
|
|
4
|
-
'
|
|
5
|
-
'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
config,
|
|
21
|
-
});
|
|
22
|
-
return Object.assign(piece, {
|
|
23
|
-
/** Read File: Read a file from the file system */
|
|
24
|
-
readFile: piece.tool('read_file'),
|
|
25
|
-
/** Create file: Create file from content */
|
|
26
|
-
createFile: piece.tool('createFile'),
|
|
27
|
-
/** Change File Encoding: Changes the encoding of a file */
|
|
28
|
-
changeFileEncoding: piece.tool('change_file_encoding'),
|
|
29
|
-
/** Check file type: Check MIME type of a file and filter based on selected types */
|
|
30
|
-
checkFileType: piece.tool('checkFileType'),
|
|
31
|
-
/** Zip Files: Create compressed zip file from one or many files */
|
|
32
|
-
zipFiles: piece.tool('zipFiles'),
|
|
33
|
-
/** Unzip File: Unzip compressed zip file */
|
|
34
|
-
unzipFile: piece.tool('unzipFile'),
|
|
35
|
-
/** Get File Name: Get the name of a file */
|
|
36
|
-
getFileName: piece.tool('get_file_name'),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
1
|
+
import { definePiece } from 'frogbot/pieces';
|
|
2
|
+
import { changeFileEncoding, checkFileType, createFile, getFileName, readFile, unzipFile, zipFiles, } from './actions.js';
|
|
3
|
+
export const createFileHelper = definePiece({
|
|
4
|
+
slug: 'file-helper',
|
|
5
|
+
label: 'Files Helper',
|
|
6
|
+
admin: {
|
|
7
|
+
description: 'Create, inspect, convert, compress, and extract files',
|
|
8
|
+
group: 'Core',
|
|
9
|
+
},
|
|
10
|
+
actions: [
|
|
11
|
+
readFile,
|
|
12
|
+
createFile,
|
|
13
|
+
changeFileEncoding,
|
|
14
|
+
checkFileType,
|
|
15
|
+
zipFiles,
|
|
16
|
+
unzipFile,
|
|
17
|
+
getFileName,
|
|
18
|
+
],
|
|
19
|
+
});
|
|
39
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,WAAW,EACX,QAAQ,EACR,SAAS,EACT,QAAQ,GACT,MAAM,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC;IAC1C,IAAI,EAAE,aAAa;IACnB,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE;QACL,WAAW,EAAE,uDAAuD;QACpE,KAAK,EAAE,MAAM;KACd;IACD,OAAO,EAAE;QACP,QAAQ;QACR,UAAU;QACV,kBAAkB;QAClB,aAAa;QACb,QAAQ;QACR,SAAS;QACT,WAAW;KACZ;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frogbotai/piece-file-helper",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.23.0",
|
|
4
|
+
"description": "file-helper tools for FrogBot.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Colby Gilbert",
|
|
7
7
|
"type": "module",
|
|
@@ -18,15 +18,18 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"sideEffects": false,
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@activepieces/piece-file-helper": "0.1.24"
|
|
23
|
-
},
|
|
24
21
|
"peerDependencies": {
|
|
25
|
-
"frogbot": "0.
|
|
22
|
+
"frogbot": "0.23.0"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@zip.js/zip.js": "2.8.15",
|
|
26
|
+
"mime-types": "2.1.35",
|
|
27
|
+
"zod": "^4.3.6"
|
|
26
28
|
},
|
|
27
29
|
"devDependencies": {
|
|
30
|
+
"@types/mime-types": "2.1.1",
|
|
28
31
|
"typescript": "5.6.2",
|
|
29
|
-
"frogbot": "0.
|
|
32
|
+
"frogbot": "0.23.0"
|
|
30
33
|
},
|
|
31
34
|
"publishConfig": {
|
|
32
35
|
"access": "public"
|