roboto-js 1.5.0 → 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.
- package/dist/cjs/rbt_file.cjs +53 -47
- package/dist/esm/rbt_file.js +53 -47
- package/package.json +1 -1
- package/src/rbt_file.js +48 -40
package/dist/cjs/rbt_file.cjs
CHANGED
|
@@ -163,61 +163,67 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
163
163
|
key: "uploadFile",
|
|
164
164
|
value: function uploadFile(file) {
|
|
165
165
|
var _this2 = this;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
+
});
|
|
185
198
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
_this2.save().then(function () {
|
|
199
|
-
_this2.emit('success', upload.url);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
});
|
|
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
|
+
});
|
|
203
209
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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
|
+
// }
|
|
210
216
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
217
|
+
// // Start the upload
|
|
218
|
+
// upload.start();
|
|
219
|
+
// })
|
|
220
|
+
upload.start(); // Start the upload
|
|
221
|
+
});
|
|
215
222
|
}
|
|
216
223
|
}, {
|
|
217
224
|
key: "setProgress",
|
|
218
225
|
value: function setProgress(newProgress) {
|
|
219
226
|
this.progress = newProgress;
|
|
220
|
-
console.log("Progress: ".concat(this.progress * 100, "%"));
|
|
221
227
|
this.emit('progress', this.progress); // Emit a progress event
|
|
222
228
|
}
|
|
223
229
|
}]);
|
package/dist/esm/rbt_file.js
CHANGED
|
@@ -71,59 +71,65 @@ export default class RbtFile extends EventEmitter {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
uploadFile(file) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
});
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
this.save().then(() => {
|
|
107
|
-
this.emit('success', upload.url);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
});
|
|
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
|
+
}
|
|
116
|
+
});
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
+
// }
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
// // Start the upload
|
|
126
|
+
// upload.start();
|
|
127
|
+
// })
|
|
128
|
+
upload.start(); // Start the upload
|
|
129
|
+
});
|
|
123
130
|
}
|
|
124
131
|
setProgress(newProgress) {
|
|
125
132
|
this.progress = newProgress;
|
|
126
|
-
console.log(`Progress: ${this.progress * 100}%`);
|
|
127
133
|
this.emit('progress', this.progress); // Emit a progress event
|
|
128
134
|
}
|
|
129
135
|
}
|
package/package.json
CHANGED
package/src/rbt_file.js
CHANGED
|
@@ -85,45 +85,51 @@ export default class RbtFile extends EventEmitter {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
uploadFile(file) {
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
const upload = new Upload(file, {
|
|
90
|
+
endpoint: this._axios.defaults.baseURL + "/file_service/files",
|
|
91
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
92
|
+
metadata: {
|
|
93
|
+
rbtfileid: this.id,
|
|
94
|
+
filename: file.name,
|
|
95
|
+
filetype: file.type,
|
|
96
|
+
},
|
|
97
|
+
onError: error => {
|
|
98
|
+
console.error("Failed because:", error);
|
|
99
|
+
this.emit('error', error);
|
|
100
|
+
reject(error); // Reject the promise on error
|
|
101
|
+
},
|
|
102
|
+
onProgress: (bytesUploaded, bytesTotal) => {
|
|
103
|
+
const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
|
|
104
|
+
this.emit('progress', percentage / 100); // Emit normalized progress
|
|
105
|
+
},
|
|
106
|
+
onSuccess: () => {
|
|
107
|
+
//console.log("File uploaded to:", upload.url);
|
|
108
|
+
const m1 = upload.url.match(/\/([^\/]+)$/);
|
|
109
|
+
const remoteId = m1 ? m1[1] : null;
|
|
110
|
+
|
|
111
|
+
this.setData({
|
|
112
|
+
'remoteId': remoteId,
|
|
113
|
+
'remoteSrc': upload.url,
|
|
114
|
+
'sourceFile': {
|
|
115
|
+
name: upload.file.name,
|
|
116
|
+
size: upload.file.size,
|
|
117
|
+
type: upload.file.type,
|
|
118
|
+
lastModified: upload.file.lastModified,
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// Ensure save is called and finished before resolving the promise
|
|
123
|
+
this.save().then(() => {
|
|
124
|
+
this.emit('success', upload.url);
|
|
125
|
+
resolve(); // Resolve the promise after save is complete
|
|
126
|
+
}).catch(error => {
|
|
127
|
+
console.error("Save failed:", error);
|
|
128
|
+
reject(error); // Reject the promise if save fails
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
88
132
|
|
|
89
|
-
const upload = new Upload(file, {
|
|
90
|
-
endpoint: this._axios.defaults.baseURL+"/file_service/files",
|
|
91
|
-
retryDelays: [0, 1000, 3000, 5000],
|
|
92
|
-
metadata: {
|
|
93
|
-
rbtfileid: this.id,
|
|
94
|
-
filename: file.name,
|
|
95
|
-
filetype: file.type,
|
|
96
|
-
},
|
|
97
|
-
onError: error => {
|
|
98
|
-
console.error("Failed because:", error);
|
|
99
|
-
this.emit('error', error);
|
|
100
|
-
},
|
|
101
|
-
onProgress: (bytesUploaded, bytesTotal) => {
|
|
102
|
-
console.log("File progress", bytesUploaded, bytesTotal);
|
|
103
|
-
const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
|
|
104
|
-
this.setProgress(percentage / 100); // Update progress normalized between 0 and 1
|
|
105
|
-
},
|
|
106
|
-
onSuccess: () => {
|
|
107
|
-
console.log("File uploaded to:", upload.url);
|
|
108
|
-
|
|
109
|
-
// Remove the `options.endpoint` from the start of the `url`
|
|
110
|
-
const m1 = upload.url.match(/\/([^\/]+)$/);
|
|
111
|
-
const remoteId = m1 ? m1[1] : null;
|
|
112
|
-
|
|
113
|
-
this.setData({
|
|
114
|
-
'remoteId': remoteId,
|
|
115
|
-
'sourceFile': {
|
|
116
|
-
name: upload.file.name,
|
|
117
|
-
size: upload.file.size,
|
|
118
|
-
type: upload.file.type,
|
|
119
|
-
lastModified: upload.file.lastModified,
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
this.save().then(() => {
|
|
123
|
-
this.emit('success', upload.url);
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
133
|
|
|
128
134
|
// Check if there are any previous uploads to continue.
|
|
129
135
|
// upload.findPreviousUploads().then(function (previousUploads) {
|
|
@@ -135,12 +141,14 @@ export default class RbtFile extends EventEmitter {
|
|
|
135
141
|
// // Start the upload
|
|
136
142
|
// upload.start();
|
|
137
143
|
// })
|
|
138
|
-
|
|
144
|
+
upload.start(); // Start the upload
|
|
145
|
+
});
|
|
139
146
|
}
|
|
140
147
|
|
|
148
|
+
|
|
149
|
+
|
|
141
150
|
setProgress(newProgress) {
|
|
142
151
|
this.progress = newProgress;
|
|
143
|
-
console.log(`Progress: ${this.progress * 100}%`);
|
|
144
152
|
this.emit('progress', this.progress); // Emit a progress event
|
|
145
153
|
}
|
|
146
154
|
}
|