-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebhook.go
More file actions
2134 lines (1971 loc) · 85.4 KB
/
webhook.go
File metadata and controls
2134 lines (1971 loc) · 85.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit
import (
"encoding/base64"
"encoding/json"
"errors"
"net/http"
"slices"
"time"
"github.com/imagekit-developer/imagekit-go/v2/internal/apijson"
"github.com/imagekit-developer/imagekit-go/v2/internal/requestconfig"
"github.com/imagekit-developer/imagekit-go/v2/option"
"github.com/imagekit-developer/imagekit-go/v2/packages/respjson"
"github.com/imagekit-developer/imagekit-go/v2/shared"
"github.com/imagekit-developer/imagekit-go/v2/shared/constant"
standardwebhooks "github.com/standard-webhooks/standard-webhooks/libraries/go"
)
// WebhookService contains methods and other services that help with interacting
// with the ImageKit API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewWebhookService] method instead.
type WebhookService struct {
Options []option.RequestOption
}
// NewWebhookService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewWebhookService(opts ...option.RequestOption) (r WebhookService) {
r = WebhookService{}
r.Options = opts
return
}
func (r *WebhookService) UnsafeUnwrap(payload []byte, opts ...option.RequestOption) (*UnsafeUnwrapWebhookEventUnion, error) {
res := &UnsafeUnwrapWebhookEventUnion{}
err := res.UnmarshalJSON(payload)
if err != nil {
return res, err
}
return res, nil
}
func (r *WebhookService) Unwrap(payload []byte, headers http.Header, opts ...option.RequestOption) (*UnwrapWebhookEventUnion, error) {
opts = slices.Concat(r.Options, opts)
cfg, err := requestconfig.PreRequestOptions(opts...)
if err != nil {
return nil, err
}
key := cfg.WebhookSecret
if key == "" {
return nil, errors.New("The WebhookSecret option must be set in order to verify webhook headers")
}
encodedKey := base64.StdEncoding.EncodeToString([]byte(key))
wh, err := standardwebhooks.NewWebhook(encodedKey)
if err != nil {
return nil, err
}
err = wh.Verify(payload, headers)
if err != nil {
return nil, err
}
res := &UnwrapWebhookEventUnion{}
err = res.UnmarshalJSON(payload)
if err != nil {
return res, err
}
return res, nil
}
type BaseWebhookEvent struct {
// Unique identifier for the event.
ID string `json:"id" api:"required"`
// The type of webhook event.
Type string `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BaseWebhookEvent) RawJSON() string { return r.JSON.raw }
func (r *BaseWebhookEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a file is created.
type FileCreateEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// Object containing details of a file or file version.
Data File `json:"data" api:"required"`
// Type of the webhook event.
Type constant.FileCreated `json:"type" default:"file.created"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r FileCreateEvent) RawJSON() string { return r.JSON.raw }
func (r *FileCreateEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a file is deleted.
type FileDeleteEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data FileDeleteEventData `json:"data" api:"required"`
// Type of the webhook event.
Type constant.FileDeleted `json:"type" default:"file.deleted"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r FileDeleteEvent) RawJSON() string { return r.JSON.raw }
func (r *FileDeleteEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FileDeleteEventData struct {
// The unique `fileId` of the deleted file.
FileID string `json:"fileId" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FileID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FileDeleteEventData) RawJSON() string { return r.JSON.raw }
func (r *FileDeleteEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a file is updated.
type FileUpdateEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// Object containing details of a file or file version.
Data File `json:"data" api:"required"`
// Type of the webhook event.
Type constant.FileUpdated `json:"type" default:"file.updated"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r FileUpdateEvent) RawJSON() string { return r.JSON.raw }
func (r *FileUpdateEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a file version is created.
type FileVersionCreateEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// Object containing details of a file or file version.
Data File `json:"data" api:"required"`
// Type of the webhook event.
Type constant.FileVersionCreated `json:"type" default:"file-version.created"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r FileVersionCreateEvent) RawJSON() string { return r.JSON.raw }
func (r *FileVersionCreateEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a file version is deleted.
type FileVersionDeleteEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data FileVersionDeleteEventData `json:"data" api:"required"`
// Type of the webhook event.
Type constant.FileVersionDeleted `json:"type" default:"file-version.deleted"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r FileVersionDeleteEvent) RawJSON() string { return r.JSON.raw }
func (r *FileVersionDeleteEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FileVersionDeleteEventData struct {
// The unique `fileId` of the deleted file.
FileID string `json:"fileId" api:"required"`
// The unique `versionId` of the deleted file version.
VersionID string `json:"versionId" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FileID respjson.Field
VersionID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FileVersionDeleteEventData) RawJSON() string { return r.JSON.raw }
func (r *FileVersionDeleteEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a post-transformation fails. The original file remains available,
// but the requested transformation could not be generated.
type UploadPostTransformErrorEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data UploadPostTransformErrorEventData `json:"data" api:"required"`
Request UploadPostTransformErrorEventRequest `json:"request" api:"required"`
Type constant.UploadPostTransformError `json:"type" default:"upload.post-transform.error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Request respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformErrorEvent) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformErrorEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformErrorEventData struct {
// Unique identifier of the originally uploaded file.
FileID string `json:"fileId" api:"required"`
// Name of the file.
Name string `json:"name" api:"required"`
// Path of the file.
Path string `json:"path" api:"required"`
Transformation UploadPostTransformErrorEventDataTransformation `json:"transformation" api:"required"`
// URL of the attempted post-transformation.
URL string `json:"url" api:"required" format:"uri"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FileID respjson.Field
Name respjson.Field
Path respjson.Field
Transformation respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformErrorEventData) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformErrorEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformErrorEventDataTransformation struct {
Error UploadPostTransformErrorEventDataTransformationError `json:"error" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Error respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformErrorEventDataTransformation) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformErrorEventDataTransformation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformErrorEventDataTransformationError struct {
// Reason for the post-transformation failure.
Reason string `json:"reason" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Reason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformErrorEventDataTransformationError) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformErrorEventDataTransformationError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformErrorEventRequest struct {
Transformation UploadPostTransformErrorEventRequestTransformation `json:"transformation" api:"required"`
// Unique identifier for the originating request.
XRequestID string `json:"x_request_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Transformation respjson.Field
XRequestID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformErrorEventRequest) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformErrorEventRequest) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformErrorEventRequestTransformation struct {
// Type of the requested post-transformation.
//
// Any of "transformation", "abs", "gif-to-video", "thumbnail".
Type string `json:"type" api:"required"`
// Only applicable if transformation type is 'abs'. Streaming protocol used.
//
// Any of "hls", "dash".
Protocol string `json:"protocol"`
// Value for the requested transformation type.
Value string `json:"value"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
Protocol respjson.Field
Value respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformErrorEventRequestTransformation) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformErrorEventRequestTransformation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a post-transformation completes successfully. The transformed
// version of the file is now ready and can be accessed via the provided URL. Note
// that each post-transformation generates a separate webhook event.
type UploadPostTransformSuccessEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data UploadPostTransformSuccessEventData `json:"data" api:"required"`
Request UploadPostTransformSuccessEventRequest `json:"request" api:"required"`
Type constant.UploadPostTransformSuccess `json:"type" default:"upload.post-transform.success"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Request respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformSuccessEvent) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformSuccessEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformSuccessEventData struct {
// Unique identifier of the originally uploaded file.
FileID string `json:"fileId" api:"required"`
// Name of the file.
Name string `json:"name" api:"required"`
// URL of the generated post-transformation.
URL string `json:"url" api:"required" format:"uri"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FileID respjson.Field
Name respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformSuccessEventData) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformSuccessEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformSuccessEventRequest struct {
Transformation UploadPostTransformSuccessEventRequestTransformation `json:"transformation" api:"required"`
// Unique identifier for the originating request.
XRequestID string `json:"x_request_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Transformation respjson.Field
XRequestID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformSuccessEventRequest) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformSuccessEventRequest) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPostTransformSuccessEventRequestTransformation struct {
// Type of the requested post-transformation.
//
// Any of "transformation", "abs", "gif-to-video", "thumbnail".
Type string `json:"type" api:"required"`
// Only applicable if transformation type is 'abs'. Streaming protocol used.
//
// Any of "hls", "dash".
Protocol string `json:"protocol"`
// Value for the requested transformation type.
Value string `json:"value"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
Protocol respjson.Field
Value respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPostTransformSuccessEventRequestTransformation) RawJSON() string { return r.JSON.raw }
func (r *UploadPostTransformSuccessEventRequestTransformation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a pre-transformation fails. The file upload may have been
// accepted, but the requested transformation could not be applied.
type UploadPreTransformErrorEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data UploadPreTransformErrorEventData `json:"data" api:"required"`
Request UploadPreTransformErrorEventRequest `json:"request" api:"required"`
Type constant.UploadPreTransformError `json:"type" default:"upload.pre-transform.error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Request respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformErrorEvent) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformErrorEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPreTransformErrorEventData struct {
// Name of the file.
Name string `json:"name" api:"required"`
// Path of the file.
Path string `json:"path" api:"required"`
Transformation UploadPreTransformErrorEventDataTransformation `json:"transformation" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Name respjson.Field
Path respjson.Field
Transformation respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformErrorEventData) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformErrorEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPreTransformErrorEventDataTransformation struct {
Error UploadPreTransformErrorEventDataTransformationError `json:"error" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Error respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformErrorEventDataTransformation) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformErrorEventDataTransformation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPreTransformErrorEventDataTransformationError struct {
// Reason for the pre-transformation failure.
Reason string `json:"reason" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Reason respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformErrorEventDataTransformationError) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformErrorEventDataTransformationError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPreTransformErrorEventRequest struct {
// The requested pre-transformation string.
Transformation string `json:"transformation" api:"required"`
// Unique identifier for the originating request.
XRequestID string `json:"x_request_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Transformation respjson.Field
XRequestID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformErrorEventRequest) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformErrorEventRequest) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a pre-transformation completes successfully. The file has been
// processed with the requested transformation and is now available in the Media
// Library.
type UploadPreTransformSuccessEvent struct {
// Timestamp of when the event occurred in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// Object containing details of a successful upload.
Data UploadPreTransformSuccessEventData `json:"data" api:"required"`
Request UploadPreTransformSuccessEventRequest `json:"request" api:"required"`
Type constant.UploadPreTransformSuccess `json:"type" default:"upload.pre-transform.success"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Request respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformSuccessEvent) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformSuccessEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Object containing details of a successful upload.
type UploadPreTransformSuccessEventData struct {
// An array of tags assigned to the uploaded file by auto tagging.
AITags []shared.AITag `json:"AITags" api:"nullable"`
// The audio codec used in the video (only for video).
AudioCodec string `json:"audioCodec"`
// The bit rate of the video in kbps (only for video).
BitRate int64 `json:"bitRate"`
// Value of custom coordinates associated with the image in the format
// `x,y,width,height`. If `customCoordinates` are not defined, then it is `null`.
// Send `customCoordinates` in `responseFields` in API request to get the value of
// this field.
CustomCoordinates string `json:"customCoordinates" api:"nullable"`
// A key-value data associated with the asset. Use `responseField` in API request
// to get `customMetadata` in the upload API response. Before setting any custom
// metadata on an asset, you have to create the field using custom metadata fields
// API. Send `customMetadata` in `responseFields` in API request to get the value
// of this field.
CustomMetadata shared.CustomMetadata `json:"customMetadata"`
// Optional text to describe the contents of the file. Can be set by the user or
// the ai-auto-description extension.
Description string `json:"description"`
// The duration of the video in seconds (only for video).
Duration int64 `json:"duration"`
// Consolidated embedded metadata associated with the file. It includes exif, iptc,
// and xmp data. Send `embeddedMetadata` in `responseFields` in API request to get
// embeddedMetadata in the upload API response.
EmbeddedMetadata shared.EmbeddedMetadata `json:"embeddedMetadata"`
// Extension names with their processing status at the time of completion of the
// request. It could have one of the following status values:
//
// `success`: The extension has been successfully applied. `failed`: The extension
// has failed and will not be retried. `pending`: The extension will finish
// processing in some time. On completion, the final status (success / failed) will
// be sent to the `webhookUrl` provided.
//
// If no extension was requested, then this parameter is not returned.
ExtensionStatus UploadPreTransformSuccessEventDataExtensionStatus `json:"extensionStatus"`
// Unique fileId. Store this fileld in your database, as this will be used to
// perform update action on this file.
FileID string `json:"fileId"`
// The relative path of the file in the media library e.g.
// `/marketing-assets/new-banner.jpg`.
FilePath string `json:"filePath"`
// Type of the uploaded file. Possible values are `image`, `non-image`.
FileType string `json:"fileType"`
// Height of the image in pixels (Only for images)
Height float64 `json:"height"`
// Is the file marked as private. It can be either `true` or `false`. Send
// `isPrivateFile` in `responseFields` in API request to get the value of this
// field.
IsPrivateFile bool `json:"isPrivateFile"`
// Is the file published or in draft state. It can be either `true` or `false`.
// Send `isPublished` in `responseFields` in API request to get the value of this
// field.
IsPublished bool `json:"isPublished"`
// Legacy metadata. Send `metadata` in `responseFields` in API request to get
// metadata in the upload API response.
Metadata Metadata `json:"metadata"`
// Name of the asset.
Name string `json:"name"`
// This field is included in the response only if the Path policy feature is
// available in the plan. It contains schema definitions for the custom metadata
// fields selected for the specified file path. Field selection can only be done
// when the Path policy feature is enabled.
//
// Keys are the names of the custom metadata fields; the value object has details
// about the custom metadata schema.
SelectedFieldsSchema shared.SelectedFieldsSchema `json:"selectedFieldsSchema"`
// Size of the image file in Bytes.
Size float64 `json:"size"`
// The array of tags associated with the asset. If no tags are set, it will be
// `null`. Send `tags` in `responseFields` in API request to get the value of this
// field.
Tags []string `json:"tags" api:"nullable"`
// In the case of an image, a small thumbnail URL.
ThumbnailURL string `json:"thumbnailUrl"`
// A publicly accessible URL of the file.
URL string `json:"url"`
// An object containing the file or file version's `id` (versionId) and `name`.
VersionInfo shared.VersionInfo `json:"versionInfo"`
// The video codec used in the video (only for video).
VideoCodec string `json:"videoCodec"`
// Width of the image in pixels (Only for Images)
Width float64 `json:"width"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AITags respjson.Field
AudioCodec respjson.Field
BitRate respjson.Field
CustomCoordinates respjson.Field
CustomMetadata respjson.Field
Description respjson.Field
Duration respjson.Field
EmbeddedMetadata respjson.Field
ExtensionStatus respjson.Field
FileID respjson.Field
FilePath respjson.Field
FileType respjson.Field
Height respjson.Field
IsPrivateFile respjson.Field
IsPublished respjson.Field
Metadata respjson.Field
Name respjson.Field
SelectedFieldsSchema respjson.Field
Size respjson.Field
Tags respjson.Field
ThumbnailURL respjson.Field
URL respjson.Field
VersionInfo respjson.Field
VideoCodec respjson.Field
Width respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformSuccessEventData) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformSuccessEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Extension names with their processing status at the time of completion of the
// request. It could have one of the following status values:
//
// `success`: The extension has been successfully applied. `failed`: The extension
// has failed and will not be retried. `pending`: The extension will finish
// processing in some time. On completion, the final status (success / failed) will
// be sent to the `webhookUrl` provided.
//
// If no extension was requested, then this parameter is not returned.
type UploadPreTransformSuccessEventDataExtensionStatus struct {
// Any of "success", "pending", "failed".
AIAutoDescription string `json:"ai-auto-description"`
// Any of "success", "pending", "failed".
AITasks string `json:"ai-tasks"`
// Any of "success", "pending", "failed".
AwsAutoTagging string `json:"aws-auto-tagging"`
// Any of "success", "pending", "failed".
GoogleAutoTagging string `json:"google-auto-tagging"`
// Any of "success", "pending", "failed".
RemoveBg string `json:"remove-bg"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AIAutoDescription respjson.Field
AITasks respjson.Field
AwsAutoTagging respjson.Field
GoogleAutoTagging respjson.Field
RemoveBg respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformSuccessEventDataExtensionStatus) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformSuccessEventDataExtensionStatus) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type UploadPreTransformSuccessEventRequest struct {
// The requested pre-transformation string.
Transformation string `json:"transformation" api:"required"`
// Unique identifier for the originating request.
XRequestID string `json:"x_request_id" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Transformation respjson.Field
XRequestID respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r UploadPreTransformSuccessEventRequest) RawJSON() string { return r.JSON.raw }
func (r *UploadPreTransformSuccessEventRequest) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when a new video transformation request is accepted for processing.
// This event confirms that ImageKit has received and queued your transformation
// request. Use this for debugging and tracking transformation lifecycle.
type VideoTransformationAcceptedEvent struct {
// Timestamp when the event was created in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data VideoTransformationAcceptedEventData `json:"data" api:"required"`
// Information about the original request that triggered the video transformation.
Request VideoTransformationAcceptedEventRequest `json:"request" api:"required"`
Type constant.VideoTransformationAccepted `json:"type" default:"video.transformation.accepted"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Request respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationAcceptedEvent) RawJSON() string { return r.JSON.raw }
func (r *VideoTransformationAcceptedEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VideoTransformationAcceptedEventData struct {
// Information about the source video asset being transformed.
Asset VideoTransformationAcceptedEventDataAsset `json:"asset" api:"required"`
// Base information about a video transformation request.
Transformation VideoTransformationAcceptedEventDataTransformation `json:"transformation" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Asset respjson.Field
Transformation respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationAcceptedEventData) RawJSON() string { return r.JSON.raw }
func (r *VideoTransformationAcceptedEventData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Information about the source video asset being transformed.
type VideoTransformationAcceptedEventDataAsset struct {
// URL to download or access the source video file.
URL string `json:"url" api:"required" format:"uri"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationAcceptedEventDataAsset) RawJSON() string { return r.JSON.raw }
func (r *VideoTransformationAcceptedEventDataAsset) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Base information about a video transformation request.
type VideoTransformationAcceptedEventDataTransformation struct {
// Type of video transformation:
//
// - `video-transformation`: Standard video processing (resize, format conversion,
// etc.)
// - `gif-to-video`: Convert animated GIF to video format
// - `video-thumbnail`: Generate thumbnail image from video
//
// Any of "video-transformation", "gif-to-video", "video-thumbnail".
Type string `json:"type" api:"required"`
// Configuration options for video transformations.
Options VideoTransformationAcceptedEventDataTransformationOptions `json:"options"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
Options respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationAcceptedEventDataTransformation) RawJSON() string { return r.JSON.raw }
func (r *VideoTransformationAcceptedEventDataTransformation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Configuration options for video transformations.
type VideoTransformationAcceptedEventDataTransformationOptions struct {
// Audio codec used for encoding (aac or opus).
//
// Any of "aac", "opus".
AudioCodec string `json:"audio_codec"`
// Whether to automatically rotate the video based on metadata.
AutoRotate bool `json:"auto_rotate"`
// Output format for the transformed video or thumbnail.
//
// Any of "mp4", "webm", "jpg", "png", "webp".
Format string `json:"format"`
// Quality setting for the output video.
Quality int64 `json:"quality"`
// Streaming protocol for adaptive bitrate streaming.
//
// Any of "HLS", "DASH".
StreamProtocol string `json:"stream_protocol"`
// Array of quality representations for adaptive bitrate streaming.
Variants []string `json:"variants"`
// Video codec used for encoding (h264, vp9, or av1).
//
// Any of "h264", "vp9", "av1".
VideoCodec string `json:"video_codec"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AudioCodec respjson.Field
AutoRotate respjson.Field
Format respjson.Field
Quality respjson.Field
StreamProtocol respjson.Field
Variants respjson.Field
VideoCodec respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationAcceptedEventDataTransformationOptions) RawJSON() string {
return r.JSON.raw
}
func (r *VideoTransformationAcceptedEventDataTransformationOptions) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Information about the original request that triggered the video transformation.
type VideoTransformationAcceptedEventRequest struct {
// Full URL of the transformation request that was submitted.
URL string `json:"url" api:"required" format:"uri"`
// Unique identifier for the originating transformation request.
XRequestID string `json:"x_request_id" api:"required"`
// User-Agent header from the original request that triggered the transformation.
UserAgent string `json:"user_agent"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
URL respjson.Field
XRequestID respjson.Field
UserAgent respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationAcceptedEventRequest) RawJSON() string { return r.JSON.raw }
func (r *VideoTransformationAcceptedEventRequest) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Triggered when an error occurs during video encoding. Listen to this webhook to
// log error reasons and debug issues. Check your origin and URL endpoint settings
// if the reason is related to download failure. For other errors, contact ImageKit
// support.
type VideoTransformationErrorEvent struct {
// Timestamp when the event was created in ISO8601 format.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
Data VideoTransformationErrorEventData `json:"data" api:"required"`
// Information about the original request that triggered the video transformation.
Request VideoTransformationErrorEventRequest `json:"request" api:"required"`
Type constant.VideoTransformationError `json:"type" default:"video.transformation.error"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreatedAt respjson.Field
Data respjson.Field
Request respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
BaseWebhookEvent
}
// Returns the unmodified JSON received from the API
func (r VideoTransformationErrorEvent) RawJSON() string { return r.JSON.raw }
func (r *VideoTransformationErrorEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type VideoTransformationErrorEventData struct {
// Information about the source video asset being transformed.
Asset VideoTransformationErrorEventDataAsset `json:"asset" api:"required"`
Transformation VideoTransformationErrorEventDataTransformation `json:"transformation" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Asset respjson.Field
Transformation respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}