tessa 2.0 → 6.0.0.rc2
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 +4 -4
- data/README.md +11 -18
- data/app/assets/javascripts/tessa.esm.js +212 -173
- data/app/assets/javascripts/tessa.js +206 -167
- data/app/javascript/activestorage/file_checksum.ts +76 -0
- data/app/javascript/tessa/index.ts +264 -0
- data/app/javascript/tessa/types.ts +34 -0
- data/config/routes.rb +0 -1
- data/lib/tessa/simple_form/asset_input.rb +24 -25
- data/lib/tessa/version.rb +1 -1
- data/lib/tessa.rb +0 -80
- data/package.json +7 -2
- data/rollup.config.js +5 -5
- data/spec/dummy/app/models/single_asset_model.rb +1 -1
- data/spec/dummy/app/models/single_asset_model_form.rb +3 -5
- data/spec/dummy/bin/rails +2 -2
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +14 -6
- data/spec/dummy/bin/yarn +9 -3
- data/spec/dummy/config/application.rb +11 -9
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +34 -5
- data/spec/dummy/config/environments/production.rb +49 -10
- data/spec/dummy/config/environments/test.rb +28 -12
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/new_framework_defaults_6_1.rb +67 -0
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +5 -0
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +1 -1
- data/spec/dummy/config/storage.yml +31 -0
- data/spec/dummy/config.ru +2 -1
- data/spec/dummy/db/migrate/20230406194400_add_service_name_to_active_storage_blobs.active_storage.rb +22 -0
- data/spec/dummy/db/migrate/20230406194401_create_active_storage_variant_records.active_storage.rb +27 -0
- data/spec/dummy/db/schema.rb +15 -7
- data/tessa.gemspec +4 -5
- data/tsconfig.json +10 -0
- data/yarn.lock +74 -7
- metadata +36 -74
- data/app/javascript/activestorage/file_checksum.js +0 -53
- data/app/javascript/tessa/index.js.coffee +0 -183
- data/lib/tasks/tessa.rake +0 -18
- data/lib/tessa/active_storage/asset_wrapper.rb +0 -32
- data/lib/tessa/asset/failure.rb +0 -37
- data/lib/tessa/asset.rb +0 -47
- data/lib/tessa/asset_change.rb +0 -49
- data/lib/tessa/asset_change_set.rb +0 -49
- data/lib/tessa/config.rb +0 -16
- data/lib/tessa/controller_helpers.rb +0 -16
- data/lib/tessa/fake_connection.rb +0 -29
- data/lib/tessa/jobs/migrate_assets_job.rb +0 -222
- data/lib/tessa/model/dynamic_extensions.rb +0 -145
- data/lib/tessa/model/field.rb +0 -77
- data/lib/tessa/model.rb +0 -94
- data/lib/tessa/rack_upload_proxy.rb +0 -41
- data/lib/tessa/response_factory.rb +0 -15
- data/lib/tessa/upload/uploads_file.rb +0 -18
- data/lib/tessa/upload.rb +0 -31
- data/lib/tessa/view_helpers.rb +0 -23
- data/spec/dummy/app/models/multiple_asset_model.rb +0 -8
- data/spec/support/remote_call_macro.rb +0 -40
- data/spec/tessa/asset/failure_spec.rb +0 -48
- data/spec/tessa/asset_change_set_spec.rb +0 -198
- data/spec/tessa/asset_change_spec.rb +0 -86
- data/spec/tessa/asset_spec.rb +0 -196
- data/spec/tessa/config_spec.rb +0 -70
- data/spec/tessa/controller_helpers_spec.rb +0 -55
- data/spec/tessa/jobs/migrate_assets_job_spec.rb +0 -247
- data/spec/tessa/model_field_spec.rb +0 -72
- data/spec/tessa/model_spec.rb +0 -325
- data/spec/tessa/rack_upload_proxy_spec.rb +0 -83
- data/spec/tessa/upload/uploads_file_spec.rb +0 -72
- data/spec/tessa/upload_spec.rb +0 -125
- data/spec/tessa_spec.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20d746d445cccc01d998f1d8bead8b92b8e0083e1858cd40ed2151785c1f4830
|
4
|
+
data.tar.gz: aa0432076ee14f238af2bf5cffdc83a0f37055246a1524ae2a05cb48e5bb3ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 386f143532a9e1a17b7149488d6d50d2affa444a3fc029653c5dca2218eef980df1963982cc64020b7aca85c7fbd7063e19a23fa0355cdebc4a0881230715585
|
7
|
+
data.tar.gz: f504a6ae2e98ee85478bb5d89ddb950533c80aa5a881f7accb336dfd36049eea8b1336c5a9f602ff6b51a4085826d76104475e3af9fdb8e17fdb0b7160a177f6
|
data/README.md
CHANGED
@@ -23,6 +23,12 @@ When that migration is completed, v2.x of this gem will remove all code that acc
|
|
23
23
|
will transition to being simply a convenience wrapper around ActiveStorage, so that we don't have to re-write as much
|
24
24
|
of our code in our frontend apps.
|
25
25
|
|
26
|
+
v6.x of this gem is compatible with ActiveStorage v6 and above. Since v6, ActiveStorage now does everything that this
|
27
|
+
gem used to do, with the exception of Dropzone integration. Therefore, tessa-client v6 only contains the following
|
28
|
+
two modules:
|
29
|
+
1. A set of Javascript utilities to integrate Dropzone.js with ActiveStorage direct uploads
|
30
|
+
2. A SimpleForm helper to write out the hidden input fields for an ActiveStorage `has_one_attached`.
|
31
|
+
|
26
32
|
## Installation
|
27
33
|
|
28
34
|
Add this line to your application's Gemfile:
|
@@ -61,17 +67,7 @@ from the user's browser.
|
|
61
67
|
|
62
68
|
To get all this working, follow these steps:
|
63
69
|
|
64
|
-
1.
|
65
|
-
in your `config/routes.rb`, `mount Tessa::Engine, at: '/'`. It's important that it is mounted at root.
|
66
|
-
|
67
|
-
You can use Authentication around the engine to prevent unauthorized uploads. With devise it's as simple as:
|
68
|
-
```rb
|
69
|
-
authenticated :user do
|
70
|
-
mount Tessa::Engine, at: '/'
|
71
|
-
end
|
72
|
-
```
|
73
|
-
|
74
|
-
2. In your application.js, require the js libraries:
|
70
|
+
1. In your application.js, require the js libraries:
|
75
71
|
```js
|
76
72
|
//= require dropzone
|
77
73
|
//= require tessa
|
@@ -79,17 +75,14 @@ You can use Authentication around the engine to prevent unauthorized uploads. W
|
|
79
75
|
Note that this only works if you are using Sprockets.
|
80
76
|
If you are using another bundler, we don't support that yet.
|
81
77
|
|
82
|
-
|
83
|
-
with Tessa `asset` declarations so far.
|
78
|
+
2. use ActiveStorage to add an attached asset
|
84
79
|
|
85
80
|
```rb
|
86
81
|
class Model < ApplicationRecord
|
87
|
-
|
88
|
-
|
89
|
-
asset :image # Note: this essentially delegates to has_one_attached
|
82
|
+
has_one_attached :image
|
90
83
|
```
|
91
84
|
|
92
|
-
|
85
|
+
3. When rendering your form, use the SimpleForm helper to render the dropzone div:
|
93
86
|
|
94
87
|
```erb
|
95
88
|
<%= f.input :image,
|
@@ -98,7 +91,7 @@ class Model < ApplicationRecord
|
|
98
91
|
hint: "Use an image that is 1440 x 288 in size (5:1 aspect ratio)" %>
|
99
92
|
```
|
100
93
|
|
101
|
-
|
94
|
+
4. Configure your ActiveStorage service to accept direct uploads.
|
102
95
|
The disk service does this automatically. The S3 service requires additional CORS configuration.
|
103
96
|
|
104
97
|
## Contributing
|
@@ -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,269 @@ var sparkMd5 = {
|
|
410
441
|
}));
|
411
442
|
})(sparkMd5);
|
412
443
|
|
413
|
-
var
|
444
|
+
var fileSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
|
414
445
|
|
415
|
-
|
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
|
460
|
+
this.md5Buffer = new sparkMd5.exports.ArrayBuffer;
|
431
461
|
this.fileReader = new FileReader;
|
432
|
-
this.fileReader.addEventListener("load", (
|
433
|
-
|
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
|
-
|
440
|
-
|
441
|
-
this.callback
|
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
|
-
|
450
|
-
|
451
|
-
|
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
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
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 = ()
|
477
|
-
|
478
|
-
|
479
|
-
|
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
|
-
|
490
|
-
|
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
|
-
|
556
|
+
_this.emit("uploadprogress", file, progress, file.upload.bytesSent);
|
499
557
|
};
|
500
|
-
xhr.onload = e
|
501
|
-
|
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
|
562
|
+
if (xhr.readyState != 4) {
|
506
563
|
return;
|
507
564
|
}
|
508
565
|
response = xhr.responseText;
|
509
|
-
if (xhr.getResponseHeader("content-type") &&
|
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 (
|
513
|
-
e = error1;
|
569
|
+
} catch (e) {
|
514
570
|
response = "Invalid JSON response from server.";
|
515
571
|
}
|
516
572
|
}
|
517
573
|
updateProgress();
|
518
|
-
if (
|
519
|
-
|
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
|
578
|
+
xhr.onerror = function() {
|
579
|
+
if (file.status == WCCDropzone.CANCELED) {
|
526
580
|
return;
|
527
581
|
}
|
528
|
-
|
582
|
+
handleError();
|
529
583
|
};
|
530
|
-
progressObj = (
|
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
|
-
|
592
|
+
Object.assign(headers, this.options.headers);
|
539
593
|
}
|
540
594
|
if (file.uploadHeaders) {
|
541
|
-
|
595
|
+
Object.assign(headers, file.uploadHeaders);
|
542
596
|
}
|
543
|
-
for (
|
544
|
-
|
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
|
-
|
549
|
-
}
|
550
|
-
uploadFiles(files) {
|
551
|
-
var
|
552
|
-
|
553
|
-
|
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
|
-
|
558
|
-
|
559
|
-
};
|
560
|
-
|
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?";
|
562
|
-
|
563
|
-
WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
|
609
|
+
};
|
610
|
+
return WCCDropzone;
|
611
|
+
}(BaseDropzone);
|
564
612
|
|
565
|
-
|
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?";
|
566
614
|
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
615
|
+
function tessaInit() {
|
616
|
+
$(".tessa-upload").each((function(i, item) {
|
617
|
+
var $item = $(item);
|
618
|
+
var directUploadURL = $item.data("direct-upload-url") || "/rails/active_storage/direct_uploads";
|
619
|
+
var options = __assign({
|
620
|
+
maxFiles: 1,
|
621
|
+
addRemoveLinks: true,
|
622
|
+
url: "UNUSED",
|
623
|
+
dictDefaultMessage: "Drop files or click to upload.",
|
624
|
+
accept: createAcceptFn({
|
625
|
+
directUploadURL: directUploadURL
|
626
|
+
})
|
627
|
+
}, $item.data("dropzone-options"));
|
628
|
+
if ($item.hasClass("multiple")) {
|
629
|
+
options.maxFiles = undefined;
|
580
630
|
}
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
631
|
+
var dropzone = new WCCDropzone(item, options);
|
632
|
+
$item.find('input[type="hidden"]').each((function(i, input) {
|
633
|
+
var _a, _b;
|
634
|
+
var $input = $(input);
|
635
|
+
var mockFile = $input.data("meta");
|
636
|
+
if (!mockFile) {
|
637
|
+
return;
|
638
|
+
}
|
639
|
+
mockFile.accepted = true;
|
640
|
+
(_a = dropzone.options.addedfile) === null || _a === void 0 ? void 0 : _a.call(dropzone, mockFile);
|
641
|
+
(_b = dropzone.options.thumbnail) === null || _b === void 0 ? void 0 : _b.call(dropzone, mockFile, mockFile.url);
|
642
|
+
dropzone.emit("complete", mockFile);
|
643
|
+
dropzone.files.push(mockFile);
|
644
|
+
}));
|
645
|
+
var inputName = $item.data("input-name") || $item.find('input[type="hidden"]').attr("name");
|
646
|
+
dropzone.on("success", (function(file) {
|
647
|
+
$('input[name="'.concat(inputName, '"]')).val(file.signedID);
|
648
|
+
}));
|
649
|
+
dropzone.on("removedfile", (function(file) {
|
650
|
+
$item.find('input[name="'.concat(inputName, '"]')).val("");
|
651
|
+
}));
|
596
652
|
}));
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
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;
|
653
|
+
$("form:has(.tessa-upload)").each((function(i, form) {
|
654
|
+
var $form = $(form);
|
655
|
+
$form.on("submit", (function(event) {
|
656
|
+
var safeToSubmit = true;
|
607
657
|
$form.find(".tessa-upload").each((function(j, dropzoneElement) {
|
608
|
-
|
609
|
-
if (file.status
|
610
|
-
|
658
|
+
dropzoneElement.dropzone.files.forEach((function(file) {
|
659
|
+
if (file.status && file.status != WCCDropzone.SUCCESS) {
|
660
|
+
safeToSubmit = false;
|
611
661
|
}
|
612
662
|
}));
|
613
663
|
}));
|
614
|
-
if (!safeToSubmit && !confirm(
|
664
|
+
if (!safeToSubmit && !confirm(uploadPendingWarning)) {
|
615
665
|
return false;
|
616
666
|
}
|
617
667
|
}));
|
618
668
|
}));
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
669
|
+
}
|
670
|
+
|
671
|
+
function createAcceptFn(_a) {
|
672
|
+
var directUploadURL = _a.directUploadURL;
|
673
|
+
return function(file, done) {
|
674
|
+
var postData = {
|
675
|
+
blob: {
|
676
|
+
filename: file.name,
|
677
|
+
byte_size: file.size,
|
678
|
+
content_type: file.type,
|
679
|
+
checksum: ""
|
680
|
+
}
|
625
681
|
};
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
}
|
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;
|
682
|
+
FileChecksum.create(file, (function(error, checksum) {
|
683
|
+
if (error) {
|
684
|
+
return done(error);
|
646
685
|
}
|
647
|
-
|
648
|
-
|
649
|
-
if (!actionInput.length) {
|
650
|
-
actionInput = $('<input type="hidden">').attr({
|
651
|
-
id: inputID,
|
652
|
-
name: `${inputPrefix}[${file.assetID}][action]`
|
653
|
-
}).appendTo(item);
|
686
|
+
if (!checksum) {
|
687
|
+
return done("Failed to generate checksum for file '".concat(file.name, "'"));
|
654
688
|
}
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
689
|
+
postData.blob["checksum"] = checksum;
|
690
|
+
$.ajax(directUploadURL, {
|
691
|
+
type: "POST",
|
692
|
+
data: postData,
|
693
|
+
success: function(response) {
|
694
|
+
file.uploadURL = response.direct_upload.url;
|
695
|
+
file.uploadMethod = "PUT";
|
696
|
+
file.uploadHeaders = response.direct_upload.headers;
|
697
|
+
file.signedID = response.signed_id;
|
698
|
+
done();
|
699
|
+
},
|
700
|
+
error: function(response) {
|
701
|
+
console.error(response);
|
702
|
+
done("Failed to initiate the upload process!");
|
703
|
+
}
|
704
|
+
});
|
664
705
|
}));
|
665
|
-
}
|
666
|
-
}
|
706
|
+
};
|
707
|
+
}
|
667
708
|
|
668
|
-
$(
|
669
|
-
return window.WCC.tessaInit();
|
670
|
-
}));
|
709
|
+
$(tessaInit);
|