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.
@@ -1,135 +1,231 @@
1
- import { Upload } from 'tus-js-client';
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
- this.isRbtFile = true;
9
- this.id = record.id;
10
- this._axios = axiosInstance;
11
- this._internalData = record;
12
- this._data = record.data ? record.data : record.dataJson ? JSON.parse(record.dataJson) : {};
13
- this.progress = 0;
14
- }
15
- get(path) {
16
- return _.get(this._data, path);
17
- }
18
- set(path, value) {
19
- _.set(this._data, path, value);
20
- }
21
- getData() {
22
- return {
23
- ...this._data
24
- };
25
- }
26
- setData(data) {
27
- // Use lodash's merge to deeply merge the incoming data into _data
28
- _.merge(this._data, data);
29
- return {
30
- ...this._data
31
- }; // Return the updated _data as a new object
32
- }
33
- toRecord() {
34
- return {
35
- ...this._internalData,
36
- dataJson: JSON.stringify(this._data)
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
- async save() {
40
- if (!this._internalData.type) {
41
- throw new Error('Cannot save object without type');
45
+ _createClass(RbtFile, [{
46
+ key: "get",
47
+ value: function get(path) {
48
+ return _lodash["default"].get(this._data, path);
42
49
  }
43
- try {
44
- const record = this.toRecord();
45
- const response = await this._axios.post('/object_service/saveObject', [record]);
46
- if (response.data.ok === false) {
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
- async delete() {
57
- if (!this._internalData.type) {
58
- throw new Error('Cannot delete object without type');
55
+ }, {
56
+ key: "getData",
57
+ value: function getData() {
58
+ return _objectSpread({}, this._data);
59
59
  }
60
- try {
61
- const record = this.toRecord();
62
- const response = await this._axios.delete(`/object_service/deleteObject/${this.id}`);
63
- if (response.data.ok === false) {
64
- throw new Error(response.data.message);
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
- uploadFile(file) {
74
- return new Promise((resolve, reject) => {
75
- const upload = new Upload(file, {
76
- endpoint: this._axios.defaults.baseURL + "/file_service/files",
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
- // Check if there are any previous uploads to continue.
119
- // upload.findPreviousUploads().then(function (previousUploads) {
120
- // // Found previous uploads so we select the first one.
121
- // if (previousUploads.length) {
122
- // upload.resumeFromPreviousUpload(previousUploads[0])
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
- // // Start the upload
126
- // upload.start();
127
- // })
128
- upload.start(); // Start the upload
129
- });
130
- }
131
- setProgress(newProgress) {
132
- this.progress = newProgress;
133
- this.emit('progress', this.progress); // Emit a progress event
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"]);