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