tessa 6.0.1 → 6.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97d04730151300a62dbd1abc5a52d0fa768ff9170b08f3fb1e3ac40aea74278e
4
- data.tar.gz: 0fcd8e364428394587b86af49e2042bdcb14574c7c9f499164c62d235114977b
3
+ metadata.gz: 195c947f914e8b899ea4fa8b6cea489d7a8f8292e573f4090fde8759f820fb9a
4
+ data.tar.gz: 8dbaaceb8252224077755508be5e01b08bbeb93c46f5a37d141596826b54f5d3
5
5
  SHA512:
6
- metadata.gz: 44ee62a0b0fe6b810559e85c9032929b16f3ea22ac0cd2b41045a86614ad60c9e0b1aedc86e3884e51fe923d9e44ed0e5514b615af3dc99700c26ec1400a1dd3
7
- data.tar.gz: f869838f12e587ee6ced568125dca1ffd44973955a276f5d37fb5b4711829cc09b85c6b1f69f780de2bb1e83ecaf5994738a796f48fec623083efdbcb59aebe6
6
+ metadata.gz: 79912868222e71679ed0422041df9165070625ca1d5723ec5de78f47995f348ca61ce007fb70f470e45f0ae2a78330b560edc4f93e2ed650d08bcd8927db0b4c
7
+ data.tar.gz: b33ab283bf19599fb16ca5751beb078c34712f7195b35a0bc3b4b9e1855279fc331046f82c25cdd0717b6151a0870cb5d6d7ea15b6540032f3e63a4fc419e79c
@@ -1,3 +1,34 @@
1
+ var extendStatics = function(d, b) {
2
+ extendStatics = Object.setPrototypeOf || {
3
+ __proto__: []
4
+ } instanceof Array && function(d, b) {
5
+ d.__proto__ = b;
6
+ } || function(d, b) {
7
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
8
+ };
9
+ return extendStatics(d, b);
10
+ };
11
+
12
+ function __extends(d, b) {
13
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
14
+ extendStatics(d, b);
15
+ function __() {
16
+ this.constructor = d;
17
+ }
18
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __);
19
+ }
20
+
21
+ var __assign = function() {
22
+ __assign = Object.assign || function __assign(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
26
+ }
27
+ return t;
28
+ };
29
+ return __assign.apply(this, arguments);
30
+ };
31
+
1
32
  var sparkMd5 = {
2
33
  exports: {}
3
34
  };
@@ -410,261 +441,280 @@ var sparkMd5 = {
410
441
  }));
411
442
  })(sparkMd5);
412
443
 
413
- var SparkMD5 = sparkMd5.exports;
444
+ var fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
414
445
 
415
- const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
416
-
417
- class FileChecksum {
418
- static create(file, callback) {
419
- const instance = new FileChecksum(file);
420
- instance.create(callback);
421
- }
422
- constructor(file) {
446
+ var FileChecksum = function() {
447
+ function FileChecksum(file) {
423
448
  this.file = file;
424
449
  this.chunkSize = 2097152;
425
450
  this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
426
451
  this.chunkIndex = 0;
427
452
  }
428
- create(callback) {
453
+ FileChecksum.create = function(file, callback) {
454
+ var instance = new FileChecksum(file);
455
+ instance.create(callback);
456
+ };
457
+ FileChecksum.prototype.create = function(callback) {
458
+ var _this = this;
429
459
  this.callback = callback;
430
- this.md5Buffer = new SparkMD5.ArrayBuffer;
460
+ this.md5Buffer = new sparkMd5.exports.ArrayBuffer;
431
461
  this.fileReader = new FileReader;
432
- this.fileReader.addEventListener("load", (event => this.fileReaderDidLoad(event)));
433
- this.fileReader.addEventListener("error", (event => this.fileReaderDidError(event)));
462
+ this.fileReader.addEventListener("load", (function(event) {
463
+ return _this.fileReaderDidLoad(event);
464
+ }));
465
+ this.fileReader.addEventListener("error", (function(event) {
466
+ return _this.fileReaderDidError(event);
467
+ }));
434
468
  this.readNextChunk();
435
- }
436
- fileReaderDidLoad(event) {
469
+ };
470
+ FileChecksum.prototype.fileReaderDidLoad = function(event) {
471
+ var _a;
472
+ if (!this.md5Buffer || !this.fileReader) {
473
+ throw new Error("FileChecksum: fileReaderDidLoad called before create");
474
+ }
475
+ if (!((_a = event.target) === null || _a === void 0 ? void 0 : _a.result)) {
476
+ return;
477
+ }
437
478
  this.md5Buffer.append(event.target.result);
438
479
  if (!this.readNextChunk()) {
439
- const binaryDigest = this.md5Buffer.end(true);
440
- const base64digest = btoa(binaryDigest);
441
- this.callback(null, base64digest);
480
+ var binaryDigest = this.md5Buffer.end(true);
481
+ var base64digest = btoa(binaryDigest);
482
+ if (this.callback) {
483
+ this.callback(null, base64digest);
484
+ }
485
+ }
486
+ };
487
+ FileChecksum.prototype.fileReaderDidError = function(event) {
488
+ if (this.callback) {
489
+ this.callback("Error reading ".concat(this.file.name));
490
+ }
491
+ };
492
+ FileChecksum.prototype.readNextChunk = function() {
493
+ if (!this.fileReader) {
494
+ throw new Error("FileChecksum: readNextChunk called before create");
442
495
  }
443
- }
444
- fileReaderDidError(event) {
445
- this.callback(`Error reading ${this.file.name}`);
446
- }
447
- readNextChunk() {
448
496
  if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {
449
- const start = this.chunkIndex * this.chunkSize;
450
- const end = Math.min(start + this.chunkSize, this.file.size);
451
- const bytes = fileSlice.call(this.file, start, end);
497
+ var start = this.chunkIndex * this.chunkSize;
498
+ var end = Math.min(start + this.chunkSize, this.file.size);
499
+ var bytes = fileSlice.call(this.file, start, end);
452
500
  this.fileReader.readAsArrayBuffer(bytes);
453
501
  this.chunkIndex++;
454
502
  return true;
455
503
  } else {
456
504
  return false;
457
505
  }
458
- }
459
- }
460
-
461
- var $;
506
+ };
507
+ return FileChecksum;
508
+ }();
462
509
 
463
510
  window.WCC || (window.WCC = {});
464
511
 
465
- $ = window.jQuery;
512
+ var $ = window.jQuery;
466
513
 
467
- Dropzone.autoDiscover = false;
514
+ window.Dropzone.autoDiscover = false;
468
515
 
469
- window.WCC.Dropzone = class Dropzone extends window.Dropzone {
470
- uploadFile(file) {
471
- var handleError, headerName, headerValue, headers, progressObj, ref, response, updateProgress, xhr;
472
- xhr = new XMLHttpRequest;
516
+ var BaseDropzone = window.Dropzone;
517
+
518
+ var WCCDropzone = function(_super) {
519
+ __extends(WCCDropzone, _super);
520
+ function WCCDropzone() {
521
+ return _super !== null && _super.apply(this, arguments) || this;
522
+ }
523
+ WCCDropzone.prototype.uploadFile = function(file) {
524
+ var _this = this;
525
+ var _a;
526
+ var xhr = new XMLHttpRequest;
473
527
  file.xhr = xhr;
474
528
  xhr.open(file.uploadMethod, file.uploadURL, true);
475
- response = null;
476
- handleError = () => this._errorProcessing([ file ], response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
477
- updateProgress = e => {
478
- var allFilesFinished, progress;
479
- if (e != null) {
529
+ var response = null;
530
+ var handleError = function() {
531
+ var _a;
532
+ _this._errorProcessing([ file ], response || ((_a = _this.options.dictResponseError) === null || _a === void 0 ? void 0 : _a.replace("{{statusCode}}", xhr.status.toString())), xhr);
533
+ };
534
+ var updateProgress = function(e) {
535
+ var _a;
536
+ var progress;
537
+ if (e) {
480
538
  progress = 100 * e.loaded / e.total;
481
- file.upload = {
539
+ file.upload = __assign(__assign({}, file.upload), {
482
540
  progress: progress,
483
541
  total: e.total,
484
542
  bytesSent: e.loaded
485
- };
543
+ });
486
544
  } else {
487
- allFilesFinished = true;
488
545
  progress = 100;
489
- if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
490
- allFilesFinished = false;
546
+ var allFilesFinished = false;
547
+ if (file.upload.progress == 100 && file.upload.bytesSent == file.upload.total) {
548
+ allFilesFinished = true;
491
549
  }
492
550
  file.upload.progress = progress;
493
- file.upload.bytesSent = file.upload.total;
551
+ file.upload.bytesSent = (_a = file.upload) === null || _a === void 0 ? void 0 : _a.total;
494
552
  if (allFilesFinished) {
495
553
  return;
496
554
  }
497
555
  }
498
- return this.emit("uploadprogress", file, progress, file.upload.bytesSent);
556
+ _this.emit("uploadprogress", file, progress, file.upload.bytesSent);
499
557
  };
500
- xhr.onload = e => {
501
- var ref;
502
- if (file.status === WCC.Dropzone.CANCELED) {
558
+ xhr.onload = function(e) {
559
+ if (file.status == WCCDropzone.CANCELED) {
503
560
  return;
504
561
  }
505
- if (xhr.readyState !== 4) {
562
+ if (xhr.readyState != 4) {
506
563
  return;
507
564
  }
508
565
  response = xhr.responseText;
509
- if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
566
+ if (xhr.getResponseHeader("content-type") && xhr.getResponseHeader("content-type").indexOf("application/json") >= 0) {
510
567
  try {
511
568
  response = JSON.parse(response);
512
- } catch (error1) {
513
- e = error1;
569
+ } catch (e) {
514
570
  response = "Invalid JSON response from server.";
515
571
  }
516
572
  }
517
573
  updateProgress();
518
- if (!(200 <= (ref = xhr.status) && ref < 300)) {
519
- return handleError();
520
- } else {
521
- return this._finished([ file ], response, e);
574
+ if (xhr.status < 200 || xhr.status >= 300) handleError(); else {
575
+ _this._finished([ file ], response, e);
522
576
  }
523
577
  };
524
- xhr.onerror = () => {
525
- if (file.status === WCC.Dropzone.CANCELED) {
578
+ xhr.onerror = function() {
579
+ if (file.status == WCCDropzone.CANCELED) {
526
580
  return;
527
581
  }
528
- return handleError();
582
+ handleError();
529
583
  };
530
- progressObj = (ref = xhr.upload) != null ? ref : xhr;
584
+ var progressObj = (_a = xhr.upload) !== null && _a !== void 0 ? _a : xhr;
531
585
  progressObj.onprogress = updateProgress;
532
- headers = {
586
+ var headers = {
533
587
  Accept: "application/json",
534
588
  "Cache-Control": "no-cache",
535
589
  "X-Requested-With": "XMLHttpRequest"
536
590
  };
537
591
  if (this.options.headers) {
538
- $.extend(headers, this.options.headers);
592
+ Object.assign(headers, this.options.headers);
539
593
  }
540
594
  if (file.uploadHeaders) {
541
- $.extend(headers, file.uploadHeaders);
595
+ Object.assign(headers, file.uploadHeaders);
542
596
  }
543
- for (headerName in headers) {
544
- headerValue = headers[headerName];
597
+ for (var _i = 0, _b = Object.entries(headers); _i < _b.length; _i++) {
598
+ var _c = _b[_i], headerName = _c[0], headerValue = _c[1];
545
599
  xhr.setRequestHeader(headerName, headerValue);
546
600
  }
547
601
  this.emit("sending", file, xhr);
548
- return xhr.send(file);
549
- }
550
- uploadFiles(files) {
551
- var file, l, len, results;
552
- results = [];
553
- for (l = 0, len = files.length; l < len; l++) {
554
- file = files[l];
555
- results.push(this.uploadFile(file));
602
+ xhr.send(file);
603
+ };
604
+ WCCDropzone.prototype.uploadFiles = function(files) {
605
+ for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
606
+ var file = files_1[_i];
607
+ this.uploadFile(file);
556
608
  }
557
- return results;
558
- }
559
- };
609
+ };
610
+ return WCCDropzone;
611
+ }(BaseDropzone);
560
612
 
561
- WCC.Dropzone.uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
613
+ var uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
562
614
 
563
- WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
615
+ var kb = 1e3;
564
616
 
565
- WCC.Dropzone.prototype.defaultOptions.dictDefaultMessage = "Drop files or click to upload.";
617
+ var mb = 1e3 * kb;
566
618
 
567
- WCC.Dropzone.prototype.defaultOptions.accept = function(file, done) {
568
- var dz, postData, tessaParams;
569
- dz = $(file._removeLink).closest(".tessa-upload").first();
570
- tessaParams = dz.data("tessa-params") || {};
571
- postData = {
572
- name: file.name,
573
- size: file.size,
574
- mime_type: file.type
575
- };
576
- postData = $.extend(postData, tessaParams);
577
- return FileChecksum.create(file, (function(error, checksum) {
578
- if (error) {
579
- return done(error);
619
+ var gb = 1e3 * mb;
620
+
621
+ function tessaInit() {
622
+ $(".tessa-upload").each((function(i, item) {
623
+ var $item = $(item);
624
+ var directUploadURL = $item.data("direct-upload-url") || "/rails/active_storage/direct_uploads";
625
+ var options = __assign({
626
+ maxFiles: 1,
627
+ maxFilesize: 5 * gb,
628
+ addRemoveLinks: true,
629
+ url: "UNUSED",
630
+ dictDefaultMessage: "Drop files or click to upload.",
631
+ accept: createAcceptFn({
632
+ directUploadURL: directUploadURL
633
+ })
634
+ }, $item.data("dropzone-options"));
635
+ if ($item.hasClass("multiple")) {
636
+ options.maxFiles = undefined;
580
637
  }
581
- postData["checksum"] = checksum;
582
- return $.ajax("/tessa/uploads", {
583
- type: "POST",
584
- data: postData,
585
- success: function(response) {
586
- file.uploadURL = response.upload_url;
587
- file.uploadMethod = response.upload_method;
588
- file.uploadHeaders = response.upload_headers;
589
- file.assetID = response.asset_id;
590
- return done();
591
- },
592
- error: function(response) {
593
- return done("Failed to initiate the upload process!");
594
- }
595
- });
638
+ var dropzone = new WCCDropzone(item, options);
639
+ $item.find('input[type="hidden"]').each((function(i, input) {
640
+ var _a, _b;
641
+ var $input = $(input);
642
+ var mockFile = $input.data("meta");
643
+ if (!mockFile) {
644
+ return;
645
+ }
646
+ mockFile.accepted = true;
647
+ (_a = dropzone.options.addedfile) === null || _a === void 0 ? void 0 : _a.call(dropzone, mockFile);
648
+ (_b = dropzone.options.thumbnail) === null || _b === void 0 ? void 0 : _b.call(dropzone, mockFile, mockFile.url);
649
+ dropzone.emit("complete", mockFile);
650
+ dropzone.files.push(mockFile);
651
+ }));
652
+ var inputName = $item.data("input-name") || $item.find('input[type="hidden"]').attr("name");
653
+ dropzone.on("success", (function(file) {
654
+ $('input[name="'.concat(inputName, '"]')).val(file.signedID);
655
+ }));
656
+ dropzone.on("removedfile", (function(file) {
657
+ $item.find('input[name="'.concat(inputName, '"]')).val("");
658
+ }));
596
659
  }));
597
- };
598
-
599
- window.WCC.tessaInit = function(sel) {
600
- sel = sel || "form:has(.tessa-upload)";
601
- $(sel).each((function(i, form) {
602
- var $form;
603
- $form = $(form);
604
- return $form.bind("submit", (function(event) {
605
- var safeToSubmit;
606
- safeToSubmit = true;
660
+ $("form:has(.tessa-upload)").each((function(i, form) {
661
+ var $form = $(form);
662
+ $form.on("submit", (function(event) {
663
+ var safeToSubmit = true;
607
664
  $form.find(".tessa-upload").each((function(j, dropzoneElement) {
608
- return $(dropzoneElement.dropzone.files).each((function(k, file) {
609
- if (file.status != null && file.status !== WCC.Dropzone.SUCCESS) {
610
- return safeToSubmit = false;
665
+ dropzoneElement.dropzone.files.forEach((function(file) {
666
+ if (file.status && file.status != WCCDropzone.SUCCESS) {
667
+ safeToSubmit = false;
611
668
  }
612
669
  }));
613
670
  }));
614
- if (!safeToSubmit && !confirm(WCC.Dropzone.uploadPendingWarning)) {
671
+ if (!safeToSubmit && !confirm(uploadPendingWarning)) {
615
672
  return false;
616
673
  }
617
674
  }));
618
675
  }));
619
- return $(".tessa-upload", sel).each((function(i, item) {
620
- var $item, args, dropzone, inputPrefix, updateAction;
621
- $item = $(item);
622
- args = {
623
- maxFiles: 1,
624
- addRemoveLinks: true
625
- };
626
- $.extend(args, $item.data("dropzone-options"));
627
- if ($item.hasClass("multiple")) {
628
- args.maxFiles = null;
676
+ }
677
+
678
+ function createAcceptFn(_a) {
679
+ var directUploadURL = _a.directUploadURL;
680
+ return function(file, done) {
681
+ console.log("check file size", file.size, this.options.maxFilesize);
682
+ if (this.options.maxFilesize && file.size > this.options.maxFilesize) {
683
+ return done("Uploads are limited to ".concat(Math.floor(this.options.maxFilesize / gb), " Gigabytes.") + " Your file is ".concat((file.size / gb).toFixed(2), " GB.") + " Please contact helpdesk for assistance.");
629
684
  }
630
- inputPrefix = $item.data("asset-field-prefix");
631
- dropzone = new WCC.Dropzone(item, args);
632
- $item.find('input[type="hidden"]').each((function(j, input) {
633
- var $input, mockFile;
634
- $input = $(input);
635
- mockFile = $input.data("meta");
636
- mockFile.accepted = true;
637
- dropzone.options.addedfile.call(dropzone, mockFile);
638
- dropzone.options.thumbnail.call(dropzone, mockFile, mockFile.url);
639
- dropzone.emit("complete", mockFile);
640
- return dropzone.files.push(mockFile);
641
- }));
642
- updateAction = function(file) {
643
- var actionInput, inputID;
644
- if (file.assetID == null) {
645
- return;
646
- }
647
- inputID = `#tessa_asset_action_${file.assetID}`;
648
- actionInput = $(inputID);
649
- if (!actionInput.length) {
650
- actionInput = $('<input type="hidden">').attr({
651
- id: inputID,
652
- name: `${inputPrefix}[${file.assetID}][action]`
653
- }).appendTo(item);
685
+ var postData = {
686
+ blob: {
687
+ filename: file.name,
688
+ byte_size: file.size,
689
+ content_type: file.type,
690
+ checksum: ""
654
691
  }
655
- return actionInput.val(file.action);
656
692
  };
657
- dropzone.on("success", (function(file) {
658
- file.action = "add";
659
- return updateAction(file);
660
- }));
661
- return dropzone.on("removedfile", (function(file) {
662
- file.action = "remove";
663
- return updateAction(file);
693
+ FileChecksum.create(file, (function(error, checksum) {
694
+ if (error) {
695
+ return done(error);
696
+ }
697
+ if (!checksum) {
698
+ return done("Failed to generate checksum for file '".concat(file.name, "'"));
699
+ }
700
+ postData.blob["checksum"] = checksum;
701
+ $.ajax(directUploadURL, {
702
+ type: "POST",
703
+ data: postData,
704
+ success: function(response) {
705
+ file.uploadURL = response.direct_upload.url;
706
+ file.uploadMethod = "PUT";
707
+ file.uploadHeaders = response.direct_upload.headers;
708
+ file.signedID = response.signed_id;
709
+ done();
710
+ },
711
+ error: function(response) {
712
+ console.error(response);
713
+ done("Failed to initiate the upload process!");
714
+ }
715
+ });
664
716
  }));
665
- }));
666
- };
717
+ };
718
+ }
667
719
 
668
- $((function() {
669
- return window.WCC.tessaInit();
670
- }));
720
+ $(tessaInit);
@@ -2,6 +2,34 @@
2
2
  typeof define === "function" && define.amd ? define(factory) : factory();
3
3
  })((function() {
4
4
  "use strict";
5
+ var extendStatics = function(d, b) {
6
+ extendStatics = Object.setPrototypeOf || {
7
+ __proto__: []
8
+ } instanceof Array && function(d, b) {
9
+ d.__proto__ = b;
10
+ } || function(d, b) {
11
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
12
+ };
13
+ return extendStatics(d, b);
14
+ };
15
+ function __extends(d, b) {
16
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
+ extendStatics(d, b);
18
+ function __() {
19
+ this.constructor = d;
20
+ }
21
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __);
22
+ }
23
+ var __assign = function() {
24
+ __assign = Object.assign || function __assign(t) {
25
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
26
+ s = arguments[i];
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28
+ }
29
+ return t;
30
+ };
31
+ return __assign.apply(this, arguments);
32
+ };
5
33
  var sparkMd5 = {
6
34
  exports: {}
7
35
  };
@@ -412,249 +440,268 @@
412
440
  return SparkMD5;
413
441
  }));
414
442
  })(sparkMd5);
415
- var SparkMD5 = sparkMd5.exports;
416
- const fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
417
- class FileChecksum {
418
- static create(file, callback) {
419
- const instance = new FileChecksum(file);
420
- instance.create(callback);
421
- }
422
- constructor(file) {
443
+ var fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
444
+ var FileChecksum = function() {
445
+ function FileChecksum(file) {
423
446
  this.file = file;
424
447
  this.chunkSize = 2097152;
425
448
  this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
426
449
  this.chunkIndex = 0;
427
450
  }
428
- create(callback) {
451
+ FileChecksum.create = function(file, callback) {
452
+ var instance = new FileChecksum(file);
453
+ instance.create(callback);
454
+ };
455
+ FileChecksum.prototype.create = function(callback) {
456
+ var _this = this;
429
457
  this.callback = callback;
430
- this.md5Buffer = new SparkMD5.ArrayBuffer;
458
+ this.md5Buffer = new sparkMd5.exports.ArrayBuffer;
431
459
  this.fileReader = new FileReader;
432
- this.fileReader.addEventListener("load", (event => this.fileReaderDidLoad(event)));
433
- this.fileReader.addEventListener("error", (event => this.fileReaderDidError(event)));
460
+ this.fileReader.addEventListener("load", (function(event) {
461
+ return _this.fileReaderDidLoad(event);
462
+ }));
463
+ this.fileReader.addEventListener("error", (function(event) {
464
+ return _this.fileReaderDidError(event);
465
+ }));
434
466
  this.readNextChunk();
435
- }
436
- fileReaderDidLoad(event) {
467
+ };
468
+ FileChecksum.prototype.fileReaderDidLoad = function(event) {
469
+ var _a;
470
+ if (!this.md5Buffer || !this.fileReader) {
471
+ throw new Error("FileChecksum: fileReaderDidLoad called before create");
472
+ }
473
+ if (!((_a = event.target) === null || _a === void 0 ? void 0 : _a.result)) {
474
+ return;
475
+ }
437
476
  this.md5Buffer.append(event.target.result);
438
477
  if (!this.readNextChunk()) {
439
- const binaryDigest = this.md5Buffer.end(true);
440
- const base64digest = btoa(binaryDigest);
441
- this.callback(null, base64digest);
478
+ var binaryDigest = this.md5Buffer.end(true);
479
+ var base64digest = btoa(binaryDigest);
480
+ if (this.callback) {
481
+ this.callback(null, base64digest);
482
+ }
483
+ }
484
+ };
485
+ FileChecksum.prototype.fileReaderDidError = function(event) {
486
+ if (this.callback) {
487
+ this.callback("Error reading ".concat(this.file.name));
488
+ }
489
+ };
490
+ FileChecksum.prototype.readNextChunk = function() {
491
+ if (!this.fileReader) {
492
+ throw new Error("FileChecksum: readNextChunk called before create");
442
493
  }
443
- }
444
- fileReaderDidError(event) {
445
- this.callback(`Error reading ${this.file.name}`);
446
- }
447
- readNextChunk() {
448
494
  if (this.chunkIndex < this.chunkCount || this.chunkIndex == 0 && this.chunkCount == 0) {
449
- const start = this.chunkIndex * this.chunkSize;
450
- const end = Math.min(start + this.chunkSize, this.file.size);
451
- const bytes = fileSlice.call(this.file, start, end);
495
+ var start = this.chunkIndex * this.chunkSize;
496
+ var end = Math.min(start + this.chunkSize, this.file.size);
497
+ var bytes = fileSlice.call(this.file, start, end);
452
498
  this.fileReader.readAsArrayBuffer(bytes);
453
499
  this.chunkIndex++;
454
500
  return true;
455
501
  } else {
456
502
  return false;
457
503
  }
458
- }
459
- }
460
- var $;
504
+ };
505
+ return FileChecksum;
506
+ }();
461
507
  window.WCC || (window.WCC = {});
462
- $ = window.jQuery;
463
- Dropzone.autoDiscover = false;
464
- window.WCC.Dropzone = class Dropzone extends window.Dropzone {
465
- uploadFile(file) {
466
- var handleError, headerName, headerValue, headers, progressObj, ref, response, updateProgress, xhr;
467
- xhr = new XMLHttpRequest;
508
+ var $ = window.jQuery;
509
+ window.Dropzone.autoDiscover = false;
510
+ var BaseDropzone = window.Dropzone;
511
+ var WCCDropzone = function(_super) {
512
+ __extends(WCCDropzone, _super);
513
+ function WCCDropzone() {
514
+ return _super !== null && _super.apply(this, arguments) || this;
515
+ }
516
+ WCCDropzone.prototype.uploadFile = function(file) {
517
+ var _this = this;
518
+ var _a;
519
+ var xhr = new XMLHttpRequest;
468
520
  file.xhr = xhr;
469
521
  xhr.open(file.uploadMethod, file.uploadURL, true);
470
- response = null;
471
- handleError = () => this._errorProcessing([ file ], response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
472
- updateProgress = e => {
473
- var allFilesFinished, progress;
474
- if (e != null) {
522
+ var response = null;
523
+ var handleError = function() {
524
+ var _a;
525
+ _this._errorProcessing([ file ], response || ((_a = _this.options.dictResponseError) === null || _a === void 0 ? void 0 : _a.replace("{{statusCode}}", xhr.status.toString())), xhr);
526
+ };
527
+ var updateProgress = function(e) {
528
+ var _a;
529
+ var progress;
530
+ if (e) {
475
531
  progress = 100 * e.loaded / e.total;
476
- file.upload = {
532
+ file.upload = __assign(__assign({}, file.upload), {
477
533
  progress: progress,
478
534
  total: e.total,
479
535
  bytesSent: e.loaded
480
- };
536
+ });
481
537
  } else {
482
- allFilesFinished = true;
483
538
  progress = 100;
484
- if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
485
- allFilesFinished = false;
539
+ var allFilesFinished = false;
540
+ if (file.upload.progress == 100 && file.upload.bytesSent == file.upload.total) {
541
+ allFilesFinished = true;
486
542
  }
487
543
  file.upload.progress = progress;
488
- file.upload.bytesSent = file.upload.total;
544
+ file.upload.bytesSent = (_a = file.upload) === null || _a === void 0 ? void 0 : _a.total;
489
545
  if (allFilesFinished) {
490
546
  return;
491
547
  }
492
548
  }
493
- return this.emit("uploadprogress", file, progress, file.upload.bytesSent);
549
+ _this.emit("uploadprogress", file, progress, file.upload.bytesSent);
494
550
  };
495
- xhr.onload = e => {
496
- var ref;
497
- if (file.status === WCC.Dropzone.CANCELED) {
551
+ xhr.onload = function(e) {
552
+ if (file.status == WCCDropzone.CANCELED) {
498
553
  return;
499
554
  }
500
- if (xhr.readyState !== 4) {
555
+ if (xhr.readyState != 4) {
501
556
  return;
502
557
  }
503
558
  response = xhr.responseText;
504
- if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
559
+ if (xhr.getResponseHeader("content-type") && xhr.getResponseHeader("content-type").indexOf("application/json") >= 0) {
505
560
  try {
506
561
  response = JSON.parse(response);
507
- } catch (error1) {
508
- e = error1;
562
+ } catch (e) {
509
563
  response = "Invalid JSON response from server.";
510
564
  }
511
565
  }
512
566
  updateProgress();
513
- if (!(200 <= (ref = xhr.status) && ref < 300)) {
514
- return handleError();
515
- } else {
516
- return this._finished([ file ], response, e);
567
+ if (xhr.status < 200 || xhr.status >= 300) handleError(); else {
568
+ _this._finished([ file ], response, e);
517
569
  }
518
570
  };
519
- xhr.onerror = () => {
520
- if (file.status === WCC.Dropzone.CANCELED) {
571
+ xhr.onerror = function() {
572
+ if (file.status == WCCDropzone.CANCELED) {
521
573
  return;
522
574
  }
523
- return handleError();
575
+ handleError();
524
576
  };
525
- progressObj = (ref = xhr.upload) != null ? ref : xhr;
577
+ var progressObj = (_a = xhr.upload) !== null && _a !== void 0 ? _a : xhr;
526
578
  progressObj.onprogress = updateProgress;
527
- headers = {
579
+ var headers = {
528
580
  Accept: "application/json",
529
581
  "Cache-Control": "no-cache",
530
582
  "X-Requested-With": "XMLHttpRequest"
531
583
  };
532
584
  if (this.options.headers) {
533
- $.extend(headers, this.options.headers);
585
+ Object.assign(headers, this.options.headers);
534
586
  }
535
587
  if (file.uploadHeaders) {
536
- $.extend(headers, file.uploadHeaders);
588
+ Object.assign(headers, file.uploadHeaders);
537
589
  }
538
- for (headerName in headers) {
539
- headerValue = headers[headerName];
590
+ for (var _i = 0, _b = Object.entries(headers); _i < _b.length; _i++) {
591
+ var _c = _b[_i], headerName = _c[0], headerValue = _c[1];
540
592
  xhr.setRequestHeader(headerName, headerValue);
541
593
  }
542
594
  this.emit("sending", file, xhr);
543
- return xhr.send(file);
544
- }
545
- uploadFiles(files) {
546
- var file, l, len, results;
547
- results = [];
548
- for (l = 0, len = files.length; l < len; l++) {
549
- file = files[l];
550
- results.push(this.uploadFile(file));
595
+ xhr.send(file);
596
+ };
597
+ WCCDropzone.prototype.uploadFiles = function(files) {
598
+ for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
599
+ var file = files_1[_i];
600
+ this.uploadFile(file);
551
601
  }
552
- return results;
553
- }
554
- };
555
- WCC.Dropzone.uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
556
- WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
557
- WCC.Dropzone.prototype.defaultOptions.dictDefaultMessage = "Drop files or click to upload.";
558
- WCC.Dropzone.prototype.defaultOptions.accept = function(file, done) {
559
- var dz, postData, tessaParams;
560
- dz = $(file._removeLink).closest(".tessa-upload").first();
561
- tessaParams = dz.data("tessa-params") || {};
562
- postData = {
563
- name: file.name,
564
- size: file.size,
565
- mime_type: file.type
566
602
  };
567
- postData = $.extend(postData, tessaParams);
568
- return FileChecksum.create(file, (function(error, checksum) {
569
- if (error) {
570
- return done(error);
603
+ return WCCDropzone;
604
+ }(BaseDropzone);
605
+ var uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?";
606
+ var kb = 1e3;
607
+ var mb = 1e3 * kb;
608
+ var gb = 1e3 * mb;
609
+ function tessaInit() {
610
+ $(".tessa-upload").each((function(i, item) {
611
+ var $item = $(item);
612
+ var directUploadURL = $item.data("direct-upload-url") || "/rails/active_storage/direct_uploads";
613
+ var options = __assign({
614
+ maxFiles: 1,
615
+ maxFilesize: 5 * gb,
616
+ addRemoveLinks: true,
617
+ url: "UNUSED",
618
+ dictDefaultMessage: "Drop files or click to upload.",
619
+ accept: createAcceptFn({
620
+ directUploadURL: directUploadURL
621
+ })
622
+ }, $item.data("dropzone-options"));
623
+ if ($item.hasClass("multiple")) {
624
+ options.maxFiles = undefined;
571
625
  }
572
- postData["checksum"] = checksum;
573
- return $.ajax("/tessa/uploads", {
574
- type: "POST",
575
- data: postData,
576
- success: function(response) {
577
- file.uploadURL = response.upload_url;
578
- file.uploadMethod = response.upload_method;
579
- file.uploadHeaders = response.upload_headers;
580
- file.assetID = response.asset_id;
581
- return done();
582
- },
583
- error: function(response) {
584
- return done("Failed to initiate the upload process!");
585
- }
586
- });
626
+ var dropzone = new WCCDropzone(item, options);
627
+ $item.find('input[type="hidden"]').each((function(i, input) {
628
+ var _a, _b;
629
+ var $input = $(input);
630
+ var mockFile = $input.data("meta");
631
+ if (!mockFile) {
632
+ return;
633
+ }
634
+ mockFile.accepted = true;
635
+ (_a = dropzone.options.addedfile) === null || _a === void 0 ? void 0 : _a.call(dropzone, mockFile);
636
+ (_b = dropzone.options.thumbnail) === null || _b === void 0 ? void 0 : _b.call(dropzone, mockFile, mockFile.url);
637
+ dropzone.emit("complete", mockFile);
638
+ dropzone.files.push(mockFile);
639
+ }));
640
+ var inputName = $item.data("input-name") || $item.find('input[type="hidden"]').attr("name");
641
+ dropzone.on("success", (function(file) {
642
+ $('input[name="'.concat(inputName, '"]')).val(file.signedID);
643
+ }));
644
+ dropzone.on("removedfile", (function(file) {
645
+ $item.find('input[name="'.concat(inputName, '"]')).val("");
646
+ }));
587
647
  }));
588
- };
589
- window.WCC.tessaInit = function(sel) {
590
- sel = sel || "form:has(.tessa-upload)";
591
- $(sel).each((function(i, form) {
592
- var $form;
593
- $form = $(form);
594
- return $form.bind("submit", (function(event) {
595
- var safeToSubmit;
596
- safeToSubmit = true;
648
+ $("form:has(.tessa-upload)").each((function(i, form) {
649
+ var $form = $(form);
650
+ $form.on("submit", (function(event) {
651
+ var safeToSubmit = true;
597
652
  $form.find(".tessa-upload").each((function(j, dropzoneElement) {
598
- return $(dropzoneElement.dropzone.files).each((function(k, file) {
599
- if (file.status != null && file.status !== WCC.Dropzone.SUCCESS) {
600
- return safeToSubmit = false;
653
+ dropzoneElement.dropzone.files.forEach((function(file) {
654
+ if (file.status && file.status != WCCDropzone.SUCCESS) {
655
+ safeToSubmit = false;
601
656
  }
602
657
  }));
603
658
  }));
604
- if (!safeToSubmit && !confirm(WCC.Dropzone.uploadPendingWarning)) {
659
+ if (!safeToSubmit && !confirm(uploadPendingWarning)) {
605
660
  return false;
606
661
  }
607
662
  }));
608
663
  }));
609
- return $(".tessa-upload", sel).each((function(i, item) {
610
- var $item, args, dropzone, inputPrefix, updateAction;
611
- $item = $(item);
612
- args = {
613
- maxFiles: 1,
614
- addRemoveLinks: true
615
- };
616
- $.extend(args, $item.data("dropzone-options"));
617
- if ($item.hasClass("multiple")) {
618
- args.maxFiles = null;
664
+ }
665
+ function createAcceptFn(_a) {
666
+ var directUploadURL = _a.directUploadURL;
667
+ return function(file, done) {
668
+ console.log("check file size", file.size, this.options.maxFilesize);
669
+ if (this.options.maxFilesize && file.size > this.options.maxFilesize) {
670
+ return done("Uploads are limited to ".concat(Math.floor(this.options.maxFilesize / gb), " Gigabytes.") + " Your file is ".concat((file.size / gb).toFixed(2), " GB.") + " Please contact helpdesk for assistance.");
619
671
  }
620
- inputPrefix = $item.data("asset-field-prefix");
621
- dropzone = new WCC.Dropzone(item, args);
622
- $item.find('input[type="hidden"]').each((function(j, input) {
623
- var $input, mockFile;
624
- $input = $(input);
625
- mockFile = $input.data("meta");
626
- mockFile.accepted = true;
627
- dropzone.options.addedfile.call(dropzone, mockFile);
628
- dropzone.options.thumbnail.call(dropzone, mockFile, mockFile.url);
629
- dropzone.emit("complete", mockFile);
630
- return dropzone.files.push(mockFile);
631
- }));
632
- updateAction = function(file) {
633
- var actionInput, inputID;
634
- if (file.assetID == null) {
635
- return;
672
+ var postData = {
673
+ blob: {
674
+ filename: file.name,
675
+ byte_size: file.size,
676
+ content_type: file.type,
677
+ checksum: ""
636
678
  }
637
- inputID = `#tessa_asset_action_${file.assetID}`;
638
- actionInput = $(inputID);
639
- if (!actionInput.length) {
640
- actionInput = $('<input type="hidden">').attr({
641
- id: inputID,
642
- name: `${inputPrefix}[${file.assetID}][action]`
643
- }).appendTo(item);
644
- }
645
- return actionInput.val(file.action);
646
679
  };
647
- dropzone.on("success", (function(file) {
648
- file.action = "add";
649
- return updateAction(file);
650
- }));
651
- return dropzone.on("removedfile", (function(file) {
652
- file.action = "remove";
653
- return updateAction(file);
680
+ FileChecksum.create(file, (function(error, checksum) {
681
+ if (error) {
682
+ return done(error);
683
+ }
684
+ if (!checksum) {
685
+ return done("Failed to generate checksum for file '".concat(file.name, "'"));
686
+ }
687
+ postData.blob["checksum"] = checksum;
688
+ $.ajax(directUploadURL, {
689
+ type: "POST",
690
+ data: postData,
691
+ success: function(response) {
692
+ file.uploadURL = response.direct_upload.url;
693
+ file.uploadMethod = "PUT";
694
+ file.uploadHeaders = response.direct_upload.headers;
695
+ file.signedID = response.signed_id;
696
+ done();
697
+ },
698
+ error: function(response) {
699
+ console.error(response);
700
+ done("Failed to initiate the upload process!");
701
+ }
702
+ });
654
703
  }));
655
- }));
656
- };
657
- $((function() {
658
- return window.WCC.tessaInit();
659
- }));
704
+ };
705
+ }
706
+ $(tessaInit);
660
707
  }));
@@ -133,6 +133,10 @@ class WCCDropzone extends BaseDropzone {
133
133
 
134
134
  const uploadPendingWarning = "File uploads have not yet completed. If you submit the form now they will not be saved. Are you sure you want to continue?"
135
135
 
136
+ const kb = 1000
137
+ const mb = 1000 * kb
138
+ const gb = 1000 * mb
139
+
136
140
  /**
137
141
  * Called on page load to initialize the Dropzone
138
142
  */
@@ -144,6 +148,9 @@ function tessaInit() {
144
148
 
145
149
  const options: WCCDropzoneOptions = {
146
150
  maxFiles: 1,
151
+ // With a single PUT operation, you can upload a single object up to 5 GB in size.
152
+ // https://docs.aws.amazon.com/AmazonS3/latest/userguide/upload-objects.html
153
+ maxFilesize: 5 * gb,
147
154
  addRemoveLinks: true,
148
155
  url: 'UNUSED',
149
156
  dictDefaultMessage: 'Drop files or click to upload.',
@@ -221,7 +228,16 @@ interface AcceptOptions {
221
228
  * @param done Callback when file is accepted or rejected by the Tessa::RackUploadProxy
222
229
  */
223
230
  function createAcceptFn({ directUploadURL }: AcceptOptions) {
224
- return function(file: WCCDropzoneFile, done: (error?: string | Error) => void) {
231
+ return function(this: WCCDropzone, file: WCCDropzoneFile, done: (error?: string | Error) => void) {
232
+ console.log('check file size', file.size, this.options.maxFilesize)
233
+ if (this.options.maxFilesize && file.size > this.options.maxFilesize) {
234
+ return done(
235
+ `Uploads are limited to ${Math.floor(this.options.maxFilesize / gb)} Gigabytes.` +
236
+ ` Your file is ${(file.size / gb).toFixed(2)} GB.` +
237
+ ` Please contact helpdesk for assistance.`
238
+ )
239
+ }
240
+
225
241
  const postData: ActiveStorageDirectUploadParams = {
226
242
  blob: {
227
243
  filename: file.name,
data/lib/tessa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tessa
2
- VERSION = "6.0.1"
2
+ VERSION = "6.0.3"
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tessa
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Powell
8
8
  - Travis Petticrew
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-08-10 00:00:00.000000000 Z
12
+ date: 2023-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -218,7 +218,7 @@ homepage: https://github.com/watermarkchurch/tessa-client
218
218
  licenses:
219
219
  - MIT
220
220
  metadata: {}
221
- post_install_message:
221
+ post_install_message:
222
222
  rdoc_options: []
223
223
  require_paths:
224
224
  - lib
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  version: '0'
235
235
  requirements: []
236
236
  rubygems_version: 3.0.3.1
237
- signing_key:
237
+ signing_key:
238
238
  specification_version: 4
239
239
  summary: Manage your assets.
240
240
  test_files: