tessa 0.9.0 → 1.0.0.pre.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.babelrc +8 -0
- data/.circleci/config.yml +42 -0
- data/.eslintrc +19 -0
- data/.gitignore +5 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -4
- data/README.md +4 -4
- data/Rakefile +8 -0
- data/app/assets/javascripts/.keep +0 -0
- data/app/assets/javascripts/tessa.esm.js +672 -0
- data/app/assets/javascripts/tessa.js +662 -0
- data/app/javascript/activestorage/file_checksum.js +53 -0
- data/app/javascript/tessa/index.js.coffee +183 -0
- data/config/routes.rb +3 -0
- data/lib/tessa/active_storage/asset_wrapper.rb +24 -0
- data/lib/tessa/engine.rb +5 -0
- data/lib/tessa/model/dynamic_extensions.rb +151 -0
- data/lib/tessa/model.rb +35 -36
- data/lib/tessa/rack_upload_proxy.rb +18 -10
- data/lib/tessa/upload/uploads_file.rb +1 -4
- data/lib/tessa/version.rb +1 -1
- data/lib/tessa/view_helpers.rb +4 -2
- data/lib/tessa.rb +30 -0
- data/package.json +43 -0
- data/rollup.config.js +44 -0
- data/spec/dummy/.gitignore +27 -0
- data/spec/dummy/README.md +24 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/multiple_asset_model.rb +8 -0
- data/spec/dummy/app/models/single_asset_model.rb +5 -0
- data/spec/dummy/app/models/single_asset_model_form.rb +25 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +28 -0
- data/spec/dummy/bin/update +28 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +33 -0
- data/spec/dummy/config/boot.rb +3 -0
- data/spec/dummy/config/credentials.yml.enc +1 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +47 -0
- data/spec/dummy/config/environments/production.rb +76 -0
- data/spec/dummy/config/environments/test.rb +43 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +14 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +37 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/storage.yml +3 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/migrate/20220606221557_create_active_storage_tables.active_storage.rb +27 -0
- data/spec/dummy/db/migrate/20220606221900_create_single_asset_models.rb +10 -0
- data/spec/dummy/db/migrate/20220607191519_create_multiple_asset_models.rb +10 -0
- data/spec/dummy/db/schema.rb +50 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +1 -0
- data/spec/dummy/tmp/.keep +0 -0
- data/spec/dummy/vendor/.keep +0 -0
- data/spec/rails_helper.rb +14 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/tessa/model_spec.rb +195 -244
- data/spec/tessa/rack_upload_proxy_spec.rb +23 -81
- data/spec/tessa/upload/uploads_file_spec.rb +12 -8
- data/tessa.gemspec +10 -2
- data/yarn.lock +1661 -0
- metadata +196 -18
- data/circle.yml +0 -3
@@ -0,0 +1,672 @@
|
|
1
|
+
var sparkMd5 = {
|
2
|
+
exports: {}
|
3
|
+
};
|
4
|
+
|
5
|
+
(function(module, exports) {
|
6
|
+
(function(factory) {
|
7
|
+
{
|
8
|
+
module.exports = factory();
|
9
|
+
}
|
10
|
+
})((function(undefined$1) {
|
11
|
+
var hex_chr = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" ];
|
12
|
+
function md5cycle(x, k) {
|
13
|
+
var a = x[0], b = x[1], c = x[2], d = x[3];
|
14
|
+
a += (b & c | ~b & d) + k[0] - 680876936 | 0;
|
15
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
16
|
+
d += (a & b | ~a & c) + k[1] - 389564586 | 0;
|
17
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
18
|
+
c += (d & a | ~d & b) + k[2] + 606105819 | 0;
|
19
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
20
|
+
b += (c & d | ~c & a) + k[3] - 1044525330 | 0;
|
21
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
22
|
+
a += (b & c | ~b & d) + k[4] - 176418897 | 0;
|
23
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
24
|
+
d += (a & b | ~a & c) + k[5] + 1200080426 | 0;
|
25
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
26
|
+
c += (d & a | ~d & b) + k[6] - 1473231341 | 0;
|
27
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
28
|
+
b += (c & d | ~c & a) + k[7] - 45705983 | 0;
|
29
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
30
|
+
a += (b & c | ~b & d) + k[8] + 1770035416 | 0;
|
31
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
32
|
+
d += (a & b | ~a & c) + k[9] - 1958414417 | 0;
|
33
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
34
|
+
c += (d & a | ~d & b) + k[10] - 42063 | 0;
|
35
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
36
|
+
b += (c & d | ~c & a) + k[11] - 1990404162 | 0;
|
37
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
38
|
+
a += (b & c | ~b & d) + k[12] + 1804603682 | 0;
|
39
|
+
a = (a << 7 | a >>> 25) + b | 0;
|
40
|
+
d += (a & b | ~a & c) + k[13] - 40341101 | 0;
|
41
|
+
d = (d << 12 | d >>> 20) + a | 0;
|
42
|
+
c += (d & a | ~d & b) + k[14] - 1502002290 | 0;
|
43
|
+
c = (c << 17 | c >>> 15) + d | 0;
|
44
|
+
b += (c & d | ~c & a) + k[15] + 1236535329 | 0;
|
45
|
+
b = (b << 22 | b >>> 10) + c | 0;
|
46
|
+
a += (b & d | c & ~d) + k[1] - 165796510 | 0;
|
47
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
48
|
+
d += (a & c | b & ~c) + k[6] - 1069501632 | 0;
|
49
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
50
|
+
c += (d & b | a & ~b) + k[11] + 643717713 | 0;
|
51
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
52
|
+
b += (c & a | d & ~a) + k[0] - 373897302 | 0;
|
53
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
54
|
+
a += (b & d | c & ~d) + k[5] - 701558691 | 0;
|
55
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
56
|
+
d += (a & c | b & ~c) + k[10] + 38016083 | 0;
|
57
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
58
|
+
c += (d & b | a & ~b) + k[15] - 660478335 | 0;
|
59
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
60
|
+
b += (c & a | d & ~a) + k[4] - 405537848 | 0;
|
61
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
62
|
+
a += (b & d | c & ~d) + k[9] + 568446438 | 0;
|
63
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
64
|
+
d += (a & c | b & ~c) + k[14] - 1019803690 | 0;
|
65
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
66
|
+
c += (d & b | a & ~b) + k[3] - 187363961 | 0;
|
67
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
68
|
+
b += (c & a | d & ~a) + k[8] + 1163531501 | 0;
|
69
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
70
|
+
a += (b & d | c & ~d) + k[13] - 1444681467 | 0;
|
71
|
+
a = (a << 5 | a >>> 27) + b | 0;
|
72
|
+
d += (a & c | b & ~c) + k[2] - 51403784 | 0;
|
73
|
+
d = (d << 9 | d >>> 23) + a | 0;
|
74
|
+
c += (d & b | a & ~b) + k[7] + 1735328473 | 0;
|
75
|
+
c = (c << 14 | c >>> 18) + d | 0;
|
76
|
+
b += (c & a | d & ~a) + k[12] - 1926607734 | 0;
|
77
|
+
b = (b << 20 | b >>> 12) + c | 0;
|
78
|
+
a += (b ^ c ^ d) + k[5] - 378558 | 0;
|
79
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
80
|
+
d += (a ^ b ^ c) + k[8] - 2022574463 | 0;
|
81
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
82
|
+
c += (d ^ a ^ b) + k[11] + 1839030562 | 0;
|
83
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
84
|
+
b += (c ^ d ^ a) + k[14] - 35309556 | 0;
|
85
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
86
|
+
a += (b ^ c ^ d) + k[1] - 1530992060 | 0;
|
87
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
88
|
+
d += (a ^ b ^ c) + k[4] + 1272893353 | 0;
|
89
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
90
|
+
c += (d ^ a ^ b) + k[7] - 155497632 | 0;
|
91
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
92
|
+
b += (c ^ d ^ a) + k[10] - 1094730640 | 0;
|
93
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
94
|
+
a += (b ^ c ^ d) + k[13] + 681279174 | 0;
|
95
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
96
|
+
d += (a ^ b ^ c) + k[0] - 358537222 | 0;
|
97
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
98
|
+
c += (d ^ a ^ b) + k[3] - 722521979 | 0;
|
99
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
100
|
+
b += (c ^ d ^ a) + k[6] + 76029189 | 0;
|
101
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
102
|
+
a += (b ^ c ^ d) + k[9] - 640364487 | 0;
|
103
|
+
a = (a << 4 | a >>> 28) + b | 0;
|
104
|
+
d += (a ^ b ^ c) + k[12] - 421815835 | 0;
|
105
|
+
d = (d << 11 | d >>> 21) + a | 0;
|
106
|
+
c += (d ^ a ^ b) + k[15] + 530742520 | 0;
|
107
|
+
c = (c << 16 | c >>> 16) + d | 0;
|
108
|
+
b += (c ^ d ^ a) + k[2] - 995338651 | 0;
|
109
|
+
b = (b << 23 | b >>> 9) + c | 0;
|
110
|
+
a += (c ^ (b | ~d)) + k[0] - 198630844 | 0;
|
111
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
112
|
+
d += (b ^ (a | ~c)) + k[7] + 1126891415 | 0;
|
113
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
114
|
+
c += (a ^ (d | ~b)) + k[14] - 1416354905 | 0;
|
115
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
116
|
+
b += (d ^ (c | ~a)) + k[5] - 57434055 | 0;
|
117
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
118
|
+
a += (c ^ (b | ~d)) + k[12] + 1700485571 | 0;
|
119
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
120
|
+
d += (b ^ (a | ~c)) + k[3] - 1894986606 | 0;
|
121
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
122
|
+
c += (a ^ (d | ~b)) + k[10] - 1051523 | 0;
|
123
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
124
|
+
b += (d ^ (c | ~a)) + k[1] - 2054922799 | 0;
|
125
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
126
|
+
a += (c ^ (b | ~d)) + k[8] + 1873313359 | 0;
|
127
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
128
|
+
d += (b ^ (a | ~c)) + k[15] - 30611744 | 0;
|
129
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
130
|
+
c += (a ^ (d | ~b)) + k[6] - 1560198380 | 0;
|
131
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
132
|
+
b += (d ^ (c | ~a)) + k[13] + 1309151649 | 0;
|
133
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
134
|
+
a += (c ^ (b | ~d)) + k[4] - 145523070 | 0;
|
135
|
+
a = (a << 6 | a >>> 26) + b | 0;
|
136
|
+
d += (b ^ (a | ~c)) + k[11] - 1120210379 | 0;
|
137
|
+
d = (d << 10 | d >>> 22) + a | 0;
|
138
|
+
c += (a ^ (d | ~b)) + k[2] + 718787259 | 0;
|
139
|
+
c = (c << 15 | c >>> 17) + d | 0;
|
140
|
+
b += (d ^ (c | ~a)) + k[9] - 343485551 | 0;
|
141
|
+
b = (b << 21 | b >>> 11) + c | 0;
|
142
|
+
x[0] = a + x[0] | 0;
|
143
|
+
x[1] = b + x[1] | 0;
|
144
|
+
x[2] = c + x[2] | 0;
|
145
|
+
x[3] = d + x[3] | 0;
|
146
|
+
}
|
147
|
+
function md5blk(s) {
|
148
|
+
var md5blks = [], i;
|
149
|
+
for (i = 0; i < 64; i += 4) {
|
150
|
+
md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24);
|
151
|
+
}
|
152
|
+
return md5blks;
|
153
|
+
}
|
154
|
+
function md5blk_array(a) {
|
155
|
+
var md5blks = [], i;
|
156
|
+
for (i = 0; i < 64; i += 4) {
|
157
|
+
md5blks[i >> 2] = a[i] + (a[i + 1] << 8) + (a[i + 2] << 16) + (a[i + 3] << 24);
|
158
|
+
}
|
159
|
+
return md5blks;
|
160
|
+
}
|
161
|
+
function md51(s) {
|
162
|
+
var n = s.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;
|
163
|
+
for (i = 64; i <= n; i += 64) {
|
164
|
+
md5cycle(state, md5blk(s.substring(i - 64, i)));
|
165
|
+
}
|
166
|
+
s = s.substring(i - 64);
|
167
|
+
length = s.length;
|
168
|
+
tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
|
169
|
+
for (i = 0; i < length; i += 1) {
|
170
|
+
tail[i >> 2] |= s.charCodeAt(i) << (i % 4 << 3);
|
171
|
+
}
|
172
|
+
tail[i >> 2] |= 128 << (i % 4 << 3);
|
173
|
+
if (i > 55) {
|
174
|
+
md5cycle(state, tail);
|
175
|
+
for (i = 0; i < 16; i += 1) {
|
176
|
+
tail[i] = 0;
|
177
|
+
}
|
178
|
+
}
|
179
|
+
tmp = n * 8;
|
180
|
+
tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
181
|
+
lo = parseInt(tmp[2], 16);
|
182
|
+
hi = parseInt(tmp[1], 16) || 0;
|
183
|
+
tail[14] = lo;
|
184
|
+
tail[15] = hi;
|
185
|
+
md5cycle(state, tail);
|
186
|
+
return state;
|
187
|
+
}
|
188
|
+
function md51_array(a) {
|
189
|
+
var n = a.length, state = [ 1732584193, -271733879, -1732584194, 271733878 ], i, length, tail, tmp, lo, hi;
|
190
|
+
for (i = 64; i <= n; i += 64) {
|
191
|
+
md5cycle(state, md5blk_array(a.subarray(i - 64, i)));
|
192
|
+
}
|
193
|
+
a = i - 64 < n ? a.subarray(i - 64) : new Uint8Array(0);
|
194
|
+
length = a.length;
|
195
|
+
tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
|
196
|
+
for (i = 0; i < length; i += 1) {
|
197
|
+
tail[i >> 2] |= a[i] << (i % 4 << 3);
|
198
|
+
}
|
199
|
+
tail[i >> 2] |= 128 << (i % 4 << 3);
|
200
|
+
if (i > 55) {
|
201
|
+
md5cycle(state, tail);
|
202
|
+
for (i = 0; i < 16; i += 1) {
|
203
|
+
tail[i] = 0;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
tmp = n * 8;
|
207
|
+
tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
208
|
+
lo = parseInt(tmp[2], 16);
|
209
|
+
hi = parseInt(tmp[1], 16) || 0;
|
210
|
+
tail[14] = lo;
|
211
|
+
tail[15] = hi;
|
212
|
+
md5cycle(state, tail);
|
213
|
+
return state;
|
214
|
+
}
|
215
|
+
function rhex(n) {
|
216
|
+
var s = "", j;
|
217
|
+
for (j = 0; j < 4; j += 1) {
|
218
|
+
s += hex_chr[n >> j * 8 + 4 & 15] + hex_chr[n >> j * 8 & 15];
|
219
|
+
}
|
220
|
+
return s;
|
221
|
+
}
|
222
|
+
function hex(x) {
|
223
|
+
var i;
|
224
|
+
for (i = 0; i < x.length; i += 1) {
|
225
|
+
x[i] = rhex(x[i]);
|
226
|
+
}
|
227
|
+
return x.join("");
|
228
|
+
}
|
229
|
+
if (hex(md51("hello")) !== "5d41402abc4b2a76b9719d911017c592") ;
|
230
|
+
if (typeof ArrayBuffer !== "undefined" && !ArrayBuffer.prototype.slice) {
|
231
|
+
(function() {
|
232
|
+
function clamp(val, length) {
|
233
|
+
val = val | 0 || 0;
|
234
|
+
if (val < 0) {
|
235
|
+
return Math.max(val + length, 0);
|
236
|
+
}
|
237
|
+
return Math.min(val, length);
|
238
|
+
}
|
239
|
+
ArrayBuffer.prototype.slice = function(from, to) {
|
240
|
+
var length = this.byteLength, begin = clamp(from, length), end = length, num, target, targetArray, sourceArray;
|
241
|
+
if (to !== undefined$1) {
|
242
|
+
end = clamp(to, length);
|
243
|
+
}
|
244
|
+
if (begin > end) {
|
245
|
+
return new ArrayBuffer(0);
|
246
|
+
}
|
247
|
+
num = end - begin;
|
248
|
+
target = new ArrayBuffer(num);
|
249
|
+
targetArray = new Uint8Array(target);
|
250
|
+
sourceArray = new Uint8Array(this, begin, num);
|
251
|
+
targetArray.set(sourceArray);
|
252
|
+
return target;
|
253
|
+
};
|
254
|
+
})();
|
255
|
+
}
|
256
|
+
function toUtf8(str) {
|
257
|
+
if (/[\u0080-\uFFFF]/.test(str)) {
|
258
|
+
str = unescape(encodeURIComponent(str));
|
259
|
+
}
|
260
|
+
return str;
|
261
|
+
}
|
262
|
+
function utf8Str2ArrayBuffer(str, returnUInt8Array) {
|
263
|
+
var length = str.length, buff = new ArrayBuffer(length), arr = new Uint8Array(buff), i;
|
264
|
+
for (i = 0; i < length; i += 1) {
|
265
|
+
arr[i] = str.charCodeAt(i);
|
266
|
+
}
|
267
|
+
return returnUInt8Array ? arr : buff;
|
268
|
+
}
|
269
|
+
function arrayBuffer2Utf8Str(buff) {
|
270
|
+
return String.fromCharCode.apply(null, new Uint8Array(buff));
|
271
|
+
}
|
272
|
+
function concatenateArrayBuffers(first, second, returnUInt8Array) {
|
273
|
+
var result = new Uint8Array(first.byteLength + second.byteLength);
|
274
|
+
result.set(new Uint8Array(first));
|
275
|
+
result.set(new Uint8Array(second), first.byteLength);
|
276
|
+
return returnUInt8Array ? result : result.buffer;
|
277
|
+
}
|
278
|
+
function hexToBinaryString(hex) {
|
279
|
+
var bytes = [], length = hex.length, x;
|
280
|
+
for (x = 0; x < length - 1; x += 2) {
|
281
|
+
bytes.push(parseInt(hex.substr(x, 2), 16));
|
282
|
+
}
|
283
|
+
return String.fromCharCode.apply(String, bytes);
|
284
|
+
}
|
285
|
+
function SparkMD5() {
|
286
|
+
this.reset();
|
287
|
+
}
|
288
|
+
SparkMD5.prototype.append = function(str) {
|
289
|
+
this.appendBinary(toUtf8(str));
|
290
|
+
return this;
|
291
|
+
};
|
292
|
+
SparkMD5.prototype.appendBinary = function(contents) {
|
293
|
+
this._buff += contents;
|
294
|
+
this._length += contents.length;
|
295
|
+
var length = this._buff.length, i;
|
296
|
+
for (i = 64; i <= length; i += 64) {
|
297
|
+
md5cycle(this._hash, md5blk(this._buff.substring(i - 64, i)));
|
298
|
+
}
|
299
|
+
this._buff = this._buff.substring(i - 64);
|
300
|
+
return this;
|
301
|
+
};
|
302
|
+
SparkMD5.prototype.end = function(raw) {
|
303
|
+
var buff = this._buff, length = buff.length, i, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], ret;
|
304
|
+
for (i = 0; i < length; i += 1) {
|
305
|
+
tail[i >> 2] |= buff.charCodeAt(i) << (i % 4 << 3);
|
306
|
+
}
|
307
|
+
this._finish(tail, length);
|
308
|
+
ret = hex(this._hash);
|
309
|
+
if (raw) {
|
310
|
+
ret = hexToBinaryString(ret);
|
311
|
+
}
|
312
|
+
this.reset();
|
313
|
+
return ret;
|
314
|
+
};
|
315
|
+
SparkMD5.prototype.reset = function() {
|
316
|
+
this._buff = "";
|
317
|
+
this._length = 0;
|
318
|
+
this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];
|
319
|
+
return this;
|
320
|
+
};
|
321
|
+
SparkMD5.prototype.getState = function() {
|
322
|
+
return {
|
323
|
+
buff: this._buff,
|
324
|
+
length: this._length,
|
325
|
+
hash: this._hash.slice()
|
326
|
+
};
|
327
|
+
};
|
328
|
+
SparkMD5.prototype.setState = function(state) {
|
329
|
+
this._buff = state.buff;
|
330
|
+
this._length = state.length;
|
331
|
+
this._hash = state.hash;
|
332
|
+
return this;
|
333
|
+
};
|
334
|
+
SparkMD5.prototype.destroy = function() {
|
335
|
+
delete this._hash;
|
336
|
+
delete this._buff;
|
337
|
+
delete this._length;
|
338
|
+
};
|
339
|
+
SparkMD5.prototype._finish = function(tail, length) {
|
340
|
+
var i = length, tmp, lo, hi;
|
341
|
+
tail[i >> 2] |= 128 << (i % 4 << 3);
|
342
|
+
if (i > 55) {
|
343
|
+
md5cycle(this._hash, tail);
|
344
|
+
for (i = 0; i < 16; i += 1) {
|
345
|
+
tail[i] = 0;
|
346
|
+
}
|
347
|
+
}
|
348
|
+
tmp = this._length * 8;
|
349
|
+
tmp = tmp.toString(16).match(/(.*?)(.{0,8})$/);
|
350
|
+
lo = parseInt(tmp[2], 16);
|
351
|
+
hi = parseInt(tmp[1], 16) || 0;
|
352
|
+
tail[14] = lo;
|
353
|
+
tail[15] = hi;
|
354
|
+
md5cycle(this._hash, tail);
|
355
|
+
};
|
356
|
+
SparkMD5.hash = function(str, raw) {
|
357
|
+
return SparkMD5.hashBinary(toUtf8(str), raw);
|
358
|
+
};
|
359
|
+
SparkMD5.hashBinary = function(content, raw) {
|
360
|
+
var hash = md51(content), ret = hex(hash);
|
361
|
+
return raw ? hexToBinaryString(ret) : ret;
|
362
|
+
};
|
363
|
+
SparkMD5.ArrayBuffer = function() {
|
364
|
+
this.reset();
|
365
|
+
};
|
366
|
+
SparkMD5.ArrayBuffer.prototype.append = function(arr) {
|
367
|
+
var buff = concatenateArrayBuffers(this._buff.buffer, arr, true), length = buff.length, i;
|
368
|
+
this._length += arr.byteLength;
|
369
|
+
for (i = 64; i <= length; i += 64) {
|
370
|
+
md5cycle(this._hash, md5blk_array(buff.subarray(i - 64, i)));
|
371
|
+
}
|
372
|
+
this._buff = i - 64 < length ? new Uint8Array(buff.buffer.slice(i - 64)) : new Uint8Array(0);
|
373
|
+
return this;
|
374
|
+
};
|
375
|
+
SparkMD5.ArrayBuffer.prototype.end = function(raw) {
|
376
|
+
var buff = this._buff, length = buff.length, tail = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], i, ret;
|
377
|
+
for (i = 0; i < length; i += 1) {
|
378
|
+
tail[i >> 2] |= buff[i] << (i % 4 << 3);
|
379
|
+
}
|
380
|
+
this._finish(tail, length);
|
381
|
+
ret = hex(this._hash);
|
382
|
+
if (raw) {
|
383
|
+
ret = hexToBinaryString(ret);
|
384
|
+
}
|
385
|
+
this.reset();
|
386
|
+
return ret;
|
387
|
+
};
|
388
|
+
SparkMD5.ArrayBuffer.prototype.reset = function() {
|
389
|
+
this._buff = new Uint8Array(0);
|
390
|
+
this._length = 0;
|
391
|
+
this._hash = [ 1732584193, -271733879, -1732584194, 271733878 ];
|
392
|
+
return this;
|
393
|
+
};
|
394
|
+
SparkMD5.ArrayBuffer.prototype.getState = function() {
|
395
|
+
var state = SparkMD5.prototype.getState.call(this);
|
396
|
+
state.buff = arrayBuffer2Utf8Str(state.buff);
|
397
|
+
return state;
|
398
|
+
};
|
399
|
+
SparkMD5.ArrayBuffer.prototype.setState = function(state) {
|
400
|
+
state.buff = utf8Str2ArrayBuffer(state.buff, true);
|
401
|
+
return SparkMD5.prototype.setState.call(this, state);
|
402
|
+
};
|
403
|
+
SparkMD5.ArrayBuffer.prototype.destroy = SparkMD5.prototype.destroy;
|
404
|
+
SparkMD5.ArrayBuffer.prototype._finish = SparkMD5.prototype._finish;
|
405
|
+
SparkMD5.ArrayBuffer.hash = function(arr, raw) {
|
406
|
+
var hash = md51_array(new Uint8Array(arr)), ret = hex(hash);
|
407
|
+
return raw ? hexToBinaryString(ret) : ret;
|
408
|
+
};
|
409
|
+
return SparkMD5;
|
410
|
+
}));
|
411
|
+
})(sparkMd5);
|
412
|
+
|
413
|
+
var SparkMD5 = sparkMd5.exports;
|
414
|
+
|
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) {
|
423
|
+
this.file = file;
|
424
|
+
this.chunkSize = 2097152;
|
425
|
+
this.chunkCount = Math.ceil(this.file.size / this.chunkSize);
|
426
|
+
this.chunkIndex = 0;
|
427
|
+
}
|
428
|
+
create(callback) {
|
429
|
+
this.callback = callback;
|
430
|
+
this.md5Buffer = new SparkMD5.ArrayBuffer;
|
431
|
+
this.fileReader = new FileReader;
|
432
|
+
this.fileReader.addEventListener("load", (event => this.fileReaderDidLoad(event)));
|
433
|
+
this.fileReader.addEventListener("error", (event => this.fileReaderDidError(event)));
|
434
|
+
this.readNextChunk();
|
435
|
+
}
|
436
|
+
fileReaderDidLoad(event) {
|
437
|
+
this.md5Buffer.append(event.target.result);
|
438
|
+
if (!this.readNextChunk()) {
|
439
|
+
const binaryDigest = this.md5Buffer.end(true);
|
440
|
+
const base64digest = btoa(binaryDigest);
|
441
|
+
this.callback(null, base64digest);
|
442
|
+
}
|
443
|
+
}
|
444
|
+
fileReaderDidError(event) {
|
445
|
+
this.callback(`Error reading ${this.file.name}`);
|
446
|
+
}
|
447
|
+
readNextChunk() {
|
448
|
+
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);
|
452
|
+
this.fileReader.readAsArrayBuffer(bytes);
|
453
|
+
this.chunkIndex++;
|
454
|
+
return true;
|
455
|
+
} else {
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
var $;
|
462
|
+
|
463
|
+
window.WCC || (window.WCC = {});
|
464
|
+
|
465
|
+
$ = window.jQuery;
|
466
|
+
|
467
|
+
Dropzone.autoDiscover = false;
|
468
|
+
|
469
|
+
window.WCC.Dropzone = class Dropzone extends window.Dropzone {
|
470
|
+
uploadFile(file) {
|
471
|
+
var handleError, headerName, headerValue, headers, progressObj, ref, ref1, response, updateProgress, xhr;
|
472
|
+
xhr = new XMLHttpRequest;
|
473
|
+
file.xhr = xhr;
|
474
|
+
xhr.open(file.uploadMethod, file.uploadURL, true);
|
475
|
+
ref = file.uploadHeaders;
|
476
|
+
for (headerName in ref) {
|
477
|
+
headerValue = ref[headerName];
|
478
|
+
xhr.setRequestHeader(headerName, headerValue);
|
479
|
+
}
|
480
|
+
response = null;
|
481
|
+
handleError = () => this._errorProcessing([ file ], response || this.options.dictResponseError.replace("{{statusCode}}", xhr.status), xhr);
|
482
|
+
updateProgress = e => {
|
483
|
+
var allFilesFinished, progress;
|
484
|
+
if (e != null) {
|
485
|
+
progress = 100 * e.loaded / e.total;
|
486
|
+
file.upload = {
|
487
|
+
progress: progress,
|
488
|
+
total: e.total,
|
489
|
+
bytesSent: e.loaded
|
490
|
+
};
|
491
|
+
} else {
|
492
|
+
allFilesFinished = true;
|
493
|
+
progress = 100;
|
494
|
+
if (!(file.upload.progress === 100 && file.upload.bytesSent === file.upload.total)) {
|
495
|
+
allFilesFinished = false;
|
496
|
+
}
|
497
|
+
file.upload.progress = progress;
|
498
|
+
file.upload.bytesSent = file.upload.total;
|
499
|
+
if (allFilesFinished) {
|
500
|
+
return;
|
501
|
+
}
|
502
|
+
}
|
503
|
+
return this.emit("uploadprogress", file, progress, file.upload.bytesSent);
|
504
|
+
};
|
505
|
+
xhr.onload = e => {
|
506
|
+
var ref1;
|
507
|
+
if (file.status === WCC.Dropzone.CANCELED) {
|
508
|
+
return;
|
509
|
+
}
|
510
|
+
if (xhr.readyState !== 4) {
|
511
|
+
return;
|
512
|
+
}
|
513
|
+
response = xhr.responseText;
|
514
|
+
if (xhr.getResponseHeader("content-type") && ~xhr.getResponseHeader("content-type").indexOf("application/json")) {
|
515
|
+
try {
|
516
|
+
response = JSON.parse(response);
|
517
|
+
} catch (error1) {
|
518
|
+
e = error1;
|
519
|
+
response = "Invalid JSON response from server.";
|
520
|
+
}
|
521
|
+
}
|
522
|
+
updateProgress();
|
523
|
+
if (!(200 <= (ref1 = xhr.status) && ref1 < 300)) {
|
524
|
+
return handleError();
|
525
|
+
} else {
|
526
|
+
return this._finished([ file ], response, e);
|
527
|
+
}
|
528
|
+
};
|
529
|
+
xhr.onerror = () => {
|
530
|
+
if (file.status === WCC.Dropzone.CANCELED) {
|
531
|
+
return;
|
532
|
+
}
|
533
|
+
return handleError();
|
534
|
+
};
|
535
|
+
progressObj = (ref1 = xhr.upload) != null ? ref1 : xhr;
|
536
|
+
progressObj.onprogress = updateProgress;
|
537
|
+
headers = {
|
538
|
+
Accept: "application/json",
|
539
|
+
"Cache-Control": "no-cache",
|
540
|
+
"X-Requested-With": "XMLHttpRequest"
|
541
|
+
};
|
542
|
+
if (this.options.headers) {
|
543
|
+
extend(headers, this.options.headers);
|
544
|
+
}
|
545
|
+
for (headerName in headers) {
|
546
|
+
headerValue = headers[headerName];
|
547
|
+
xhr.setRequestHeader(headerName, headerValue);
|
548
|
+
}
|
549
|
+
this.emit("sending", file, xhr);
|
550
|
+
return xhr.send(file);
|
551
|
+
}
|
552
|
+
uploadFiles(files) {
|
553
|
+
var file, l, len, results;
|
554
|
+
results = [];
|
555
|
+
for (l = 0, len = files.length; l < len; l++) {
|
556
|
+
file = files[l];
|
557
|
+
results.push(this.uploadFile(file));
|
558
|
+
}
|
559
|
+
return results;
|
560
|
+
}
|
561
|
+
};
|
562
|
+
|
563
|
+
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?";
|
564
|
+
|
565
|
+
WCC.Dropzone.prototype.defaultOptions.url = "UNUSED";
|
566
|
+
|
567
|
+
WCC.Dropzone.prototype.defaultOptions.dictDefaultMessage = "Drop files or click to upload.";
|
568
|
+
|
569
|
+
WCC.Dropzone.prototype.defaultOptions.accept = function(file, done) {
|
570
|
+
var dz, postData, tessaParams;
|
571
|
+
dz = $(file._removeLink).closest(".tessa-upload").first();
|
572
|
+
tessaParams = dz.data("tessa-params") || {};
|
573
|
+
postData = {
|
574
|
+
name: file.name,
|
575
|
+
size: file.size,
|
576
|
+
mime_type: file.type
|
577
|
+
};
|
578
|
+
postData = $.extend(postData, tessaParams);
|
579
|
+
return FileChecksum.create(file, (function(error, checksum) {
|
580
|
+
if (error) {
|
581
|
+
return done(error);
|
582
|
+
}
|
583
|
+
postData["checksum"] = checksum;
|
584
|
+
return $.ajax("/tessa/uploads", {
|
585
|
+
type: "POST",
|
586
|
+
data: postData,
|
587
|
+
success: function(response) {
|
588
|
+
file.uploadURL = response.upload_url;
|
589
|
+
file.uploadMethod = response.upload_method;
|
590
|
+
file.uploadHeaders = response.upload_headers;
|
591
|
+
file.assetID = response.asset_id;
|
592
|
+
return done();
|
593
|
+
},
|
594
|
+
error: function(response) {
|
595
|
+
return done("Failed to initiate the upload process!");
|
596
|
+
}
|
597
|
+
});
|
598
|
+
}));
|
599
|
+
};
|
600
|
+
|
601
|
+
window.WCC.tessaInit = function(sel) {
|
602
|
+
sel = sel || "form:has(.tessa-upload)";
|
603
|
+
$(sel).each((function(i, form) {
|
604
|
+
var $form;
|
605
|
+
$form = $(form);
|
606
|
+
return $form.bind("submit", (function(event) {
|
607
|
+
var safeToSubmit;
|
608
|
+
safeToSubmit = true;
|
609
|
+
$form.find(".tessa-upload").each((function(j, dropzoneElement) {
|
610
|
+
return $(dropzoneElement.dropzone.files).each((function(k, file) {
|
611
|
+
if (file.status != null && file.status !== WCC.Dropzone.SUCCESS) {
|
612
|
+
return safeToSubmit = false;
|
613
|
+
}
|
614
|
+
}));
|
615
|
+
}));
|
616
|
+
if (!safeToSubmit && !confirm(WCC.Dropzone.uploadPendingWarning)) {
|
617
|
+
return false;
|
618
|
+
}
|
619
|
+
}));
|
620
|
+
}));
|
621
|
+
return $(".tessa-upload", sel).each((function(i, item) {
|
622
|
+
var $item, args, dropzone, inputPrefix, updateAction;
|
623
|
+
$item = $(item);
|
624
|
+
args = {
|
625
|
+
maxFiles: 1,
|
626
|
+
addRemoveLinks: true
|
627
|
+
};
|
628
|
+
$.extend(args, $item.data("dropzone-options"));
|
629
|
+
if ($item.hasClass("multiple")) {
|
630
|
+
args.maxFiles = null;
|
631
|
+
}
|
632
|
+
inputPrefix = $item.data("asset-field-prefix");
|
633
|
+
dropzone = new WCC.Dropzone(item, args);
|
634
|
+
$item.find('input[type="hidden"]').each((function(j, input) {
|
635
|
+
var $input, mockFile;
|
636
|
+
$input = $(input);
|
637
|
+
mockFile = $input.data("meta");
|
638
|
+
mockFile.accepted = true;
|
639
|
+
dropzone.options.addedfile.call(dropzone, mockFile);
|
640
|
+
dropzone.options.thumbnail.call(dropzone, mockFile, mockFile.url);
|
641
|
+
dropzone.emit("complete", mockFile);
|
642
|
+
return dropzone.files.push(mockFile);
|
643
|
+
}));
|
644
|
+
updateAction = function(file) {
|
645
|
+
var actionInput, inputID;
|
646
|
+
if (file.assetID == null) {
|
647
|
+
return;
|
648
|
+
}
|
649
|
+
inputID = `#tessa_asset_action_${file.assetID}`;
|
650
|
+
actionInput = $(inputID);
|
651
|
+
if (!actionInput.length) {
|
652
|
+
actionInput = $('<input type="hidden">').attr({
|
653
|
+
id: inputID,
|
654
|
+
name: `${inputPrefix}[${file.assetID}][action]`
|
655
|
+
}).appendTo(item);
|
656
|
+
}
|
657
|
+
return actionInput.val(file.action);
|
658
|
+
};
|
659
|
+
dropzone.on("success", (function(file) {
|
660
|
+
file.action = "add";
|
661
|
+
return updateAction(file);
|
662
|
+
}));
|
663
|
+
return dropzone.on("removedfile", (function(file) {
|
664
|
+
file.action = "remove";
|
665
|
+
return updateAction(file);
|
666
|
+
}));
|
667
|
+
}));
|
668
|
+
};
|
669
|
+
|
670
|
+
$((function() {
|
671
|
+
return window.WCC.tessaInit();
|
672
|
+
}));
|