n8n-nodes-pixelvault 0.3.0 → 0.5.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.
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PixelVault = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
4
5
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
5
6
|
const IMAGES_URL = 'https://api.pixelvault.dev/v1/images';
|
|
7
|
+
const VIDEOS_URL = 'https://api.pixelvault.dev/v1/videos';
|
|
8
|
+
const AUDIO_URL = 'https://api.pixelvault.dev/v1/audio';
|
|
9
|
+
const AUDIO_MAX_BYTES = 25000000;
|
|
6
10
|
const MIN_EXPIRES_IN = 60;
|
|
7
11
|
const MAX_EXPIRES_IN = 2592000;
|
|
8
12
|
const DESCRIBE_POLL_MS = 2000;
|
|
9
13
|
const DESCRIBE_MAX_WAIT_MS = 40000;
|
|
14
|
+
const VIDEO_POLL_INITIAL_MS = 1000;
|
|
15
|
+
const VIDEO_POLL_MAX_MS = 5000;
|
|
10
16
|
function parseMetadata(value) {
|
|
11
17
|
if (value === undefined || value === null || value === '')
|
|
12
18
|
return {};
|
|
@@ -30,7 +36,7 @@ function parseExpiresIn(value) {
|
|
|
30
36
|
const seconds = Number(value);
|
|
31
37
|
if (!Number.isInteger(seconds) || seconds < MIN_EXPIRES_IN || seconds > MAX_EXPIRES_IN) {
|
|
32
38
|
return {
|
|
33
|
-
error: `Expires In must be 0 (keep the
|
|
39
|
+
error: `Expires In must be 0 (keep the asset) or a whole number of seconds between ${MIN_EXPIRES_IN} and ${MAX_EXPIRES_IN}.`,
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
42
|
return { seconds };
|
|
@@ -43,6 +49,28 @@ function fieldsFromOptions(options) {
|
|
|
43
49
|
fields.visibility = options.visibility;
|
|
44
50
|
return fields;
|
|
45
51
|
}
|
|
52
|
+
function audioContentType(fileName, mimeType) {
|
|
53
|
+
const normalized = mimeType === null || mimeType === void 0 ? void 0 : mimeType.toLowerCase();
|
|
54
|
+
if (normalized === 'audio/mpeg' || normalized === 'audio/mp3')
|
|
55
|
+
return 'audio/mpeg';
|
|
56
|
+
if (normalized === 'audio/wav' || normalized === 'audio/x-wav')
|
|
57
|
+
return 'audio/wav';
|
|
58
|
+
if (normalized === 'audio/mp4' || normalized === 'audio/m4a' || normalized === 'audio/x-m4a') {
|
|
59
|
+
return 'audio/mp4';
|
|
60
|
+
}
|
|
61
|
+
if (normalized === 'audio/ogg' || normalized === 'application/ogg')
|
|
62
|
+
return 'audio/ogg';
|
|
63
|
+
const extension = fileName.slice(fileName.lastIndexOf('.') + 1).toLowerCase();
|
|
64
|
+
if (extension === 'mp3')
|
|
65
|
+
return 'audio/mpeg';
|
|
66
|
+
if (extension === 'wav')
|
|
67
|
+
return 'audio/wav';
|
|
68
|
+
if (extension === 'm4a')
|
|
69
|
+
return 'audio/mp4';
|
|
70
|
+
if (extension === 'ogg')
|
|
71
|
+
return 'audio/ogg';
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
46
74
|
function buildMultipart(file, fields) {
|
|
47
75
|
const boundary = `----n8nPixelVault${Date.now().toString(16)}${Math.random().toString(16).slice(2)}`;
|
|
48
76
|
const safeName = file.fileName.replace(/["\r\n]/g, '_');
|
|
@@ -67,7 +95,7 @@ class PixelVault {
|
|
|
67
95
|
group: ['transform'],
|
|
68
96
|
version: 1,
|
|
69
97
|
subtitle: '={{$parameter["operation"]}}',
|
|
70
|
-
description: 'Host
|
|
98
|
+
description: 'Host images, video, and audio and get CDN URLs',
|
|
71
99
|
defaults: {
|
|
72
100
|
name: 'PixelVault',
|
|
73
101
|
},
|
|
@@ -80,18 +108,25 @@ class PixelVault {
|
|
|
80
108
|
},
|
|
81
109
|
],
|
|
82
110
|
properties: [
|
|
111
|
+
{
|
|
112
|
+
displayName: 'Resource',
|
|
113
|
+
name: 'resource',
|
|
114
|
+
type: 'options',
|
|
115
|
+
noDataExpression: true,
|
|
116
|
+
options: [
|
|
117
|
+
{ name: 'Audio', value: 'audio' },
|
|
118
|
+
{ name: 'Image', value: 'image' },
|
|
119
|
+
{ name: 'Video', value: 'video' },
|
|
120
|
+
],
|
|
121
|
+
default: 'image',
|
|
122
|
+
},
|
|
83
123
|
{
|
|
84
124
|
displayName: 'Operation',
|
|
85
125
|
name: 'operation',
|
|
86
126
|
type: 'options',
|
|
87
127
|
noDataExpression: true,
|
|
128
|
+
displayOptions: { show: { resource: ['image'] } },
|
|
88
129
|
options: [
|
|
89
|
-
{
|
|
90
|
-
name: 'Upload Image',
|
|
91
|
-
value: 'upload',
|
|
92
|
-
description: 'Upload an image from binary data and get a public URL',
|
|
93
|
-
action: 'Upload an image',
|
|
94
|
-
},
|
|
95
130
|
{
|
|
96
131
|
name: 'Import Image From URL',
|
|
97
132
|
value: 'importUrl',
|
|
@@ -104,17 +139,139 @@ class PixelVault {
|
|
|
104
139
|
description: "Replace an image's custom metadata (use {} to clear it)",
|
|
105
140
|
action: 'Update image metadata',
|
|
106
141
|
},
|
|
142
|
+
{
|
|
143
|
+
name: 'Upload Image',
|
|
144
|
+
value: 'upload',
|
|
145
|
+
description: 'Upload an image from binary data and get a CDN URL',
|
|
146
|
+
action: 'Upload an image',
|
|
147
|
+
},
|
|
107
148
|
],
|
|
108
149
|
default: 'upload',
|
|
109
150
|
},
|
|
151
|
+
{
|
|
152
|
+
displayName: 'Operation',
|
|
153
|
+
name: 'operation',
|
|
154
|
+
type: 'options',
|
|
155
|
+
noDataExpression: true,
|
|
156
|
+
displayOptions: { show: { resource: ['audio'] } },
|
|
157
|
+
options: [
|
|
158
|
+
{
|
|
159
|
+
name: 'Delete Audio',
|
|
160
|
+
value: 'deleteAudio',
|
|
161
|
+
description: 'Permanently delete an audio original',
|
|
162
|
+
action: 'Delete audio',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'Get Audio',
|
|
166
|
+
value: 'getAudio',
|
|
167
|
+
description: 'Get the original URL, privacy, expiry, and inspected audio metadata',
|
|
168
|
+
action: 'Get audio',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: 'Import Audio From URL',
|
|
172
|
+
value: 'importAudio',
|
|
173
|
+
description: 'Securely import MP3, WAV, M4A, or OGG from a public URL',
|
|
174
|
+
action: 'Import audio from a URL',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: 'List Audio',
|
|
178
|
+
value: 'listAudio',
|
|
179
|
+
description: 'List audio with optional folder, collection, and metadata filters',
|
|
180
|
+
action: 'List audio',
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'Sign Audio URL',
|
|
184
|
+
value: 'signAudio',
|
|
185
|
+
description: 'Mint a fresh time-limited URL for a private audio original',
|
|
186
|
+
action: 'Create a signed audio link',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'Update Audio',
|
|
190
|
+
value: 'updateAudio',
|
|
191
|
+
description: 'Replace audio metadata, folder, and collection membership',
|
|
192
|
+
action: 'Update audio',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'Upload Audio',
|
|
196
|
+
value: 'uploadAudio',
|
|
197
|
+
description: 'Upload original MP3, WAV, M4A, or OGG binary data',
|
|
198
|
+
action: 'Upload audio',
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
default: 'uploadAudio',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
displayName: 'Operation',
|
|
205
|
+
name: 'operation',
|
|
206
|
+
type: 'options',
|
|
207
|
+
noDataExpression: true,
|
|
208
|
+
displayOptions: { show: { resource: ['video'] } },
|
|
209
|
+
options: [
|
|
210
|
+
{
|
|
211
|
+
name: 'Delete Video',
|
|
212
|
+
value: 'deleteVideo',
|
|
213
|
+
description: 'Delete a video and its derived artifacts',
|
|
214
|
+
action: 'Delete a video',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'Enrich Video',
|
|
218
|
+
value: 'enrichVideo',
|
|
219
|
+
description: 'Start transcript and storyboard enrichment, optionally waiting for completion',
|
|
220
|
+
action: 'Enrich a video',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: 'Get Video Status and Artifacts',
|
|
224
|
+
value: 'getVideo',
|
|
225
|
+
description: 'Get the original, status, transcript, storyboard, poster, and optimized URL',
|
|
226
|
+
action: 'Get video status and artifacts',
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: 'Import Video From URL',
|
|
230
|
+
value: 'importVideo',
|
|
231
|
+
description: 'Securely import an MP4 from a public HTTPS URL',
|
|
232
|
+
action: 'Import a video from a URL',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
name: 'List Videos',
|
|
236
|
+
value: 'listVideos',
|
|
237
|
+
description: 'List videos with optional folder, collection, and metadata filters',
|
|
238
|
+
action: 'List videos',
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'Optimize Video',
|
|
242
|
+
value: 'optimizeVideo',
|
|
243
|
+
description: 'Start social-ready optimization, optionally waiting for completion',
|
|
244
|
+
action: 'Optimize a video',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
name: 'Sign Video URLs',
|
|
248
|
+
value: 'signVideo',
|
|
249
|
+
description: 'Mint fresh private original and available artifact URLs',
|
|
250
|
+
action: 'Create signed links for a video',
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: 'Update Video',
|
|
254
|
+
value: 'updateVideo',
|
|
255
|
+
description: 'Replace video metadata, folder, and collection membership',
|
|
256
|
+
action: 'Update a video',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'Upload Video',
|
|
260
|
+
value: 'uploadVideo',
|
|
261
|
+
description: 'Upload an MP4 from binary data',
|
|
262
|
+
action: 'Upload a video',
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
default: 'uploadVideo',
|
|
266
|
+
},
|
|
110
267
|
{
|
|
111
268
|
displayName: 'Input Binary Field',
|
|
112
269
|
name: 'binaryPropertyName',
|
|
113
270
|
type: 'string',
|
|
114
271
|
default: 'data',
|
|
115
272
|
required: true,
|
|
116
|
-
displayOptions: { show: { operation: ['upload'] } },
|
|
117
|
-
description: 'Name of the binary property that holds the image to upload',
|
|
273
|
+
displayOptions: { show: { operation: ['upload', 'uploadVideo', 'uploadAudio'] } },
|
|
274
|
+
description: 'Name of the binary property that holds the image, MP4, or audio file to upload',
|
|
118
275
|
},
|
|
119
276
|
{
|
|
120
277
|
displayName: 'Image URL',
|
|
@@ -136,14 +293,69 @@ class PixelVault {
|
|
|
136
293
|
displayOptions: { show: { operation: ['updateMetadata'] } },
|
|
137
294
|
description: 'ID of the image whose metadata to replace',
|
|
138
295
|
},
|
|
296
|
+
{
|
|
297
|
+
displayName: 'Audio URL',
|
|
298
|
+
name: 'audioUrl',
|
|
299
|
+
type: 'string',
|
|
300
|
+
default: '',
|
|
301
|
+
required: true,
|
|
302
|
+
placeholder: 'https://example.com/audio.mp3',
|
|
303
|
+
displayOptions: { show: { operation: ['importAudio'] } },
|
|
304
|
+
description: 'A public HTTP(S) URL that returns MP3, WAV, M4A, or OGG bytes. Authenticated sources must be downloaded in n8n first.',
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
displayName: 'Audio ID',
|
|
308
|
+
name: 'audioId',
|
|
309
|
+
type: 'string',
|
|
310
|
+
default: '',
|
|
311
|
+
required: true,
|
|
312
|
+
placeholder: 'aud_abc123',
|
|
313
|
+
displayOptions: {
|
|
314
|
+
show: {
|
|
315
|
+
operation: ['getAudio', 'updateAudio', 'signAudio', 'deleteAudio'],
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
description: 'Stable audio asset ID',
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
displayName: 'Video URL',
|
|
322
|
+
name: 'videoUrl',
|
|
323
|
+
type: 'string',
|
|
324
|
+
default: '',
|
|
325
|
+
required: true,
|
|
326
|
+
placeholder: 'https://example.com/video.mp4',
|
|
327
|
+
displayOptions: { show: { operation: ['importVideo'] } },
|
|
328
|
+
description: 'A public HTTPS URL that returns MP4 bytes. Authenticated sources must be downloaded in n8n first.',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
displayName: 'Video ID',
|
|
332
|
+
name: 'videoId',
|
|
333
|
+
type: 'string',
|
|
334
|
+
default: '',
|
|
335
|
+
required: true,
|
|
336
|
+
placeholder: 'vid_abc123',
|
|
337
|
+
displayOptions: {
|
|
338
|
+
show: {
|
|
339
|
+
operation: [
|
|
340
|
+
'getVideo',
|
|
341
|
+
'optimizeVideo',
|
|
342
|
+
'enrichVideo',
|
|
343
|
+
'updateVideo',
|
|
344
|
+
'signVideo',
|
|
345
|
+
'deleteVideo',
|
|
346
|
+
],
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
description: 'Stable video asset ID. Reuse it to resume an asynchronous workflow.',
|
|
350
|
+
},
|
|
139
351
|
{
|
|
140
352
|
displayName: 'Metadata (JSON)',
|
|
141
353
|
name: 'metadata',
|
|
142
354
|
type: 'json',
|
|
143
355
|
default: '{}',
|
|
144
356
|
required: true,
|
|
145
|
-
displayOptions: { show: { operation: ['updateMetadata'] } },
|
|
146
|
-
description: 'The full metadata object to store. It replaces the existing metadata
|
|
357
|
+
displayOptions: { show: { operation: ['updateMetadata', 'updateVideo', 'updateAudio'] } },
|
|
358
|
+
description: 'The full metadata object to store. It replaces the existing metadata; {} clears it. Up to 50 top-level keys and 4 KB.',
|
|
147
359
|
},
|
|
148
360
|
{
|
|
149
361
|
displayName: 'Options',
|
|
@@ -151,13 +363,43 @@ class PixelVault {
|
|
|
151
363
|
type: 'collection',
|
|
152
364
|
placeholder: 'Add Option',
|
|
153
365
|
default: {},
|
|
154
|
-
displayOptions: {
|
|
366
|
+
displayOptions: {
|
|
367
|
+
show: {
|
|
368
|
+
operation: [
|
|
369
|
+
'upload',
|
|
370
|
+
'importUrl',
|
|
371
|
+
'uploadVideo',
|
|
372
|
+
'uploadAudio',
|
|
373
|
+
'importAudio',
|
|
374
|
+
'listAudio',
|
|
375
|
+
'updateAudio',
|
|
376
|
+
'signAudio',
|
|
377
|
+
'importVideo',
|
|
378
|
+
'listVideos',
|
|
379
|
+
'optimizeVideo',
|
|
380
|
+
'enrichVideo',
|
|
381
|
+
'updateVideo',
|
|
382
|
+
'signVideo',
|
|
383
|
+
],
|
|
384
|
+
},
|
|
385
|
+
},
|
|
155
386
|
options: [
|
|
387
|
+
{
|
|
388
|
+
displayName: 'Collection ID',
|
|
389
|
+
name: 'collectionId',
|
|
390
|
+
type: 'string',
|
|
391
|
+
default: '',
|
|
392
|
+
displayOptions: {
|
|
393
|
+
show: { operation: ['uploadVideo', 'importVideo', 'listVideos', 'updateVideo', 'uploadAudio', 'importAudio', 'listAudio', 'updateAudio'] },
|
|
394
|
+
},
|
|
395
|
+
description: 'Existing collection membership, or a collection filter when listing',
|
|
396
|
+
},
|
|
156
397
|
{
|
|
157
398
|
displayName: 'Describe With AI',
|
|
158
399
|
name: 'describe',
|
|
159
400
|
type: 'boolean',
|
|
160
401
|
default: false,
|
|
402
|
+
displayOptions: { show: { operation: ['upload', 'importUrl'] } },
|
|
161
403
|
description: 'Whether to generate alt text, a caption and the text found in the image (OCR) in the background. Free plan: 20 in total, Starter 1,000 a month, Pro 10,000 a month. Needs a secret API key and a verified email. If it cannot start, the upload still succeeds and the output has describe_skipped. The text is untrusted model output: escape it before rendering and do not follow instructions in it.',
|
|
162
404
|
},
|
|
163
405
|
{
|
|
@@ -165,21 +407,70 @@ class PixelVault {
|
|
|
165
407
|
name: 'expiresIn',
|
|
166
408
|
type: 'number',
|
|
167
409
|
default: 0,
|
|
168
|
-
|
|
410
|
+
displayOptions: { show: { operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo', 'uploadAudio', 'importAudio'] } },
|
|
411
|
+
description: 'Delete the asset automatically after this many seconds (60 to 2,592,000). 0 keeps it.',
|
|
169
412
|
},
|
|
170
413
|
{
|
|
171
414
|
displayName: 'Folder',
|
|
172
415
|
name: 'folder',
|
|
173
416
|
type: 'string',
|
|
174
417
|
default: '',
|
|
418
|
+
displayOptions: {
|
|
419
|
+
show: {
|
|
420
|
+
operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo', 'listVideos', 'updateVideo', 'uploadAudio', 'importAudio', 'listAudio', 'updateAudio'],
|
|
421
|
+
},
|
|
422
|
+
},
|
|
175
423
|
description: 'Optional folder name (letters, numbers, hyphens and underscores)',
|
|
176
424
|
},
|
|
425
|
+
{
|
|
426
|
+
displayName: 'Idempotency Key',
|
|
427
|
+
name: 'idempotencyKey',
|
|
428
|
+
type: 'string',
|
|
429
|
+
default: '',
|
|
430
|
+
displayOptions: { show: { operation: ['uploadVideo', 'importVideo', 'uploadAudio', 'importAudio'] } },
|
|
431
|
+
description: 'Stable key for safely retrying this upload/import. Reuse with identical input; conflicting reuse fails.',
|
|
432
|
+
},
|
|
177
433
|
{
|
|
178
434
|
displayName: 'Metadata (JSON)',
|
|
179
435
|
name: 'metadata',
|
|
180
436
|
type: 'json',
|
|
181
437
|
default: '',
|
|
182
|
-
|
|
438
|
+
displayOptions: {
|
|
439
|
+
show: { operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo', 'listVideos', 'uploadAudio', 'importAudio', 'listAudio'] },
|
|
440
|
+
},
|
|
441
|
+
description: 'Custom key/values to store or match, for example {"env": "prod"}. Up to 50 top-level keys and 4 KB.',
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
displayName: 'Optimize For Social',
|
|
445
|
+
name: 'socialReady',
|
|
446
|
+
type: 'boolean',
|
|
447
|
+
default: false,
|
|
448
|
+
displayOptions: { show: { operation: ['uploadVideo', 'importVideo'] } },
|
|
449
|
+
description: 'Whether to start social-ready H.264/AAC fast-start optimization after upload',
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
displayName: 'Page',
|
|
453
|
+
name: 'page',
|
|
454
|
+
type: 'number',
|
|
455
|
+
default: 1,
|
|
456
|
+
typeOptions: { minValue: 1 },
|
|
457
|
+
displayOptions: { show: { operation: ['listVideos', 'listAudio'] } },
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
displayName: 'Per Page',
|
|
461
|
+
name: 'perPage',
|
|
462
|
+
type: 'number',
|
|
463
|
+
default: 20,
|
|
464
|
+
typeOptions: { minValue: 1, maxValue: 100 },
|
|
465
|
+
displayOptions: { show: { operation: ['listVideos', 'listAudio'] } },
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
displayName: 'Signed URL Expiry (Seconds)',
|
|
469
|
+
name: 'signExpiresIn',
|
|
470
|
+
type: 'number',
|
|
471
|
+
default: 3600,
|
|
472
|
+
displayOptions: { show: { operation: ['uploadVideo', 'importVideo', 'signVideo', 'uploadAudio', 'importAudio', 'signAudio'] } },
|
|
473
|
+
description: 'Private URL lifetime, from 60 to 2,592,000 seconds',
|
|
183
474
|
},
|
|
184
475
|
{
|
|
185
476
|
displayName: 'Visibility',
|
|
@@ -190,22 +481,41 @@ class PixelVault {
|
|
|
190
481
|
{ name: 'Private (Signed URL)', value: 'private' },
|
|
191
482
|
],
|
|
192
483
|
default: 'public',
|
|
193
|
-
|
|
484
|
+
displayOptions: { show: { operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo', 'uploadAudio', 'importAudio'] } },
|
|
485
|
+
description: 'Private media is returned with time-limited signed URLs',
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
displayName: 'Wait For Completion',
|
|
489
|
+
name: 'waitForCompletion',
|
|
490
|
+
type: 'boolean',
|
|
491
|
+
default: false,
|
|
492
|
+
displayOptions: { show: { operation: ['optimizeVideo', 'enrichVideo'] } },
|
|
493
|
+
description: 'Whether to poll with bounded backoff. Leave off to return the asset and job IDs immediately and resume later with Get Video.',
|
|
194
494
|
},
|
|
195
495
|
{
|
|
196
496
|
displayName: 'Wait For Description',
|
|
197
497
|
name: 'waitForDescription',
|
|
198
498
|
type: 'boolean',
|
|
199
499
|
default: false,
|
|
500
|
+
displayOptions: { show: { operation: ['upload', 'importUrl'] } },
|
|
200
501
|
description: 'Whether to wait (up to about 40 seconds) for the AI description and include it in the output. Only used with Describe With AI.',
|
|
201
502
|
},
|
|
503
|
+
{
|
|
504
|
+
displayName: 'Wait Timeout (Seconds)',
|
|
505
|
+
name: 'waitTimeoutSeconds',
|
|
506
|
+
type: 'number',
|
|
507
|
+
default: 600,
|
|
508
|
+
typeOptions: { minValue: 1, maxValue: 3600 },
|
|
509
|
+
displayOptions: { show: { operation: ['optimizeVideo', 'enrichVideo'] } },
|
|
510
|
+
description: 'Local polling limit. Timing out does not cancel the server job.',
|
|
511
|
+
},
|
|
202
512
|
],
|
|
203
513
|
},
|
|
204
514
|
],
|
|
205
515
|
};
|
|
206
516
|
}
|
|
207
517
|
async execute() {
|
|
208
|
-
var _a, _b, _c, _d;
|
|
518
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
209
519
|
const items = this.getInputData();
|
|
210
520
|
const returnData = [];
|
|
211
521
|
const operation = this.getNodeParameter('operation', 0);
|
|
@@ -219,7 +529,7 @@ class PixelVault {
|
|
|
219
529
|
}
|
|
220
530
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), expiresError, { itemIndex: i });
|
|
221
531
|
}
|
|
222
|
-
const metadataSource = operation === 'updateMetadata'
|
|
532
|
+
const metadataSource = operation === 'updateMetadata' || operation === 'updateVideo' || operation === 'updateAudio'
|
|
223
533
|
? this.getNodeParameter('metadata', i, '{}')
|
|
224
534
|
: options.metadata;
|
|
225
535
|
const { metadata, error: metadataError } = parseMetadata(metadataSource);
|
|
@@ -273,33 +583,267 @@ class PixelVault {
|
|
|
273
583
|
json: true,
|
|
274
584
|
};
|
|
275
585
|
}
|
|
586
|
+
else if (operation === 'uploadAudio') {
|
|
587
|
+
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
|
588
|
+
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
|
589
|
+
const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
|
590
|
+
if (buffer.length > AUDIO_MAX_BYTES) {
|
|
591
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Audio originals are limited to the approved global maximum of 25,000,000 bytes. This is not a plan allowance.', { itemIndex: i });
|
|
592
|
+
}
|
|
593
|
+
const filename = (_b = binaryData.fileName) !== null && _b !== void 0 ? _b : 'audio.mp3';
|
|
594
|
+
const contentType = audioContentType(filename, binaryData.mimeType);
|
|
595
|
+
if (!contentType) {
|
|
596
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Audio binary data must be MP3, WAV, M4A, or OGG. Set a supported filename or MIME type.', { itemIndex: i });
|
|
597
|
+
}
|
|
598
|
+
const headers = {
|
|
599
|
+
'Content-Type': contentType,
|
|
600
|
+
'Content-Length': String(buffer.length),
|
|
601
|
+
'X-PixelVault-Filename': encodeURIComponent(filename),
|
|
602
|
+
};
|
|
603
|
+
if (options.visibility)
|
|
604
|
+
headers['X-PixelVault-Visibility'] = options.visibility;
|
|
605
|
+
if (expiresIn !== undefined)
|
|
606
|
+
headers['X-PixelVault-Expires-In'] = String(expiresIn);
|
|
607
|
+
if (options.folder)
|
|
608
|
+
headers['X-PixelVault-Folder'] = options.folder;
|
|
609
|
+
if (options.collectionId)
|
|
610
|
+
headers['X-PixelVault-Collection-Id'] = options.collectionId;
|
|
611
|
+
if (metadata && Object.keys(metadata).length > 0) {
|
|
612
|
+
headers['X-PixelVault-Metadata'] = JSON.stringify(metadata);
|
|
613
|
+
}
|
|
614
|
+
if (options.signExpiresIn) {
|
|
615
|
+
headers['X-PixelVault-Sign-Expires-In'] = String(options.signExpiresIn);
|
|
616
|
+
}
|
|
617
|
+
if (options.idempotencyKey) {
|
|
618
|
+
headers['Idempotency-Key'] = options.idempotencyKey;
|
|
619
|
+
headers['X-PixelVault-Content-SHA256'] = (0, node_crypto_1.createHash)('sha256').update(buffer).digest('hex');
|
|
620
|
+
}
|
|
621
|
+
requestOptions = { method: 'POST', url: AUDIO_URL, headers, body: buffer };
|
|
622
|
+
}
|
|
623
|
+
else if (operation === 'importAudio') {
|
|
624
|
+
const audioUrl = this.getNodeParameter('audioUrl', i);
|
|
625
|
+
const body = { url: audioUrl };
|
|
626
|
+
if (options.visibility)
|
|
627
|
+
body.visibility = options.visibility;
|
|
628
|
+
if (expiresIn !== undefined)
|
|
629
|
+
body.expires_in = expiresIn;
|
|
630
|
+
if (options.folder)
|
|
631
|
+
body.folder = options.folder;
|
|
632
|
+
if (options.collectionId)
|
|
633
|
+
body.collection_id = options.collectionId;
|
|
634
|
+
if (metadata && Object.keys(metadata).length > 0)
|
|
635
|
+
body.metadata = metadata;
|
|
636
|
+
if (options.signExpiresIn)
|
|
637
|
+
body.sign_expires_in = options.signExpiresIn;
|
|
638
|
+
requestOptions = {
|
|
639
|
+
method: 'POST',
|
|
640
|
+
url: AUDIO_URL,
|
|
641
|
+
headers: options.idempotencyKey ? { 'Idempotency-Key': options.idempotencyKey } : {},
|
|
642
|
+
body,
|
|
643
|
+
json: true,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
else if (operation === 'listAudio') {
|
|
647
|
+
const qs = {};
|
|
648
|
+
if (options.page)
|
|
649
|
+
qs.page = options.page;
|
|
650
|
+
if (options.perPage)
|
|
651
|
+
qs.per_page = options.perPage;
|
|
652
|
+
if (options.folder)
|
|
653
|
+
qs.folder = options.folder;
|
|
654
|
+
if (options.collectionId)
|
|
655
|
+
qs.collection_id = options.collectionId;
|
|
656
|
+
if (metadata && Object.keys(metadata).length > 0)
|
|
657
|
+
qs.metadata = JSON.stringify(metadata);
|
|
658
|
+
requestOptions = { method: 'GET', url: AUDIO_URL, qs, json: true };
|
|
659
|
+
}
|
|
660
|
+
else if (operation === 'getAudio' ||
|
|
661
|
+
operation === 'deleteAudio' ||
|
|
662
|
+
operation === 'signAudio' ||
|
|
663
|
+
operation === 'updateAudio') {
|
|
664
|
+
const audioId = this.getNodeParameter('audioId', i);
|
|
665
|
+
const audioUrl = `${AUDIO_URL}/${encodeURIComponent(audioId)}`;
|
|
666
|
+
if (operation === 'getAudio') {
|
|
667
|
+
requestOptions = { method: 'GET', url: audioUrl, json: true };
|
|
668
|
+
}
|
|
669
|
+
else if (operation === 'deleteAudio') {
|
|
670
|
+
requestOptions = { method: 'DELETE', url: audioUrl, json: true };
|
|
671
|
+
}
|
|
672
|
+
else if (operation === 'signAudio') {
|
|
673
|
+
requestOptions = {
|
|
674
|
+
method: 'POST',
|
|
675
|
+
url: `${audioUrl}/sign-url`,
|
|
676
|
+
body: options.signExpiresIn ? { expires_in: options.signExpiresIn } : {},
|
|
677
|
+
json: true,
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
const body = { metadata: metadata !== null && metadata !== void 0 ? metadata : {} };
|
|
682
|
+
if (options.folder !== undefined)
|
|
683
|
+
body.folder = options.folder || null;
|
|
684
|
+
if (options.collectionId !== undefined)
|
|
685
|
+
body.collection_id = options.collectionId || null;
|
|
686
|
+
requestOptions = { method: 'PATCH', url: audioUrl, body, json: true };
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
else if (operation === 'uploadVideo') {
|
|
690
|
+
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
|
691
|
+
const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
|
|
692
|
+
const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
|
693
|
+
const headers = {
|
|
694
|
+
'Content-Type': 'video/mp4',
|
|
695
|
+
'Content-Length': String(buffer.length),
|
|
696
|
+
'X-PixelVault-Filename': encodeURIComponent((_c = binaryData.fileName) !== null && _c !== void 0 ? _c : 'video.mp4'),
|
|
697
|
+
};
|
|
698
|
+
if (options.visibility)
|
|
699
|
+
headers['X-PixelVault-Visibility'] = options.visibility;
|
|
700
|
+
if (expiresIn !== undefined)
|
|
701
|
+
headers['X-PixelVault-Expires-In'] = String(expiresIn);
|
|
702
|
+
if (options.folder)
|
|
703
|
+
headers['X-PixelVault-Folder'] = options.folder;
|
|
704
|
+
if (options.collectionId)
|
|
705
|
+
headers['X-PixelVault-Collection-Id'] = options.collectionId;
|
|
706
|
+
if (metadata && Object.keys(metadata).length > 0) {
|
|
707
|
+
headers['X-PixelVault-Metadata'] = JSON.stringify(metadata);
|
|
708
|
+
}
|
|
709
|
+
if (options.socialReady)
|
|
710
|
+
headers['X-PixelVault-Social-Ready'] = 'true';
|
|
711
|
+
if (options.signExpiresIn) {
|
|
712
|
+
headers['X-PixelVault-Sign-Expires-In'] = String(options.signExpiresIn);
|
|
713
|
+
}
|
|
714
|
+
if (options.idempotencyKey) {
|
|
715
|
+
headers['Idempotency-Key'] = options.idempotencyKey;
|
|
716
|
+
headers['X-PixelVault-Content-SHA256'] = (0, node_crypto_1.createHash)('sha256').update(buffer).digest('hex');
|
|
717
|
+
}
|
|
718
|
+
requestOptions = { method: 'POST', url: VIDEOS_URL, headers, body: buffer };
|
|
719
|
+
}
|
|
720
|
+
else if (operation === 'importVideo') {
|
|
721
|
+
const videoUrl = this.getNodeParameter('videoUrl', i);
|
|
722
|
+
const body = { url: videoUrl };
|
|
723
|
+
if (options.visibility)
|
|
724
|
+
body.visibility = options.visibility;
|
|
725
|
+
if (expiresIn !== undefined)
|
|
726
|
+
body.expires_in = expiresIn;
|
|
727
|
+
if (options.folder)
|
|
728
|
+
body.folder = options.folder;
|
|
729
|
+
if (options.collectionId)
|
|
730
|
+
body.collection_id = options.collectionId;
|
|
731
|
+
if (metadata && Object.keys(metadata).length > 0)
|
|
732
|
+
body.metadata = metadata;
|
|
733
|
+
if (options.socialReady)
|
|
734
|
+
body.social_ready = true;
|
|
735
|
+
if (options.signExpiresIn)
|
|
736
|
+
body.sign_expires_in = options.signExpiresIn;
|
|
737
|
+
requestOptions = {
|
|
738
|
+
method: 'POST',
|
|
739
|
+
url: VIDEOS_URL,
|
|
740
|
+
headers: options.idempotencyKey ? { 'Idempotency-Key': options.idempotencyKey } : {},
|
|
741
|
+
body,
|
|
742
|
+
json: true,
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
else if (operation === 'listVideos') {
|
|
746
|
+
const qs = {};
|
|
747
|
+
if (options.page)
|
|
748
|
+
qs.page = options.page;
|
|
749
|
+
if (options.perPage)
|
|
750
|
+
qs.per_page = options.perPage;
|
|
751
|
+
if (options.folder)
|
|
752
|
+
qs.folder = options.folder;
|
|
753
|
+
if (options.collectionId)
|
|
754
|
+
qs.collection_id = options.collectionId;
|
|
755
|
+
if (metadata && Object.keys(metadata).length > 0)
|
|
756
|
+
qs.metadata = JSON.stringify(metadata);
|
|
757
|
+
requestOptions = { method: 'GET', url: VIDEOS_URL, qs, json: true };
|
|
758
|
+
}
|
|
276
759
|
else {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
760
|
+
const videoId = this.getNodeParameter('videoId', i, '');
|
|
761
|
+
const videoUrl = `${VIDEOS_URL}/${encodeURIComponent(videoId)}`;
|
|
762
|
+
if (operation === 'getVideo') {
|
|
763
|
+
requestOptions = { method: 'GET', url: videoUrl, json: true };
|
|
764
|
+
}
|
|
765
|
+
else if (operation === 'deleteVideo') {
|
|
766
|
+
requestOptions = { method: 'DELETE', url: videoUrl, json: true };
|
|
767
|
+
}
|
|
768
|
+
else if (operation === 'signVideo') {
|
|
769
|
+
requestOptions = {
|
|
770
|
+
method: 'POST',
|
|
771
|
+
url: `${videoUrl}/sign-url`,
|
|
772
|
+
body: options.signExpiresIn ? { expires_in: options.signExpiresIn } : {},
|
|
773
|
+
json: true,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
else if (operation === 'updateVideo') {
|
|
777
|
+
const body = { metadata: metadata !== null && metadata !== void 0 ? metadata : {} };
|
|
778
|
+
if (options.folder !== undefined)
|
|
779
|
+
body.folder = options.folder || null;
|
|
780
|
+
if (options.collectionId !== undefined)
|
|
781
|
+
body.collection_id = options.collectionId || null;
|
|
782
|
+
requestOptions = { method: 'PATCH', url: videoUrl, body, json: true };
|
|
783
|
+
}
|
|
784
|
+
else if (operation === 'optimizeVideo' || operation === 'enrichVideo') {
|
|
785
|
+
const action = operation === 'optimizeVideo' ? 'optimize' : 'enrich';
|
|
786
|
+
requestOptions = { method: 'POST', url: `${videoUrl}/${action}`, json: true };
|
|
787
|
+
}
|
|
788
|
+
else {
|
|
789
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`, {
|
|
790
|
+
itemIndex: i,
|
|
791
|
+
});
|
|
792
|
+
}
|
|
280
793
|
}
|
|
281
794
|
const response = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', requestOptions));
|
|
282
795
|
const parsed = (typeof response === 'string' ? JSON.parse(response) : response);
|
|
283
|
-
|
|
284
|
-
|
|
796
|
+
let output;
|
|
797
|
+
if (operation === 'listVideos') {
|
|
798
|
+
output = { videos: (_d = parsed.data) !== null && _d !== void 0 ? _d : [], meta: (_e = parsed.meta) !== null && _e !== void 0 ? _e : {} };
|
|
799
|
+
}
|
|
800
|
+
else if (operation === 'listAudio') {
|
|
801
|
+
output = { audio: (_f = parsed.data) !== null && _f !== void 0 ? _f : [], meta: (_g = parsed.meta) !== null && _g !== void 0 ? _g : {} };
|
|
802
|
+
}
|
|
803
|
+
else {
|
|
804
|
+
output = ((_h = parsed.data) !== null && _h !== void 0 ? _h : parsed);
|
|
805
|
+
}
|
|
806
|
+
const description = output.description;
|
|
285
807
|
if (options.describe &&
|
|
286
808
|
options.waitForDescription &&
|
|
287
809
|
operation !== 'updateMetadata' &&
|
|
288
|
-
typeof
|
|
810
|
+
typeof output.id === 'string' &&
|
|
289
811
|
(description === null || description === void 0 ? void 0 : description.status) === 'pending') {
|
|
290
812
|
const deadline = Date.now() + DESCRIBE_MAX_WAIT_MS;
|
|
291
813
|
for (;;) {
|
|
292
814
|
await (0, n8n_workflow_1.sleep)(DESCRIBE_POLL_MS);
|
|
293
|
-
const polled = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', { method: 'GET', url: `${IMAGES_URL}/${encodeURIComponent(
|
|
815
|
+
const polled = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', { method: 'GET', url: `${IMAGES_URL}/${encodeURIComponent(output.id)}`, json: true }));
|
|
294
816
|
const polledData = (typeof polled === 'string' ? JSON.parse(polled) : polled).data;
|
|
295
|
-
|
|
296
|
-
if (((
|
|
817
|
+
output.description = (_j = polledData === null || polledData === void 0 ? void 0 : polledData.description) !== null && _j !== void 0 ? _j : null;
|
|
818
|
+
if (((_k = output.description) === null || _k === void 0 ? void 0 : _k.status) !== 'pending')
|
|
297
819
|
break;
|
|
298
820
|
if (Date.now() >= deadline)
|
|
299
821
|
break;
|
|
300
822
|
}
|
|
301
823
|
}
|
|
302
|
-
|
|
824
|
+
if ((operation === 'optimizeVideo' || operation === 'enrichVideo') &&
|
|
825
|
+
options.waitForCompletion &&
|
|
826
|
+
typeof output.id === 'string') {
|
|
827
|
+
const pollingVideoId = output.id;
|
|
828
|
+
const deadline = Date.now() + ((_l = options.waitTimeoutSeconds) !== null && _l !== void 0 ? _l : 600) * 1000;
|
|
829
|
+
let delay = VIDEO_POLL_INITIAL_MS;
|
|
830
|
+
const jobField = operation === 'enrichVideo' ? 'enrichment' : 'social_optimization';
|
|
831
|
+
for (;;) {
|
|
832
|
+
const job = output[jobField];
|
|
833
|
+
if ((job === null || job === void 0 ? void 0 : job.status) !== 'pending' && (job === null || job === void 0 ? void 0 : job.status) !== 'processing')
|
|
834
|
+
break;
|
|
835
|
+
const remaining = deadline - Date.now();
|
|
836
|
+
if (remaining <= 0) {
|
|
837
|
+
output.wait_timed_out = true;
|
|
838
|
+
break;
|
|
839
|
+
}
|
|
840
|
+
await (0, n8n_workflow_1.sleep)(Math.min(delay, remaining));
|
|
841
|
+
const polled = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', { method: 'GET', url: `${VIDEOS_URL}/${encodeURIComponent(pollingVideoId)}`, json: true }));
|
|
842
|
+
output = (typeof polled === 'string' ? JSON.parse(polled) : polled).data;
|
|
843
|
+
delay = Math.min(Math.ceil(delay * 1.5), VIDEO_POLL_MAX_MS);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
returnData.push({ json: output, pairedItem: { item: i } });
|
|
303
847
|
}
|
|
304
848
|
catch (error) {
|
|
305
849
|
if (this.continueOnFail()) {
|