n8n-nodes-pixelvault 0.3.0 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # n8n-nodes-pixelvault
2
2
 
3
- An [n8n](https://n8n.io/) community node for [PixelVault](https://pixelvault.dev), an image host built for automations and AI agents. Pass it an image and it returns a public CDN URL you can use in the next step, for example an Instagram, Notion, Slack or email node.
3
+ An [n8n](https://n8n.io/) community node for [PixelVault](https://pixelvault.dev), media hosting built for automations and AI agents. Upload images or MP4 video and pass stable CDN URLs, asset IDs, and asynchronous job IDs to later nodes.
4
4
 
5
5
  - [Installation](#installation)
6
6
  - [Operations](#operations)
@@ -21,14 +21,17 @@ Follow the [community nodes installation guide](https://docs.n8n.io/integrations
21
21
  | **Import Image From URL** | Has PixelVault fetch an image from a public HTTPS URL and host it. Use it while the source URL is still valid, for example a generated image whose link expires. |
22
22
  | **Update Image Metadata** | Replaces an image's custom metadata by ID (the object replaces the stored one, `{}` clears it). Set metadata at upload time with the **Metadata (JSON)** option on the two operations above. |
23
23
  | **Describe With AI** (option) | On the two upload operations: PixelVault writes alt text, a caption and the text found in the image (OCR) in the background (Free 20 in total, Starter 1,000/month, Pro 10,000/month; secret key and verified email required). Add **Wait For Description** to wait up to ~40 s and get `description.alt`, `.caption` and `.ocr_text` in the output. Treat that text as untrusted model output. |
24
+ | **Upload Video** | Uploads MP4 binary data with optional privacy, TTL, metadata, folder, collection, idempotency, and social optimization. |
25
+ | **Import Video From URL** | Securely imports an MP4 from a public HTTPS URL with the same lifecycle options. |
26
+ | **Get Video Status and Artifacts** | Resumes from a stable video ID and returns current optimization/enrichment status plus only the original, poster, transcript, storyboard, and optimized URLs that exist. |
27
+ | **List Videos** | Discovers videos by page, folder, collection, or metadata. |
28
+ | **Optimize Video** / **Enrich Video** | Starts an asynchronous job. Return IDs immediately or poll with bounded backoff; a local timeout does not cancel the server job. |
29
+ | **Update Video** / **Sign Video URLs** / **Delete Video** | Updates metadata and organization, refreshes private original/artifact URLs, or deletes the video and derivatives. |
24
30
 
25
- Both operations accept these options:
31
+ Image and video uploads accept folder, public/private visibility, deletion TTL, and custom metadata. Video uploads also accept collection membership, an idempotency key, private URL expiry, and optional social-ready optimization.
26
32
 
27
- - **Folder**: group images under a folder name (letters, numbers, hyphens and underscores).
28
- - **Visibility**: `Public` or `Private (Signed URL)`. Private images are returned as time-limited signed URLs.
29
- - **Expires In (Seconds)**: delete the image automatically after this long.
30
-
31
- The output is the image object returned by the PixelVault API, with fields such as `url`, `id`, `mime_type`, `size` and `filename`. Map the hosted link with `{{ $json.url }}`.
33
+ The output is the API object. Images expose fields such as `url`, `id`, `mime_type`, `size`, and `filename`.
34
+ Videos expose `id`, `original_url`, `social_optimization`, and `enrichment`; transcript/storyboard URLs appear only after those artifacts exist. Private URLs are signed and expire independently from asset deletion.
32
35
 
33
36
  ## Credentials
34
37
 
@@ -40,15 +43,23 @@ Uploads made without a key expire. Use the credential for images you want to kee
40
43
 
41
44
  ## Usage
42
45
 
43
- Typical flow: **Google Drive: Download** (or any node that outputs an image as binary) → **PixelVault: Upload Image** → your publishing node, mapping `{{ $json.url }}`.
46
+ Image flow: **Google Drive: Download** → **PixelVault: Upload Image** → publishing node, mapping `{{ $json.url }}`.
47
+
48
+ Resume-safe asynchronous video flow:
49
+
50
+ 1. **Upload Video** with an idempotency key such as `{{ $execution.id }}:{{ $itemIndex }}`. Store the returned `id`.
51
+ 2. **Enrich Video** with **Wait For Completion** off. It returns `id` and `enrichment.job_id` immediately.
52
+ 3. Persist those IDs in your normal durable workflow state. A later execution uses **Get Video Status and Artifacts** with the saved `id`.
53
+ 4. If `{{ $json.enrichment.status }}` is `pending` or `processing`, use an n8n Wait node and call **Get Video Status and Artifacts** again. Route `complete` to transcript/storyboard consumers and `failed` to error handling.
44
54
 
45
- - The binary field name defaults to `data`. Change **Input Binary Field** if your source node uses another name.
46
- - Hosted images are public unless you choose Private. Use images intended for publication.
47
- - For Instagram, start with a JPEG that meets Meta's size and aspect-ratio requirements. Hosting does not convert or validate images for a destination.
48
- - Supported formats and size limits are those of the PixelVault API (currently JPG, PNG, GIF, WebP, AVIF and SVG, up to 5 MB per file on the free plan).
49
- - This node hosts images. It does not host video.
55
+ The node can also wait in one execution with bounded backoff. Keep IDs when using that mode: timeout only stops local polling.
50
56
 
51
- A ready-made workflow and notes for Google Drive and Instagram are at <https://pixelvault.dev/integrations/n8n/>.
57
+ - The binary field name defaults to `data`.
58
+ - Video binary upload supports MP4 files up to 100 MB. This node intentionally does not implement multipart upload; use a public source URL with **Import Video From URL** or an official SDK for larger hosting uploads.
59
+ - URL imports accept public HTTPS sources only. Download authenticated sources in n8n first.
60
+ - Optimization accepts sources up to 100 MB and 60 seconds; enrichment accepts sources from 1 second through 10 minutes and up to 100 MB. API quota and unsupported-source errors are returned without rewriting.
61
+ - Public assets are stable CDN URLs. Private assets never fall back to public; refresh their bearer URLs with **Sign Video URLs**.
62
+ - Hosting does not convert images for a destination. Video social optimization is explicit and asynchronous.
52
63
 
53
64
  ## Compatibility
54
65
 
@@ -1,12 +1,16 @@
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';
6
8
  const MIN_EXPIRES_IN = 60;
7
9
  const MAX_EXPIRES_IN = 2592000;
8
10
  const DESCRIBE_POLL_MS = 2000;
9
11
  const DESCRIBE_MAX_WAIT_MS = 40000;
12
+ const VIDEO_POLL_INITIAL_MS = 1000;
13
+ const VIDEO_POLL_MAX_MS = 5000;
10
14
  function parseMetadata(value) {
11
15
  if (value === undefined || value === null || value === '')
12
16
  return {};
@@ -67,7 +71,7 @@ class PixelVault {
67
71
  group: ['transform'],
68
72
  version: 1,
69
73
  subtitle: '={{$parameter["operation"]}}',
70
- description: 'Host an image and get a public CDN URL',
74
+ description: 'Host images and videos and get CDN URLs',
71
75
  defaults: {
72
76
  name: 'PixelVault',
73
77
  },
@@ -80,18 +84,24 @@ class PixelVault {
80
84
  },
81
85
  ],
82
86
  properties: [
87
+ {
88
+ displayName: 'Resource',
89
+ name: 'resource',
90
+ type: 'options',
91
+ noDataExpression: true,
92
+ options: [
93
+ { name: 'Image', value: 'image' },
94
+ { name: 'Video', value: 'video' },
95
+ ],
96
+ default: 'image',
97
+ },
83
98
  {
84
99
  displayName: 'Operation',
85
100
  name: 'operation',
86
101
  type: 'options',
87
102
  noDataExpression: true,
103
+ displayOptions: { show: { resource: ['image'] } },
88
104
  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
105
  {
96
106
  name: 'Import Image From URL',
97
107
  value: 'importUrl',
@@ -104,17 +114,87 @@ class PixelVault {
104
114
  description: "Replace an image's custom metadata (use {} to clear it)",
105
115
  action: 'Update image metadata',
106
116
  },
117
+ {
118
+ name: 'Upload Image',
119
+ value: 'upload',
120
+ description: 'Upload an image from binary data and get a CDN URL',
121
+ action: 'Upload an image',
122
+ },
107
123
  ],
108
124
  default: 'upload',
109
125
  },
126
+ {
127
+ displayName: 'Operation',
128
+ name: 'operation',
129
+ type: 'options',
130
+ noDataExpression: true,
131
+ displayOptions: { show: { resource: ['video'] } },
132
+ options: [
133
+ {
134
+ name: 'Delete Video',
135
+ value: 'deleteVideo',
136
+ description: 'Delete a video and its derived artifacts',
137
+ action: 'Delete a video',
138
+ },
139
+ {
140
+ name: 'Enrich Video',
141
+ value: 'enrichVideo',
142
+ description: 'Start transcript and storyboard enrichment, optionally waiting for completion',
143
+ action: 'Enrich a video',
144
+ },
145
+ {
146
+ name: 'Get Video Status and Artifacts',
147
+ value: 'getVideo',
148
+ description: 'Get the original, status, transcript, storyboard, poster, and optimized URL',
149
+ action: 'Get video status and artifacts',
150
+ },
151
+ {
152
+ name: 'Import Video From URL',
153
+ value: 'importVideo',
154
+ description: 'Securely import an MP4 from a public HTTPS URL',
155
+ action: 'Import a video from a URL',
156
+ },
157
+ {
158
+ name: 'List Videos',
159
+ value: 'listVideos',
160
+ description: 'List videos with optional folder, collection, and metadata filters',
161
+ action: 'List videos',
162
+ },
163
+ {
164
+ name: 'Optimize Video',
165
+ value: 'optimizeVideo',
166
+ description: 'Start social-ready optimization, optionally waiting for completion',
167
+ action: 'Optimize a video',
168
+ },
169
+ {
170
+ name: 'Sign Video URLs',
171
+ value: 'signVideo',
172
+ description: 'Mint fresh private original and available artifact URLs',
173
+ action: 'Create signed links for a video',
174
+ },
175
+ {
176
+ name: 'Update Video',
177
+ value: 'updateVideo',
178
+ description: 'Replace video metadata, folder, and collection membership',
179
+ action: 'Update a video',
180
+ },
181
+ {
182
+ name: 'Upload Video',
183
+ value: 'uploadVideo',
184
+ description: 'Upload an MP4 from binary data',
185
+ action: 'Upload a video',
186
+ },
187
+ ],
188
+ default: 'uploadVideo',
189
+ },
110
190
  {
111
191
  displayName: 'Input Binary Field',
112
192
  name: 'binaryPropertyName',
113
193
  type: 'string',
114
194
  default: 'data',
115
195
  required: true,
116
- displayOptions: { show: { operation: ['upload'] } },
117
- description: 'Name of the binary property that holds the image to upload',
196
+ displayOptions: { show: { operation: ['upload', 'uploadVideo'] } },
197
+ description: 'Name of the binary property that holds the image or MP4 to upload',
118
198
  },
119
199
  {
120
200
  displayName: 'Image URL',
@@ -136,14 +216,45 @@ class PixelVault {
136
216
  displayOptions: { show: { operation: ['updateMetadata'] } },
137
217
  description: 'ID of the image whose metadata to replace',
138
218
  },
219
+ {
220
+ displayName: 'Video URL',
221
+ name: 'videoUrl',
222
+ type: 'string',
223
+ default: '',
224
+ required: true,
225
+ placeholder: 'https://example.com/video.mp4',
226
+ displayOptions: { show: { operation: ['importVideo'] } },
227
+ description: 'A public HTTPS URL that returns MP4 bytes. Authenticated sources must be downloaded in n8n first.',
228
+ },
229
+ {
230
+ displayName: 'Video ID',
231
+ name: 'videoId',
232
+ type: 'string',
233
+ default: '',
234
+ required: true,
235
+ placeholder: 'vid_abc123',
236
+ displayOptions: {
237
+ show: {
238
+ operation: [
239
+ 'getVideo',
240
+ 'optimizeVideo',
241
+ 'enrichVideo',
242
+ 'updateVideo',
243
+ 'signVideo',
244
+ 'deleteVideo',
245
+ ],
246
+ },
247
+ },
248
+ description: 'Stable video asset ID. Reuse it to resume an asynchronous workflow.',
249
+ },
139
250
  {
140
251
  displayName: 'Metadata (JSON)',
141
252
  name: 'metadata',
142
253
  type: 'json',
143
254
  default: '{}',
144
255
  required: true,
145
- displayOptions: { show: { operation: ['updateMetadata'] } },
146
- description: 'The full metadata object to store. It replaces the existing metadata (it is not merged), so include every key you want to keep. {} clears it. Up to 50 top-level keys and 4 KB.',
256
+ displayOptions: { show: { operation: ['updateMetadata', 'updateVideo'] } },
257
+ description: 'The full metadata object to store. It replaces the existing metadata; {} clears it. Up to 50 top-level keys and 4 KB.',
147
258
  },
148
259
  {
149
260
  displayName: 'Options',
@@ -151,13 +262,38 @@ class PixelVault {
151
262
  type: 'collection',
152
263
  placeholder: 'Add Option',
153
264
  default: {},
154
- displayOptions: { show: { operation: ['upload', 'importUrl'] } },
265
+ displayOptions: {
266
+ show: {
267
+ operation: [
268
+ 'upload',
269
+ 'importUrl',
270
+ 'uploadVideo',
271
+ 'importVideo',
272
+ 'listVideos',
273
+ 'optimizeVideo',
274
+ 'enrichVideo',
275
+ 'updateVideo',
276
+ 'signVideo',
277
+ ],
278
+ },
279
+ },
155
280
  options: [
281
+ {
282
+ displayName: 'Collection ID',
283
+ name: 'collectionId',
284
+ type: 'string',
285
+ default: '',
286
+ displayOptions: {
287
+ show: { operation: ['uploadVideo', 'importVideo', 'listVideos', 'updateVideo'] },
288
+ },
289
+ description: 'Existing collection membership, or a collection filter when listing',
290
+ },
156
291
  {
157
292
  displayName: 'Describe With AI',
158
293
  name: 'describe',
159
294
  type: 'boolean',
160
295
  default: false,
296
+ displayOptions: { show: { operation: ['upload', 'importUrl'] } },
161
297
  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
298
  },
163
299
  {
@@ -165,21 +301,70 @@ class PixelVault {
165
301
  name: 'expiresIn',
166
302
  type: 'number',
167
303
  default: 0,
168
- description: 'Delete the image automatically after this many seconds (60 to 2,592,000). 0 keeps it.',
304
+ displayOptions: { show: { operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo'] } },
305
+ description: 'Delete the asset automatically after this many seconds (60 to 2,592,000). 0 keeps it.',
169
306
  },
170
307
  {
171
308
  displayName: 'Folder',
172
309
  name: 'folder',
173
310
  type: 'string',
174
311
  default: '',
312
+ displayOptions: {
313
+ show: {
314
+ operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo', 'listVideos', 'updateVideo'],
315
+ },
316
+ },
175
317
  description: 'Optional folder name (letters, numbers, hyphens and underscores)',
176
318
  },
319
+ {
320
+ displayName: 'Idempotency Key',
321
+ name: 'idempotencyKey',
322
+ type: 'string',
323
+ default: '',
324
+ displayOptions: { show: { operation: ['uploadVideo', 'importVideo'] } },
325
+ description: 'Stable key for safely retrying this upload/import. Reuse with identical input; conflicting reuse fails.',
326
+ },
177
327
  {
178
328
  displayName: 'Metadata (JSON)',
179
329
  name: 'metadata',
180
330
  type: 'json',
181
331
  default: '',
182
- description: 'Custom key/values to store with the image, for example {"env": "prod"}. Up to 50 top-level keys and 4 KB. Change it later with Update Image Metadata.',
332
+ displayOptions: {
333
+ show: { operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo', 'listVideos'] },
334
+ },
335
+ description: 'Custom key/values to store or match, for example {"env": "prod"}. Up to 50 top-level keys and 4 KB.',
336
+ },
337
+ {
338
+ displayName: 'Optimize For Social',
339
+ name: 'socialReady',
340
+ type: 'boolean',
341
+ default: false,
342
+ displayOptions: { show: { operation: ['uploadVideo', 'importVideo'] } },
343
+ description: 'Whether to start social-ready H.264/AAC fast-start optimization after upload',
344
+ },
345
+ {
346
+ displayName: 'Page',
347
+ name: 'page',
348
+ type: 'number',
349
+ default: 1,
350
+ typeOptions: { minValue: 1 },
351
+ displayOptions: { show: { operation: ['listVideos'] } },
352
+ },
353
+ {
354
+ displayName: 'Per Page',
355
+ name: 'perPage',
356
+ type: 'number',
357
+ default: 20,
358
+ typeOptions: { minValue: 1, maxValue: 100 },
359
+ displayOptions: { show: { operation: ['listVideos'] } },
360
+ },
361
+ {
362
+ displayName: 'Signed URL Expiry (Seconds)',
363
+ name: 'signExpiresIn',
364
+ type: 'number',
365
+ default: 3600,
366
+ displayOptions: { show: { operation: ['uploadVideo', 'importVideo', 'signVideo'] } },
367
+ description: 'Private URL lifetime, from 60 to 2,592,000 seconds',
183
368
  },
184
369
  {
185
370
  displayName: 'Visibility',
@@ -190,22 +375,41 @@ class PixelVault {
190
375
  { name: 'Private (Signed URL)', value: 'private' },
191
376
  ],
192
377
  default: 'public',
193
- description: 'Private images are returned as time-limited signed URLs',
378
+ displayOptions: { show: { operation: ['upload', 'importUrl', 'uploadVideo', 'importVideo'] } },
379
+ description: 'Private media is returned with time-limited signed URLs',
380
+ },
381
+ {
382
+ displayName: 'Wait For Completion',
383
+ name: 'waitForCompletion',
384
+ type: 'boolean',
385
+ default: false,
386
+ displayOptions: { show: { operation: ['optimizeVideo', 'enrichVideo'] } },
387
+ description: 'Whether to poll with bounded backoff. Leave off to return the asset and job IDs immediately and resume later with Get Video.',
194
388
  },
195
389
  {
196
390
  displayName: 'Wait For Description',
197
391
  name: 'waitForDescription',
198
392
  type: 'boolean',
199
393
  default: false,
394
+ displayOptions: { show: { operation: ['upload', 'importUrl'] } },
200
395
  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
396
  },
397
+ {
398
+ displayName: 'Wait Timeout (Seconds)',
399
+ name: 'waitTimeoutSeconds',
400
+ type: 'number',
401
+ default: 600,
402
+ typeOptions: { minValue: 1, maxValue: 3600 },
403
+ displayOptions: { show: { operation: ['optimizeVideo', 'enrichVideo'] } },
404
+ description: 'Local polling limit. Timing out does not cancel the server job.',
405
+ },
202
406
  ],
203
407
  },
204
408
  ],
205
409
  };
206
410
  }
207
411
  async execute() {
208
- var _a, _b, _c, _d;
412
+ var _a, _b, _c, _d, _e, _f, _g, _h;
209
413
  const items = this.getInputData();
210
414
  const returnData = [];
211
415
  const operation = this.getNodeParameter('operation', 0);
@@ -219,7 +423,7 @@ class PixelVault {
219
423
  }
220
424
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), expiresError, { itemIndex: i });
221
425
  }
222
- const metadataSource = operation === 'updateMetadata'
426
+ const metadataSource = operation === 'updateMetadata' || operation === 'updateVideo'
223
427
  ? this.getNodeParameter('metadata', i, '{}')
224
428
  : options.metadata;
225
429
  const { metadata, error: metadataError } = parseMetadata(metadataSource);
@@ -273,33 +477,161 @@ class PixelVault {
273
477
  json: true,
274
478
  };
275
479
  }
480
+ else if (operation === 'uploadVideo') {
481
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
482
+ const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
483
+ const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
484
+ const headers = {
485
+ 'Content-Type': 'video/mp4',
486
+ 'Content-Length': String(buffer.length),
487
+ 'X-PixelVault-Filename': encodeURIComponent((_b = binaryData.fileName) !== null && _b !== void 0 ? _b : 'video.mp4'),
488
+ };
489
+ if (options.visibility)
490
+ headers['X-PixelVault-Visibility'] = options.visibility;
491
+ if (expiresIn !== undefined)
492
+ headers['X-PixelVault-Expires-In'] = String(expiresIn);
493
+ if (options.folder)
494
+ headers['X-PixelVault-Folder'] = options.folder;
495
+ if (options.collectionId)
496
+ headers['X-PixelVault-Collection-Id'] = options.collectionId;
497
+ if (metadata && Object.keys(metadata).length > 0) {
498
+ headers['X-PixelVault-Metadata'] = JSON.stringify(metadata);
499
+ }
500
+ if (options.socialReady)
501
+ headers['X-PixelVault-Social-Ready'] = 'true';
502
+ if (options.signExpiresIn) {
503
+ headers['X-PixelVault-Sign-Expires-In'] = String(options.signExpiresIn);
504
+ }
505
+ if (options.idempotencyKey) {
506
+ headers['Idempotency-Key'] = options.idempotencyKey;
507
+ headers['X-PixelVault-Content-SHA256'] = (0, node_crypto_1.createHash)('sha256').update(buffer).digest('hex');
508
+ }
509
+ requestOptions = { method: 'POST', url: VIDEOS_URL, headers, body: buffer };
510
+ }
511
+ else if (operation === 'importVideo') {
512
+ const videoUrl = this.getNodeParameter('videoUrl', i);
513
+ const body = { url: videoUrl };
514
+ if (options.visibility)
515
+ body.visibility = options.visibility;
516
+ if (expiresIn !== undefined)
517
+ body.expires_in = expiresIn;
518
+ if (options.folder)
519
+ body.folder = options.folder;
520
+ if (options.collectionId)
521
+ body.collection_id = options.collectionId;
522
+ if (metadata && Object.keys(metadata).length > 0)
523
+ body.metadata = metadata;
524
+ if (options.socialReady)
525
+ body.social_ready = true;
526
+ if (options.signExpiresIn)
527
+ body.sign_expires_in = options.signExpiresIn;
528
+ requestOptions = {
529
+ method: 'POST',
530
+ url: VIDEOS_URL,
531
+ headers: options.idempotencyKey ? { 'Idempotency-Key': options.idempotencyKey } : {},
532
+ body,
533
+ json: true,
534
+ };
535
+ }
536
+ else if (operation === 'listVideos') {
537
+ const qs = {};
538
+ if (options.page)
539
+ qs.page = options.page;
540
+ if (options.perPage)
541
+ qs.per_page = options.perPage;
542
+ if (options.folder)
543
+ qs.folder = options.folder;
544
+ if (options.collectionId)
545
+ qs.collection_id = options.collectionId;
546
+ if (metadata && Object.keys(metadata).length > 0)
547
+ qs.metadata = JSON.stringify(metadata);
548
+ requestOptions = { method: 'GET', url: VIDEOS_URL, qs, json: true };
549
+ }
276
550
  else {
277
- throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`, {
278
- itemIndex: i,
279
- });
551
+ const videoId = this.getNodeParameter('videoId', i, '');
552
+ const videoUrl = `${VIDEOS_URL}/${encodeURIComponent(videoId)}`;
553
+ if (operation === 'getVideo') {
554
+ requestOptions = { method: 'GET', url: videoUrl, json: true };
555
+ }
556
+ else if (operation === 'deleteVideo') {
557
+ requestOptions = { method: 'DELETE', url: videoUrl, json: true };
558
+ }
559
+ else if (operation === 'signVideo') {
560
+ requestOptions = {
561
+ method: 'POST',
562
+ url: `${videoUrl}/sign-url`,
563
+ body: options.signExpiresIn ? { expires_in: options.signExpiresIn } : {},
564
+ json: true,
565
+ };
566
+ }
567
+ else if (operation === 'updateVideo') {
568
+ const body = { metadata: metadata !== null && metadata !== void 0 ? metadata : {} };
569
+ if (options.folder !== undefined)
570
+ body.folder = options.folder || null;
571
+ if (options.collectionId !== undefined)
572
+ body.collection_id = options.collectionId || null;
573
+ requestOptions = { method: 'PATCH', url: videoUrl, body, json: true };
574
+ }
575
+ else if (operation === 'optimizeVideo' || operation === 'enrichVideo') {
576
+ const action = operation === 'optimizeVideo' ? 'optimize' : 'enrich';
577
+ requestOptions = { method: 'POST', url: `${videoUrl}/${action}`, json: true };
578
+ }
579
+ else {
580
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Unknown operation: ${operation}`, {
581
+ itemIndex: i,
582
+ });
583
+ }
280
584
  }
281
585
  const response = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', requestOptions));
282
586
  const parsed = (typeof response === 'string' ? JSON.parse(response) : response);
283
- const image = ((_b = parsed.data) !== null && _b !== void 0 ? _b : parsed);
284
- const description = image.description;
587
+ let output;
588
+ if (operation === 'listVideos') {
589
+ output = { videos: (_c = parsed.data) !== null && _c !== void 0 ? _c : [], meta: (_d = parsed.meta) !== null && _d !== void 0 ? _d : {} };
590
+ }
591
+ else {
592
+ output = ((_e = parsed.data) !== null && _e !== void 0 ? _e : parsed);
593
+ }
594
+ const description = output.description;
285
595
  if (options.describe &&
286
596
  options.waitForDescription &&
287
597
  operation !== 'updateMetadata' &&
288
- typeof image.id === 'string' &&
598
+ typeof output.id === 'string' &&
289
599
  (description === null || description === void 0 ? void 0 : description.status) === 'pending') {
290
600
  const deadline = Date.now() + DESCRIBE_MAX_WAIT_MS;
291
601
  for (;;) {
292
602
  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(image.id)}`, json: true }));
603
+ const polled = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', { method: 'GET', url: `${IMAGES_URL}/${encodeURIComponent(output.id)}`, json: true }));
294
604
  const polledData = (typeof polled === 'string' ? JSON.parse(polled) : polled).data;
295
- image.description = (_c = polledData === null || polledData === void 0 ? void 0 : polledData.description) !== null && _c !== void 0 ? _c : null;
296
- if (((_d = image.description) === null || _d === void 0 ? void 0 : _d.status) !== 'pending')
605
+ output.description = (_f = polledData === null || polledData === void 0 ? void 0 : polledData.description) !== null && _f !== void 0 ? _f : null;
606
+ if (((_g = output.description) === null || _g === void 0 ? void 0 : _g.status) !== 'pending')
297
607
  break;
298
608
  if (Date.now() >= deadline)
299
609
  break;
300
610
  }
301
611
  }
302
- returnData.push({ json: image, pairedItem: { item: i } });
612
+ if ((operation === 'optimizeVideo' || operation === 'enrichVideo') &&
613
+ options.waitForCompletion &&
614
+ typeof output.id === 'string') {
615
+ const pollingVideoId = output.id;
616
+ const deadline = Date.now() + ((_h = options.waitTimeoutSeconds) !== null && _h !== void 0 ? _h : 600) * 1000;
617
+ let delay = VIDEO_POLL_INITIAL_MS;
618
+ const jobField = operation === 'enrichVideo' ? 'enrichment' : 'social_optimization';
619
+ for (;;) {
620
+ const job = output[jobField];
621
+ if ((job === null || job === void 0 ? void 0 : job.status) !== 'pending' && (job === null || job === void 0 ? void 0 : job.status) !== 'processing')
622
+ break;
623
+ const remaining = deadline - Date.now();
624
+ if (remaining <= 0) {
625
+ output.wait_timed_out = true;
626
+ break;
627
+ }
628
+ await (0, n8n_workflow_1.sleep)(Math.min(delay, remaining));
629
+ const polled = (await this.helpers.httpRequestWithAuthentication.call(this, 'pixelVaultApi', { method: 'GET', url: `${VIDEOS_URL}/${encodeURIComponent(pollingVideoId)}`, json: true }));
630
+ output = (typeof polled === 'string' ? JSON.parse(polled) : polled).data;
631
+ delay = Math.min(Math.ceil(delay * 1.5), VIDEO_POLL_MAX_MS);
632
+ }
633
+ }
634
+ returnData.push({ json: output, pairedItem: { item: i } });
303
635
  }
304
636
  catch (error) {
305
637
  if (this.continueOnFail()) {