roboto-js 1.8.4 → 1.8.6
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/.last-build +1 -1
- package/BUILD_NOTES.md +30 -0
- package/babel.config.json +13 -0
- package/dist/cjs/cookie_storage_adaptor.cjs +38 -84
- package/dist/cjs/index.cjs +21 -14
- package/dist/cjs/rbt_api.cjs +34 -97
- package/dist/cjs/rbt_object.cjs +5 -14
- package/dist/cjs/rbt_user.cjs +1 -3
- package/dist/cookie_storage_adaptor.js +415 -0
- package/dist/esm/cookie_storage_adaptor.js +354 -197
- package/dist/esm/index.js +604 -182
- package/dist/esm/rbt_api.js +1976 -1172
- package/dist/esm/rbt_file.js +222 -126
- package/dist/esm/rbt_metrics_api.js +166 -71
- package/dist/esm/rbt_object.js +1014 -708
- package/dist/esm/rbt_user.js +209 -138
- package/dist/index.js +594 -0
- package/dist/rbt_api.js +2115 -0
- package/dist/rbt_file.js +223 -0
- package/dist/rbt_metrics_api.js +200 -0
- package/dist/rbt_object.js +1110 -0
- package/dist/rbt_user.js +235 -0
- package/package.json +4 -3
- package/src/index.js +21 -11
- package/src/rbt_api.js +9 -0
package/dist/esm/rbt_file.js
CHANGED
|
@@ -1,135 +1,231 @@
|
|
|
1
|
-
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import EventEmitter from 'eventemitter3';
|
|
4
|
-
export default class RbtFile extends EventEmitter {
|
|
5
|
-
constructor(record, axiosInstance) {
|
|
6
|
-
super(); // Call the constructor of EventEmitter
|
|
1
|
+
"use strict";
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _tusJsClient = require("tus-js-client");
|
|
9
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
|
+
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
13
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
14
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
20
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
24
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
25
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
26
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
27
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
28
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
29
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
30
|
+
var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
31
|
+
_inherits(RbtFile, _EventEmitter);
|
|
32
|
+
function RbtFile(record, axiosInstance) {
|
|
33
|
+
var _this;
|
|
34
|
+
_classCallCheck(this, RbtFile);
|
|
35
|
+
_this = _callSuper(this, RbtFile); // Call the constructor of EventEmitter
|
|
36
|
+
|
|
37
|
+
_this.isRbtFile = true;
|
|
38
|
+
_this.id = record.id;
|
|
39
|
+
_this._axios = axiosInstance;
|
|
40
|
+
_this._internalData = record;
|
|
41
|
+
_this._data = record.data ? record.data : record.dataJson ? JSON.parse(record.dataJson) : {};
|
|
42
|
+
_this.progress = 0;
|
|
43
|
+
return _this;
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
_createClass(RbtFile, [{
|
|
46
|
+
key: "get",
|
|
47
|
+
value: function get(path) {
|
|
48
|
+
return _lodash["default"].get(this._data, path);
|
|
42
49
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
throw new Error(response.data.message);
|
|
48
|
-
}
|
|
49
|
-
this._internalData = response.data;
|
|
50
|
-
return this;
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error('RbtFile.save.error:', e.response?.data);
|
|
53
|
-
throw e; // Propagate the error
|
|
50
|
+
}, {
|
|
51
|
+
key: "set",
|
|
52
|
+
value: function set(path, value) {
|
|
53
|
+
_lodash["default"].set(this._data, path, value);
|
|
54
54
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
}, {
|
|
56
|
+
key: "getData",
|
|
57
|
+
value: function getData() {
|
|
58
|
+
return _objectSpread({}, this._data);
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
this._internalData = response.data;
|
|
67
|
-
return this;
|
|
68
|
-
} catch (e) {
|
|
69
|
-
console.error('RbtFile.delete.error:', e.response?.data);
|
|
70
|
-
throw e; // Propagate the error
|
|
60
|
+
}, {
|
|
61
|
+
key: "setData",
|
|
62
|
+
value: function setData(data) {
|
|
63
|
+
// Use lodash's merge to deeply merge the incoming data into _data
|
|
64
|
+
_lodash["default"].merge(this._data, data);
|
|
65
|
+
return _objectSpread({}, this._data); // Return the updated _data as a new object
|
|
71
66
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
retryDelays: [0, 1000, 3000, 5000],
|
|
78
|
-
metadata: {
|
|
79
|
-
rbtfileid: this.id,
|
|
80
|
-
filename: file.name,
|
|
81
|
-
filetype: file.type
|
|
82
|
-
},
|
|
83
|
-
onError: error => {
|
|
84
|
-
console.error("Failed because:", error);
|
|
85
|
-
this.emit('error', error);
|
|
86
|
-
reject(error); // Reject the promise on error
|
|
87
|
-
},
|
|
88
|
-
onProgress: (bytesUploaded, bytesTotal) => {
|
|
89
|
-
const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
|
|
90
|
-
this.emit('progress', percentage / 100); // Emit normalized progress
|
|
91
|
-
},
|
|
92
|
-
onSuccess: () => {
|
|
93
|
-
//console.log("File uploaded to:", upload.url);
|
|
94
|
-
const m1 = upload.url.match(/\/([^\/]+)$/);
|
|
95
|
-
const remoteId = m1 ? m1[1] : null;
|
|
96
|
-
this.setData({
|
|
97
|
-
'remoteId': remoteId,
|
|
98
|
-
'remoteSrc': upload.url,
|
|
99
|
-
'sourceFile': {
|
|
100
|
-
name: upload.file.name,
|
|
101
|
-
size: upload.file.size,
|
|
102
|
-
type: upload.file.type,
|
|
103
|
-
lastModified: upload.file.lastModified
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Ensure save is called and finished before resolving the promise
|
|
108
|
-
this.save().then(() => {
|
|
109
|
-
this.emit('success', upload.url);
|
|
110
|
-
resolve(); // Resolve the promise after save is complete
|
|
111
|
-
}).catch(error => {
|
|
112
|
-
console.error("Save failed:", error);
|
|
113
|
-
reject(error); // Reject the promise if save fails
|
|
114
|
-
});
|
|
115
|
-
}
|
|
67
|
+
}, {
|
|
68
|
+
key: "toRecord",
|
|
69
|
+
value: function toRecord() {
|
|
70
|
+
return _objectSpread(_objectSpread({}, this._internalData), {}, {
|
|
71
|
+
dataJson: JSON.stringify(this._data)
|
|
116
72
|
});
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
key: "save",
|
|
76
|
+
value: function () {
|
|
77
|
+
var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
78
|
+
var record, response, _e$response;
|
|
79
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
80
|
+
while (1) switch (_context.prev = _context.next) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (this._internalData.type) {
|
|
83
|
+
_context.next = 2;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
throw new Error('Cannot save object without type');
|
|
87
|
+
case 2:
|
|
88
|
+
_context.prev = 2;
|
|
89
|
+
record = this.toRecord();
|
|
90
|
+
_context.next = 6;
|
|
91
|
+
return this._axios.post('/object_service/saveObject', [record]);
|
|
92
|
+
case 6:
|
|
93
|
+
response = _context.sent;
|
|
94
|
+
if (!(response.data.ok === false)) {
|
|
95
|
+
_context.next = 9;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(response.data.message);
|
|
99
|
+
case 9:
|
|
100
|
+
this._internalData = response.data;
|
|
101
|
+
return _context.abrupt("return", this);
|
|
102
|
+
case 13:
|
|
103
|
+
_context.prev = 13;
|
|
104
|
+
_context.t0 = _context["catch"](2);
|
|
105
|
+
console.error('RbtFile.save.error:', (_e$response = _context.t0.response) === null || _e$response === void 0 ? void 0 : _e$response.data);
|
|
106
|
+
throw _context.t0;
|
|
107
|
+
case 17:
|
|
108
|
+
case "end":
|
|
109
|
+
return _context.stop();
|
|
110
|
+
}
|
|
111
|
+
}, _callee, this, [[2, 13]]);
|
|
112
|
+
}));
|
|
113
|
+
function save() {
|
|
114
|
+
return _save.apply(this, arguments);
|
|
115
|
+
}
|
|
116
|
+
return save;
|
|
117
|
+
}()
|
|
118
|
+
}, {
|
|
119
|
+
key: "delete",
|
|
120
|
+
value: function () {
|
|
121
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
122
|
+
var record, response, _e$response2;
|
|
123
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
124
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
125
|
+
case 0:
|
|
126
|
+
if (this._internalData.type) {
|
|
127
|
+
_context2.next = 2;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
throw new Error('Cannot delete object without type');
|
|
131
|
+
case 2:
|
|
132
|
+
_context2.prev = 2;
|
|
133
|
+
record = this.toRecord();
|
|
134
|
+
_context2.next = 6;
|
|
135
|
+
return this._axios["delete"]("/object_service/deleteObject/".concat(this.id));
|
|
136
|
+
case 6:
|
|
137
|
+
response = _context2.sent;
|
|
138
|
+
if (!(response.data.ok === false)) {
|
|
139
|
+
_context2.next = 9;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
throw new Error(response.data.message);
|
|
143
|
+
case 9:
|
|
144
|
+
this._internalData = response.data;
|
|
145
|
+
return _context2.abrupt("return", this);
|
|
146
|
+
case 13:
|
|
147
|
+
_context2.prev = 13;
|
|
148
|
+
_context2.t0 = _context2["catch"](2);
|
|
149
|
+
console.error('RbtFile.delete.error:', (_e$response2 = _context2.t0.response) === null || _e$response2 === void 0 ? void 0 : _e$response2.data);
|
|
150
|
+
throw _context2.t0;
|
|
151
|
+
case 17:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context2.stop();
|
|
154
|
+
}
|
|
155
|
+
}, _callee2, this, [[2, 13]]);
|
|
156
|
+
}));
|
|
157
|
+
function _delete() {
|
|
158
|
+
return _delete2.apply(this, arguments);
|
|
159
|
+
}
|
|
160
|
+
return _delete;
|
|
161
|
+
}()
|
|
162
|
+
}, {
|
|
163
|
+
key: "uploadFile",
|
|
164
|
+
value: function uploadFile(file) {
|
|
165
|
+
var _this2 = this;
|
|
166
|
+
return new Promise(function (resolve, reject) {
|
|
167
|
+
var upload = new _tusJsClient.Upload(file, {
|
|
168
|
+
endpoint: _this2._axios.defaults.baseURL + "/file_service/files",
|
|
169
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
170
|
+
metadata: {
|
|
171
|
+
rbtfileid: _this2.id,
|
|
172
|
+
filename: file.name,
|
|
173
|
+
filetype: file.type
|
|
174
|
+
},
|
|
175
|
+
onError: function onError(error) {
|
|
176
|
+
console.error("Failed because:", error);
|
|
177
|
+
_this2.emit('error', error);
|
|
178
|
+
reject(error); // Reject the promise on error
|
|
179
|
+
},
|
|
180
|
+
onProgress: function onProgress(bytesUploaded, bytesTotal) {
|
|
181
|
+
var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
|
|
182
|
+
_this2.emit('progress', percentage / 100); // Emit normalized progress
|
|
183
|
+
},
|
|
184
|
+
onSuccess: function onSuccess() {
|
|
185
|
+
//console.log("File uploaded to:", upload.url);
|
|
186
|
+
var m1 = upload.url.match(/\/([^\/]+)$/);
|
|
187
|
+
var remoteId = m1 ? m1[1] : null;
|
|
188
|
+
_this2.setData({
|
|
189
|
+
'remoteId': remoteId,
|
|
190
|
+
'remoteSrc': upload.url,
|
|
191
|
+
'sourceFile': {
|
|
192
|
+
name: upload.file.name,
|
|
193
|
+
size: upload.file.size,
|
|
194
|
+
type: upload.file.type,
|
|
195
|
+
lastModified: upload.file.lastModified
|
|
196
|
+
}
|
|
197
|
+
});
|
|
117
198
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
199
|
+
// Ensure save is called and finished before resolving the promise
|
|
200
|
+
_this2.save().then(function () {
|
|
201
|
+
_this2.emit('success', upload.url);
|
|
202
|
+
resolve(); // Resolve the promise after save is complete
|
|
203
|
+
})["catch"](function (error) {
|
|
204
|
+
console.error("Save failed:", error);
|
|
205
|
+
reject(error); // Reject the promise if save fails
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
});
|
|
124
209
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
210
|
+
// Check if there are any previous uploads to continue.
|
|
211
|
+
// upload.findPreviousUploads().then(function (previousUploads) {
|
|
212
|
+
// // Found previous uploads so we select the first one.
|
|
213
|
+
// if (previousUploads.length) {
|
|
214
|
+
// upload.resumeFromPreviousUpload(previousUploads[0])
|
|
215
|
+
// }
|
|
216
|
+
|
|
217
|
+
// // Start the upload
|
|
218
|
+
// upload.start();
|
|
219
|
+
// })
|
|
220
|
+
upload.start(); // Start the upload
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}, {
|
|
224
|
+
key: "setProgress",
|
|
225
|
+
value: function setProgress(newProgress) {
|
|
226
|
+
this.progress = newProgress;
|
|
227
|
+
this.emit('progress', this.progress); // Emit a progress event
|
|
228
|
+
}
|
|
229
|
+
}]);
|
|
230
|
+
return RbtFile;
|
|
231
|
+
}(_eventemitter["default"]);
|