@karpeleslab/klbfw 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/rest.js +10 -1
- package/upload.js +60 -56
package/package.json
CHANGED
package/rest.js
CHANGED
|
@@ -9,7 +9,16 @@ module.exports.rest = (name, verb, params, context) => {
|
|
|
9
9
|
context = context || {};
|
|
10
10
|
var ctx_final = fwWrapper.getContext();
|
|
11
11
|
for (var i in context) ctx_final[i] = context[i];
|
|
12
|
-
|
|
12
|
+
var p1 = new Promise(function(resolve, reject) {
|
|
13
|
+
__platformAsyncRest(name, verb, params, ctx_final).then(function(result) {
|
|
14
|
+
if (result.result != "success") {
|
|
15
|
+
reject(result);
|
|
16
|
+
} else {
|
|
17
|
+
resolve(result);
|
|
18
|
+
}
|
|
19
|
+
}, reject);
|
|
20
|
+
});
|
|
21
|
+
return p1;
|
|
13
22
|
}
|
|
14
23
|
if (typeof __platformRest !== "undefined") {
|
|
15
24
|
// direct SSR-mode call to rest api
|
package/upload.js
CHANGED
|
@@ -186,15 +186,17 @@ module.exports.upload = (function () {
|
|
|
186
186
|
delete upload_running[up.up_id];
|
|
187
187
|
upload.run();
|
|
188
188
|
sendprogress();
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
189
|
+
if (typeof document !== "undefined") {
|
|
190
|
+
setTimeout(function () {
|
|
191
|
+
var evt = new CustomEvent("upload:failed", {
|
|
192
|
+
detail: {
|
|
193
|
+
item: up,
|
|
194
|
+
res: data
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
document.dispatchEvent(evt);
|
|
198
|
+
}, 10);
|
|
199
|
+
}
|
|
198
200
|
}
|
|
199
201
|
|
|
200
202
|
function do_upload_part(up, partno) {
|
|
@@ -341,49 +343,51 @@ module.exports.upload = (function () {
|
|
|
341
343
|
upload.run();
|
|
342
344
|
};
|
|
343
345
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
if (typeof document !== "undefined") {
|
|
347
|
+
upload.init = function (path, params, notify) {
|
|
348
|
+
// perform upload to a given API, for example Drive/Item/<id>:upload
|
|
349
|
+
// will allow multiple files to be uploaded
|
|
350
|
+
params = params || {};
|
|
348
351
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
352
|
+
if (last_input != null) {
|
|
353
|
+
last_input.parentNode.removeChild(last_input);
|
|
354
|
+
last_input = null;
|
|
355
|
+
}
|
|
353
356
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
357
|
+
var input = document.createElement("input");
|
|
358
|
+
input.type = "file";
|
|
359
|
+
input.style.display = "none";
|
|
360
|
+
if (!params["single"]) {
|
|
361
|
+
input.multiple = "multiple";
|
|
362
|
+
}
|
|
360
363
|
|
|
361
|
-
|
|
362
|
-
|
|
364
|
+
document.getElementsByTagName('body')[0].appendChild(input);
|
|
365
|
+
last_input = input;
|
|
363
366
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
var promise = new Promise(function (resolve, reject) {
|
|
368
|
+
input.onchange = function () {
|
|
369
|
+
if (this.files.length == 0) {
|
|
370
|
+
resolve();
|
|
371
|
+
}
|
|
369
372
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
373
|
+
var count = this.files.length;
|
|
374
|
+
if (notify !== undefined) notify({status: 'init', count: count});
|
|
375
|
+
for (var i = 0; i < this.files.length; i++) {
|
|
376
|
+
upload.append(path, this.files[i], params, fwWrapper.getContext()).then(function (obj) {
|
|
377
|
+
count -= 1;
|
|
378
|
+
// Todo notify process
|
|
379
|
+
if (notify !== undefined) notify(obj);
|
|
380
|
+
if (count == 0) resolve();
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
upload.run();
|
|
384
|
+
};
|
|
385
|
+
});
|
|
383
386
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
+
input.click();
|
|
388
|
+
return promise;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
387
391
|
|
|
388
392
|
|
|
389
393
|
upload.append = function (path, file, params, context) {
|
|
@@ -525,16 +529,16 @@ module.exports.upload = (function () {
|
|
|
525
529
|
upload_queue.push(up);
|
|
526
530
|
|
|
527
531
|
upload.run();
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
532
|
+
if (typeof document !== "undefined") {
|
|
533
|
+
setTimeout(function () {
|
|
534
|
+
var evt = new CustomEvent("upload:retry", {
|
|
535
|
+
detail: {
|
|
536
|
+
item: up,
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
document.dispatchEvent(evt);
|
|
540
|
+
}, 10);
|
|
541
|
+
}
|
|
538
542
|
}
|
|
539
543
|
sendprogress();
|
|
540
544
|
};
|