roboto-js 1.4.50 → 1.5.1

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,21 +1,25 @@
1
1
  "use strict";
2
2
 
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); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports["default"] = void 0;
8
+ var _tusJsClient = require("tus-js-client");
7
9
  var _lodash = _interopRequireDefault(require("lodash"));
8
10
  var _eventemitter = _interopRequireDefault(require("eventemitter3"));
9
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
- 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); }
11
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; }
12
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); } }
13
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); }); }; }
14
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; }
15
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; }
16
18
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
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); } }
18
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); }
19
23
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
20
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); }
21
25
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
@@ -23,24 +27,19 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
23
27
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
24
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); }
25
29
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
26
- 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; }
27
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
28
- 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); }
29
30
  var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
30
31
  _inherits(RbtFile, _EventEmitter);
31
- // 1MB, for example
32
-
33
- function RbtFile(record, axiosInstance, localDb) {
32
+ function RbtFile(record, axiosInstance) {
34
33
  var _this;
35
34
  _classCallCheck(this, RbtFile);
36
35
  _this = _callSuper(this, RbtFile); // Call the constructor of EventEmitter
36
+
37
+ _this.isRbtFile = true;
37
38
  _this.id = record.id;
38
39
  _this._axios = axiosInstance;
39
40
  _this._internalData = record;
40
41
  _this._data = record.data ? record.data : record.dataJson ? JSON.parse(record.dataJson) : {};
41
- _this._localDb = localDb;
42
42
  _this.progress = 0;
43
- _this.fileHeader = {};
44
43
  return _this;
45
44
  }
46
45
  _createClass(RbtFile, [{
@@ -58,6 +57,13 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
58
57
  value: function getData() {
59
58
  return _objectSpread({}, this._data);
60
59
  }
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
66
+ }
61
67
  }, {
62
68
  key: "toRecord",
63
69
  value: function toRecord() {
@@ -126,7 +132,7 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
126
132
  _context2.prev = 2;
127
133
  record = this.toRecord();
128
134
  _context2.next = 6;
129
- return this._axios.post('/object_service/deleteObject', [record]);
135
+ return this._axios["delete"]("/object_service/deleteObject/".concat(this.id));
130
136
  case 6:
131
137
  response = _context2.sent;
132
138
  if (!(response.data.ok === false)) {
@@ -154,426 +160,72 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
154
160
  return _delete;
155
161
  }()
156
162
  }, {
157
- key: "getFileBlobUrl",
158
- value: function () {
159
- var _getFileBlobUrl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
160
- var db, tx, cursor, fileData, blob;
161
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
162
- while (1) switch (_context3.prev = _context3.next) {
163
- case 0:
164
- db = this._localDb;
165
- tx = db.transaction('files', 'readonly');
166
- _context3.next = 4;
167
- return tx.store.openCursor();
168
- case 4:
169
- cursor = _context3.sent;
170
- if (cursor) {
171
- _context3.next = 7;
172
- break;
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
173
196
  }
174
- return _context3.abrupt("return", null);
175
- case 7:
176
- fileData = cursor.value.chunk; // Assuming the first chunk has enough data
177
- blob = new Blob([fileData], {
178
- type: 'application/octet-stream'
179
- });
180
- return _context3.abrupt("return", URL.createObjectURL(blob));
181
- case 10:
182
- case "end":
183
- return _context3.stop();
197
+ });
198
+
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
+ });
184
207
  }
185
- }, _callee3, this);
186
- }));
187
- function getFileBlobUrl() {
188
- return _getFileBlobUrl.apply(this, arguments);
189
- }
190
- return getFileBlobUrl;
191
- }()
208
+ });
209
+
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
+ }
192
223
  }, {
193
224
  key: "setProgress",
194
225
  value: function setProgress(newProgress) {
195
226
  this.progress = newProgress;
196
- //console.log(`Progress: ${this.progress * 100}%`);
197
227
  this.emit('progress', this.progress); // Emit a progress event
198
228
  }
199
- }, {
200
- key: "readAndStoreFile",
201
- value: function () {
202
- var _readAndStoreFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(file) {
203
- var _this2 = this;
204
- var offset, _loop;
205
- return _regeneratorRuntime().wrap(function _callee5$(_context6) {
206
- while (1) switch (_context6.prev = _context6.next) {
207
- case 0:
208
- offset = 0;
209
- this.fileHeader = {
210
- id: this.id,
211
- name: file.name,
212
- size: file.size,
213
- ext: this._extractFileExtension(file.name),
214
- mimeType: file.type,
215
- numFrames: Math.ceil(file.size / RbtFile.FRAME_SIZE)
216
- };
217
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
218
- var chunk;
219
- return _regeneratorRuntime().wrap(function _loop$(_context5) {
220
- while (1) switch (_context5.prev = _context5.next) {
221
- case 0:
222
- chunk = file.slice(offset, offset + RbtFile.FRAME_SIZE);
223
- _context5.next = 3;
224
- return new Promise(function (resolve, reject) {
225
- var reader = new FileReader();
226
- reader.onload = /*#__PURE__*/function () {
227
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(e) {
228
- var arrayBuffer, frameIndex;
229
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
230
- while (1) switch (_context4.prev = _context4.next) {
231
- case 0:
232
- arrayBuffer = e.target.result;
233
- frameIndex = offset / RbtFile.FRAME_SIZE;
234
- _context4.next = 4;
235
- return _this2._storeChunkInIDB(arrayBuffer, frameIndex, _this2.fileHeader);
236
- case 4:
237
- _this2.setProgress((frameIndex + 1) / _this2.fileHeader.numFrames);
238
- resolve();
239
- case 6:
240
- case "end":
241
- return _context4.stop();
242
- }
243
- }, _callee4);
244
- }));
245
- return function (_x2) {
246
- return _ref.apply(this, arguments);
247
- };
248
- }();
249
- reader.onerror = function () {
250
- return reject(reader.error);
251
- };
252
- reader.readAsArrayBuffer(chunk);
253
- });
254
- case 3:
255
- offset += RbtFile.FRAME_SIZE;
256
- case 4:
257
- case "end":
258
- return _context5.stop();
259
- }
260
- }, _loop);
261
- });
262
- case 3:
263
- if (!(offset < file.size)) {
264
- _context6.next = 7;
265
- break;
266
- }
267
- return _context6.delegateYield(_loop(), "t0", 5);
268
- case 5:
269
- _context6.next = 3;
270
- break;
271
- case 7:
272
- case "end":
273
- return _context6.stop();
274
- }
275
- }, _callee5, this);
276
- }));
277
- function readAndStoreFile(_x) {
278
- return _readAndStoreFile.apply(this, arguments);
279
- }
280
- return readAndStoreFile;
281
- }()
282
- }, {
283
- key: "_extractFileExtension",
284
- value: function _extractFileExtension(fileName) {
285
- // Find the last dot in the filename
286
- var lastDotIndex = fileName.lastIndexOf('.');
287
-
288
- // No dot found, or the dot is the first character (hidden files)
289
- if (lastDotIndex === -1 || lastDotIndex === 0) return '';
290
-
291
- // Extract the extension
292
- return fileName.substring(lastDotIndex + 1);
293
- }
294
- }, {
295
- key: "_storeChunkInIDB",
296
- value: function () {
297
- var _storeChunkInIDB2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(chunk, frameIndex, fileHeader) {
298
- var db, tx, frameKey;
299
- return _regeneratorRuntime().wrap(function _callee6$(_context7) {
300
- while (1) switch (_context7.prev = _context7.next) {
301
- case 0:
302
- db = this._localDb;
303
- if (db) {
304
- _context7.next = 4;
305
- break;
306
- }
307
- console.error('Database not initialized');
308
- return _context7.abrupt("return");
309
- case 4:
310
- tx = db.transaction('files', 'readwrite');
311
- frameKey = "".concat(this.id, "_").concat(frameIndex); // Unique key combining id and frameIndex
312
- _context7.next = 8;
313
- return tx.store.put({
314
- key: frameKey,
315
- chunk: chunk,
316
- fileHeader: fileHeader
317
- }, frameKey);
318
- case 8:
319
- _context7.next = 10;
320
- return tx.done;
321
- case 10:
322
- case "end":
323
- return _context7.stop();
324
- }
325
- }, _callee6, this);
326
- }));
327
- function _storeChunkInIDB(_x3, _x4, _x5) {
328
- return _storeChunkInIDB2.apply(this, arguments);
329
- }
330
- return _storeChunkInIDB;
331
- }()
332
- }, {
333
- key: "_readFrameFromIDB",
334
- value: function () {
335
- var _readFrameFromIDB2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(frameIndex) {
336
- var db, frameKey, tx, frame;
337
- return _regeneratorRuntime().wrap(function _callee7$(_context8) {
338
- while (1) switch (_context8.prev = _context8.next) {
339
- case 0:
340
- db = this._localDb;
341
- if (db) {
342
- _context8.next = 4;
343
- break;
344
- }
345
- console.error('Database not initialized');
346
- return _context8.abrupt("return", null);
347
- case 4:
348
- frameKey = "".concat(this.id, "_").concat(frameIndex); // Same key as used in _storeChunkInIDB
349
- tx = db.transaction('files', 'readonly');
350
- _context8.next = 8;
351
- return tx.store.get(frameKey);
352
- case 8:
353
- frame = _context8.sent;
354
- return _context8.abrupt("return", frame ? frame.chunk : null);
355
- case 10:
356
- case "end":
357
- return _context8.stop();
358
- }
359
- }, _callee7, this);
360
- }));
361
- function _readFrameFromIDB(_x6) {
362
- return _readFrameFromIDB2.apply(this, arguments);
363
- }
364
- return _readFrameFromIDB;
365
- }()
366
- }, {
367
- key: "uploadFile",
368
- value: function () {
369
- var _uploadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
370
- var frameRes, frameIndex, frameData, statusRes;
371
- return _regeneratorRuntime().wrap(function _callee8$(_context9) {
372
- while (1) switch (_context9.prev = _context9.next) {
373
- case 0:
374
- if (!(!this.fileHeader || !this.fileHeader.numFrames)) {
375
- _context9.next = 2;
376
- break;
377
- }
378
- throw new Error("File not ready for upload.");
379
- case 2:
380
- this.fileRecord = this.toRecord();
381
- frameIndex = 0;
382
- case 4:
383
- if (!(frameIndex < this.fileHeader.numFrames)) {
384
- _context9.next = 24;
385
- break;
386
- }
387
- _context9.prev = 5;
388
- _context9.next = 8;
389
- return this._readFrameFromIDB(frameIndex);
390
- case 8:
391
- frameData = _context9.sent;
392
- if (frameData) {
393
- _context9.next = 11;
394
- break;
395
- }
396
- throw new Error("Failed to read frame ".concat(frameIndex));
397
- case 11:
398
- _context9.next = 13;
399
- return this._uploadFrameToServer(frameData, frameIndex, this.fileHeader, this.fileRecord);
400
- case 13:
401
- frameRes = _context9.sent;
402
- // Update progress after each frame is uploaded
403
- this.setProgress((frameIndex + 1) / this.fileHeader.numFrames);
404
- _context9.next = 21;
405
- break;
406
- case 17:
407
- _context9.prev = 17;
408
- _context9.t0 = _context9["catch"](5);
409
- console.error("Error uploading frame ".concat(frameIndex, ":"), _context9.t0);
410
- throw _context9.t0;
411
- case 21:
412
- frameIndex++;
413
- _context9.next = 4;
414
- break;
415
- case 24:
416
- _context9.prev = 24;
417
- _context9.next = 27;
418
- return this._checkUploadStatusUntilDone(this.fileRecord);
419
- case 27:
420
- statusRes = _context9.sent;
421
- this.set('remoteSrc', statusRes.remoteSrc);
422
- this.set('progress', 1);
423
- _context9.next = 32;
424
- return this.save();
425
- case 32:
426
- _context9.next = 37;
427
- break;
428
- case 34:
429
- _context9.prev = 34;
430
- _context9.t1 = _context9["catch"](24);
431
- console.error('Error during upload status check:', _context9.t1);
432
- // Handle error, possibly update UI or retry logic
433
- case 37:
434
- case "end":
435
- return _context9.stop();
436
- }
437
- }, _callee8, this, [[5, 17], [24, 34]]);
438
- }));
439
- function uploadFile() {
440
- return _uploadFile.apply(this, arguments);
441
- }
442
- return uploadFile;
443
- }()
444
- }, {
445
- key: "_uploadFrameToServer",
446
- value: function () {
447
- var _uploadFrameToServer2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(frameData, frameIndex, fileHeader, fileRecord) {
448
- var base64Data, payload, response;
449
- return _regeneratorRuntime().wrap(function _callee9$(_context10) {
450
- while (1) switch (_context10.prev = _context10.next) {
451
- case 0:
452
- base64Data = this.convertToBase64(frameData);
453
- payload = ["@filekit.ffs_server_receiveAndStore_toS3_flow", {
454
- "fileObject": fileRecord,
455
- // using fileRecord from newFile.toRecord()
456
- "fileHeader": fileHeader,
457
- "frameIndex": frameIndex,
458
- "frameData": "rpcBase64:".concat(base64Data),
459
- "timeout": 86400000
460
- }]; //console.log(payload);
461
- _context10.next = 4;
462
- return this._axios.post('/file_service/ffs_runFlow', payload);
463
- case 4:
464
- response = _context10.sent;
465
- if (!(!response || response.status != 200)) {
466
- _context10.next = 7;
467
- break;
468
- }
469
- throw new Error('Error uploading frame to server');
470
- case 7:
471
- return _context10.abrupt("return", response);
472
- case 8:
473
- case "end":
474
- return _context10.stop();
475
- }
476
- }, _callee9, this);
477
- }));
478
- function _uploadFrameToServer(_x7, _x8, _x9, _x10) {
479
- return _uploadFrameToServer2.apply(this, arguments);
480
- }
481
- return _uploadFrameToServer;
482
- }()
483
- }, {
484
- key: "_checkUploadStatusUntilDone",
485
- value: function () {
486
- var _checkUploadStatusUntilDone2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(fileRecord) {
487
- var _this3 = this;
488
- return _regeneratorRuntime().wrap(function _callee11$(_context12) {
489
- while (1) switch (_context12.prev = _context12.next) {
490
- case 0:
491
- return _context12.abrupt("return", new Promise(function (resolve, reject) {
492
- var intervalId = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
493
- var statusRes;
494
- return _regeneratorRuntime().wrap(function _callee10$(_context11) {
495
- while (1) switch (_context11.prev = _context11.next) {
496
- case 0:
497
- _context11.prev = 0;
498
- _context11.next = 3;
499
- return _this3._uploadGetStatusUpdate(fileRecord);
500
- case 3:
501
- statusRes = _context11.sent;
502
- if (statusRes.data && statusRes.data.fileHeader && statusRes.data.fileHeader.status === 'DONE') {
503
- clearInterval(intervalId); // Stop the interval
504
- resolve(statusRes.data.fileHeader); // Resolve the promise with the final status
505
- } else {
506
- // Optionally update progress or handle other status cases here
507
- //this.emit('progress', statusRes.progress); // Emit progress updates if available
508
- }
509
- _context11.next = 11;
510
- break;
511
- case 7:
512
- _context11.prev = 7;
513
- _context11.t0 = _context11["catch"](0);
514
- clearInterval(intervalId); // Stop the interval on error
515
- reject(_context11.t0); // Reject the promise if there's an error
516
- case 11:
517
- case "end":
518
- return _context11.stop();
519
- }
520
- }, _callee10, null, [[0, 7]]);
521
- })), 2000); // Check every 2 seconds
522
- }));
523
- case 1:
524
- case "end":
525
- return _context12.stop();
526
- }
527
- }, _callee11);
528
- }));
529
- function _checkUploadStatusUntilDone(_x11) {
530
- return _checkUploadStatusUntilDone2.apply(this, arguments);
531
- }
532
- return _checkUploadStatusUntilDone;
533
- }()
534
- }, {
535
- key: "_uploadGetStatusUpdate",
536
- value: function () {
537
- var _uploadGetStatusUpdate2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(fileRecord) {
538
- var payload, response;
539
- return _regeneratorRuntime().wrap(function _callee12$(_context13) {
540
- while (1) switch (_context13.prev = _context13.next) {
541
- case 0:
542
- payload = ["@filekit.ffs_server_receiveAndStore_toS3_flow", {
543
- "fileObject": fileRecord,
544
- // using fileRecord from newFile.toRecord()
545
- "getStatusUpdate": true
546
- }]; //console.log(payload);
547
- _context13.next = 3;
548
- return this._axios.post('/file_service/ffs_runFlow', payload);
549
- case 3:
550
- response = _context13.sent;
551
- if (!(!response || response.status != 200)) {
552
- _context13.next = 6;
553
- break;
554
- }
555
- throw new Error('Error getting upload status');
556
- case 6:
557
- return _context13.abrupt("return", response);
558
- case 7:
559
- case "end":
560
- return _context13.stop();
561
- }
562
- }, _callee12, this);
563
- }));
564
- function _uploadGetStatusUpdate(_x12) {
565
- return _uploadGetStatusUpdate2.apply(this, arguments);
566
- }
567
- return _uploadGetStatusUpdate;
568
- }()
569
- }, {
570
- key: "convertToBase64",
571
- value: function convertToBase64(buffer) {
572
- return btoa(new Uint8Array(buffer).reduce(function (data, _byte) {
573
- return data + String.fromCharCode(_byte);
574
- }, ''));
575
- }
576
229
  }]);
577
230
  return RbtFile;
578
- }(_eventemitter["default"]);
579
- _defineProperty(RbtFile, "FRAME_SIZE", 1024 * 1024);
231
+ }(_eventemitter["default"]);
package/dist/esm/index.js CHANGED
@@ -111,6 +111,9 @@ export default class Roboto {
111
111
  async loadFile(id) {
112
112
  return this.api.loadFile(id);
113
113
  }
114
+ async loadFiles(ids) {
115
+ return this.api.loadFiles(ids);
116
+ }
114
117
 
115
118
  //
116
119
  //
@@ -322,6 +322,24 @@ export default class RbtApi {
322
322
  return this._handleError(e);
323
323
  }
324
324
  }
325
+ async loadFiles(ids) {
326
+ try {
327
+ // Use the bulk load method with the provided IDs
328
+ const responses = await this.load('<@filekit.file>', ids);
329
+ if (!responses || !Array.isArray(responses)) {
330
+ return []; // Return an empty array if no responses or invalid data
331
+ }
332
+
333
+ // Map over the responses to create RbtFile instances
334
+ return responses.map(response => {
335
+ const record = response.toRecord();
336
+ return new RbtFile(record, this.axios, this.localDb);
337
+ });
338
+ } catch (e) {
339
+ this._handleError(e); // Handle errors (log or process as needed)
340
+ return []; // Return an empty array on failure
341
+ }
342
+ }
325
343
 
326
344
  /**
327
345
  * Creates a new object of the given type.