parse 5.2.0-alpha.1 → 5.2.0-alpha.3
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/parse.js +10519 -15246
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +10499 -15371
- package/dist/parse.weapp.min.js +2 -2
- package/lib/browser/Analytics.js +7 -11
- package/lib/browser/AnonymousUtils.js +17 -22
- package/lib/browser/Cloud.js +23 -41
- package/lib/browser/CoreManager.js +71 -79
- package/lib/browser/CryptoController.js +14 -9
- package/lib/browser/EventEmitter.js +9 -2
- package/lib/browser/EventuallyQueue.js +156 -357
- package/lib/browser/FacebookUtils.js +23 -28
- package/lib/browser/IndexedDBStorageController.js +18 -14
- package/lib/browser/InstallationController.js +55 -121
- package/lib/browser/LiveQueryClient.js +312 -485
- package/lib/browser/LiveQuerySubscription.js +25 -28
- package/lib/browser/LocalDatastore.js +258 -624
- package/lib/browser/LocalDatastoreController.default.js +42 -226
- package/lib/browser/LocalDatastoreController.js +11 -1
- package/lib/browser/LocalDatastoreController.react-native.js +66 -160
- package/lib/browser/LocalDatastoreUtils.js +4 -7
- package/lib/browser/ObjectStateMutations.js +54 -96
- package/lib/browser/OfflineQuery.js +106 -198
- package/lib/browser/Parse.js +44 -60
- package/lib/browser/ParseACL.js +242 -288
- package/lib/browser/ParseCLP.js +372 -572
- package/lib/browser/ParseConfig.js +115 -138
- package/lib/browser/ParseError.js +85 -182
- package/lib/browser/ParseFile.js +294 -438
- package/lib/browser/ParseGeoPoint.js +121 -146
- package/lib/browser/ParseHooks.js +23 -25
- package/lib/browser/ParseInstallation.js +225 -367
- package/lib/browser/ParseLiveQuery.js +74 -148
- package/lib/browser/ParseObject.js +2014 -2621
- package/lib/browser/ParseOp.js +343 -484
- package/lib/browser/ParsePolygon.js +101 -120
- package/lib/browser/ParseQuery.js +1708 -2052
- package/lib/browser/ParseRelation.js +99 -118
- package/lib/browser/ParseRole.js +88 -140
- package/lib/browser/ParseSchema.js +372 -434
- package/lib/browser/ParseSession.js +62 -110
- package/lib/browser/ParseUser.js +941 -1284
- package/lib/browser/Push.js +15 -38
- package/lib/browser/RESTController.js +85 -124
- package/lib/browser/SingleInstanceStateController.js +57 -86
- package/lib/browser/Socket.weapp.js +50 -33
- package/lib/browser/Storage.js +23 -28
- package/lib/browser/StorageController.browser.js +16 -13
- package/lib/browser/StorageController.default.js +15 -14
- package/lib/browser/StorageController.js +14 -1
- package/lib/browser/StorageController.react-native.js +31 -30
- package/lib/browser/StorageController.weapp.js +19 -13
- package/lib/browser/TaskQueue.js +31 -43
- package/lib/browser/UniqueInstanceStateController.js +65 -86
- package/lib/browser/WebSocketController.js +11 -4
- package/lib/browser/Xhr.weapp.js +90 -78
- package/lib/browser/arrayContainsObject.js +3 -3
- package/lib/browser/canBeSerialized.js +10 -11
- package/lib/browser/decode.js +11 -11
- package/lib/browser/encode.js +11 -11
- package/lib/browser/equals.js +9 -10
- package/lib/browser/escape.js +2 -2
- package/lib/browser/isRevocableSession.js +1 -1
- package/lib/browser/parseDate.js +10 -10
- package/lib/browser/promiseUtils.js +19 -19
- package/lib/browser/unique.js +4 -4
- package/lib/browser/unsavedChildren.js +20 -21
- package/lib/browser/uuid.js +2 -4
- package/lib/node/Analytics.js +5 -9
- package/lib/node/AnonymousUtils.js +10 -15
- package/lib/node/Cloud.js +11 -11
- package/lib/node/CoreManager.js +59 -67
- package/lib/node/CryptoController.js +8 -3
- package/lib/node/EventEmitter.js +7 -1
- package/lib/node/EventuallyQueue.js +20 -39
- package/lib/node/FacebookUtils.js +4 -8
- package/lib/node/IndexedDBStorageController.js +14 -10
- package/lib/node/InstallationController.js +12 -13
- package/lib/node/LiveQueryClient.js +23 -21
- package/lib/node/LiveQuerySubscription.js +6 -7
- package/lib/node/LocalDatastore.js +23 -23
- package/lib/node/LocalDatastoreController.default.js +11 -12
- package/lib/node/LocalDatastoreController.js +14 -1
- package/lib/node/LocalDatastoreController.react-native.js +25 -21
- package/lib/node/LocalDatastoreUtils.js +4 -7
- package/lib/node/ObjectStateMutations.js +12 -22
- package/lib/node/OfflineQuery.js +37 -23
- package/lib/node/Parse.js +36 -50
- package/lib/node/ParseACL.js +21 -30
- package/lib/node/ParseCLP.js +38 -40
- package/lib/node/ParseConfig.js +10 -17
- package/lib/node/ParseError.js +460 -461
- package/lib/node/ParseFile.js +27 -47
- package/lib/node/ParseGeoPoint.js +16 -17
- package/lib/node/ParseHooks.js +16 -18
- package/lib/node/ParseInstallation.js +10 -11
- package/lib/node/ParseLiveQuery.js +9 -14
- package/lib/node/ParseObject.js +142 -173
- package/lib/node/ParseOp.js +35 -47
- package/lib/node/ParsePolygon.js +14 -20
- package/lib/node/ParseQuery.js +100 -123
- package/lib/node/ParseRelation.js +10 -19
- package/lib/node/ParseRole.js +10 -11
- package/lib/node/ParseSchema.js +29 -42
- package/lib/node/ParseSession.js +10 -11
- package/lib/node/ParseUser.js +76 -87
- package/lib/node/Push.js +7 -12
- package/lib/node/RESTController.js +24 -36
- package/lib/node/SingleInstanceStateController.js +41 -69
- package/lib/node/Socket.weapp.js +23 -2
- package/lib/node/Storage.js +14 -19
- package/lib/node/StorageController.browser.js +10 -8
- package/lib/node/StorageController.default.js +9 -9
- package/lib/node/StorageController.js +16 -1
- package/lib/node/StorageController.react-native.js +20 -20
- package/lib/node/StorageController.weapp.js +14 -8
- package/lib/node/TaskQueue.js +2 -3
- package/lib/node/UniqueInstanceStateController.js +43 -63
- package/lib/node/WebSocketController.js +15 -2
- package/lib/node/Xhr.weapp.js +11 -2
- package/lib/node/arrayContainsObject.js +4 -4
- package/lib/node/canBeSerialized.js +5 -5
- package/lib/node/decode.js +4 -4
- package/lib/node/encode.js +5 -5
- package/lib/node/equals.js +4 -4
- package/lib/node/escape.js +1 -1
- package/lib/node/isRevocableSession.js +1 -1
- package/lib/node/parseDate.js +1 -1
- package/lib/node/promiseUtils.js +7 -7
- package/lib/node/unique.js +5 -5
- package/lib/node/unsavedChildren.js +5 -5
- package/lib/node/uuid.js +2 -4
- package/lib/react-native/Analytics.js +2 -2
- package/lib/react-native/AnonymousUtils.js +3 -4
- package/lib/react-native/CoreManager.js +2 -3
- package/lib/react-native/CryptoController.js +6 -1
- package/lib/react-native/EventEmitter.js +6 -1
- package/lib/react-native/EventuallyQueue.js +1 -2
- package/lib/react-native/FacebookUtils.js +1 -2
- package/lib/react-native/IndexedDBStorageController.js +11 -5
- package/lib/react-native/InstallationController.js +1 -2
- package/lib/react-native/LiveQueryClient.js +8 -7
- package/lib/react-native/LiveQuerySubscription.js +2 -4
- package/lib/react-native/LocalDatastore.js +3 -3
- package/lib/react-native/LocalDatastoreController.default.js +1 -2
- package/lib/react-native/LocalDatastoreController.js +11 -1
- package/lib/react-native/LocalDatastoreController.react-native.js +11 -12
- package/lib/react-native/LocalDatastoreUtils.js +3 -6
- package/lib/react-native/OfflineQuery.js +25 -20
- package/lib/react-native/Parse.js +24 -38
- package/lib/react-native/ParseACL.js +4 -6
- package/lib/react-native/ParseCLP.js +2 -4
- package/lib/react-native/ParseConfig.js +4 -6
- package/lib/react-native/ParseError.js +13 -31
- package/lib/react-native/ParseFile.js +3 -4
- package/lib/react-native/ParseGeoPoint.js +2 -4
- package/lib/react-native/ParseInstallation.js +13 -30
- package/lib/react-native/ParseLiveQuery.js +2 -4
- package/lib/react-native/ParseObject.js +77 -87
- package/lib/react-native/ParseOp.js +41 -79
- package/lib/react-native/ParsePolygon.js +2 -4
- package/lib/react-native/ParseQuery.js +43 -45
- package/lib/react-native/ParseRelation.js +2 -4
- package/lib/react-native/ParseRole.js +13 -30
- package/lib/react-native/ParseSchema.js +3 -5
- package/lib/react-native/ParseSession.js +12 -29
- package/lib/react-native/ParseUser.js +24 -49
- package/lib/react-native/RESTController.js +10 -4
- package/lib/react-native/SingleInstanceStateController.js +23 -37
- package/lib/react-native/Socket.weapp.js +9 -4
- package/lib/react-native/Storage.js +1 -2
- package/lib/react-native/StorageController.browser.js +6 -1
- package/lib/react-native/StorageController.default.js +6 -1
- package/lib/react-native/StorageController.js +13 -1
- package/lib/react-native/StorageController.react-native.js +11 -6
- package/lib/react-native/StorageController.weapp.js +6 -1
- package/lib/react-native/TaskQueue.js +2 -4
- package/lib/react-native/UniqueInstanceStateController.js +23 -37
- package/lib/react-native/WebSocketController.js +9 -1
- package/lib/react-native/Xhr.weapp.js +9 -4
- package/lib/react-native/unsavedChildren.js +3 -3
- package/lib/react-native/uuid.js +1 -2
- package/lib/weapp/Analytics.js +7 -11
- package/lib/weapp/AnonymousUtils.js +17 -22
- package/lib/weapp/Cloud.js +23 -41
- package/lib/weapp/CoreManager.js +71 -79
- package/lib/weapp/CryptoController.js +14 -9
- package/lib/weapp/EventEmitter.js +9 -2
- package/lib/weapp/EventuallyQueue.js +156 -357
- package/lib/weapp/FacebookUtils.js +23 -28
- package/lib/weapp/IndexedDBStorageController.js +18 -14
- package/lib/weapp/InstallationController.js +55 -121
- package/lib/weapp/LiveQueryClient.js +312 -485
- package/lib/weapp/LiveQuerySubscription.js +25 -28
- package/lib/weapp/LocalDatastore.js +258 -624
- package/lib/weapp/LocalDatastoreController.default.js +42 -226
- package/lib/weapp/LocalDatastoreController.js +11 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +66 -160
- package/lib/weapp/LocalDatastoreUtils.js +4 -7
- package/lib/weapp/ObjectStateMutations.js +54 -96
- package/lib/weapp/OfflineQuery.js +106 -198
- package/lib/weapp/Parse.js +44 -59
- package/lib/weapp/ParseACL.js +242 -288
- package/lib/weapp/ParseCLP.js +372 -572
- package/lib/weapp/ParseConfig.js +115 -138
- package/lib/weapp/ParseError.js +85 -182
- package/lib/weapp/ParseFile.js +295 -440
- package/lib/weapp/ParseGeoPoint.js +121 -146
- package/lib/weapp/ParseHooks.js +23 -25
- package/lib/weapp/ParseInstallation.js +225 -367
- package/lib/weapp/ParseLiveQuery.js +74 -148
- package/lib/weapp/ParseObject.js +2014 -2621
- package/lib/weapp/ParseOp.js +343 -484
- package/lib/weapp/ParsePolygon.js +101 -120
- package/lib/weapp/ParseQuery.js +1708 -2052
- package/lib/weapp/ParseRelation.js +99 -118
- package/lib/weapp/ParseRole.js +88 -140
- package/lib/weapp/ParseSchema.js +372 -434
- package/lib/weapp/ParseSession.js +62 -110
- package/lib/weapp/ParseUser.js +941 -1284
- package/lib/weapp/Push.js +15 -38
- package/lib/weapp/RESTController.js +86 -125
- package/lib/weapp/SingleInstanceStateController.js +57 -86
- package/lib/weapp/Socket.weapp.js +50 -33
- package/lib/weapp/Storage.js +23 -28
- package/lib/weapp/StorageController.browser.js +16 -13
- package/lib/weapp/StorageController.default.js +15 -14
- package/lib/weapp/StorageController.js +14 -1
- package/lib/weapp/StorageController.react-native.js +31 -30
- package/lib/weapp/StorageController.weapp.js +19 -13
- package/lib/weapp/TaskQueue.js +31 -43
- package/lib/weapp/UniqueInstanceStateController.js +65 -86
- package/lib/weapp/WebSocketController.js +11 -4
- package/lib/weapp/Xhr.weapp.js +90 -78
- package/lib/weapp/arrayContainsObject.js +3 -3
- package/lib/weapp/canBeSerialized.js +10 -11
- package/lib/weapp/decode.js +11 -11
- package/lib/weapp/encode.js +11 -11
- package/lib/weapp/equals.js +9 -10
- package/lib/weapp/escape.js +2 -2
- package/lib/weapp/isRevocableSession.js +1 -1
- package/lib/weapp/parseDate.js +10 -10
- package/lib/weapp/promiseUtils.js +19 -19
- package/lib/weapp/unique.js +4 -4
- package/lib/weapp/unsavedChildren.js +20 -21
- package/lib/weapp/uuid.js +6 -8
- package/package.json +24 -30
package/lib/browser/ParseFile.js
CHANGED
|
@@ -1,80 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _Object$keys2 = require("@babel/runtime-corejs3/core-js-stable/object/keys");
|
|
4
|
-
var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
|
|
5
|
-
var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
|
|
6
|
-
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
|
7
|
-
var _forEachInstanceProperty2 = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
|
8
|
-
var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
|
|
9
|
-
var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
|
|
10
3
|
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
|
11
4
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
12
5
|
_Object$defineProperty(exports, "__esModule", {
|
|
13
6
|
value: true
|
|
14
7
|
});
|
|
15
8
|
exports.default = void 0;
|
|
16
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
|
|
17
9
|
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array"));
|
|
18
10
|
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
19
11
|
var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
|
|
20
12
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
21
13
|
var _promise = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/promise"));
|
|
22
14
|
var _indexOf = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/index-of"));
|
|
23
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
|
24
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));
|
|
25
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
|
26
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
27
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
28
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
29
16
|
var _CoreManager = _interopRequireDefault(require("./CoreManager"));
|
|
30
17
|
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) {
|
|
36
|
-
return _Object$getOwnPropertyDescriptor(object, sym).enumerable;
|
|
37
|
-
})), keys.push.apply(keys, symbols);
|
|
38
|
-
}
|
|
39
|
-
return keys;
|
|
40
|
-
}
|
|
41
|
-
function _objectSpread(target) {
|
|
42
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
43
|
-
var _context8, _context9;
|
|
44
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
45
|
-
i % 2 ? _forEachInstanceProperty2(_context8 = ownKeys(Object(source), !0)).call(_context8, function (key) {
|
|
46
|
-
(0, _defineProperty2.default)(target, key, source[key]);
|
|
47
|
-
}) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context9 = ownKeys(Object(source))).call(_context9, function (key) {
|
|
48
|
-
_Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return target;
|
|
52
|
-
} /* global XMLHttpRequest, Blob */
|
|
53
|
-
var XHR = null;
|
|
18
|
+
var _Xhr = _interopRequireDefault(require("./Xhr.weapp"));
|
|
19
|
+
/* global XMLHttpRequest, Blob */
|
|
20
|
+
|
|
21
|
+
let XHR = null;
|
|
54
22
|
if (typeof XMLHttpRequest !== 'undefined') {
|
|
55
23
|
XHR = XMLHttpRequest;
|
|
56
24
|
}
|
|
57
|
-
|
|
58
|
-
metadata?: { [key: string]: any },
|
|
59
|
-
tags?: { [key: string]: any },
|
|
60
|
-
};*/
|
|
61
|
-
/*:: export type FileSource =
|
|
62
|
-
| {
|
|
63
|
-
format: 'file',
|
|
64
|
-
file: Blob,
|
|
65
|
-
type: string | undefined,
|
|
66
|
-
}
|
|
67
|
-
| {
|
|
68
|
-
format: 'base64',
|
|
69
|
-
base64: string,
|
|
70
|
-
type: string | undefined,
|
|
71
|
-
}
|
|
72
|
-
| {
|
|
73
|
-
format: 'uri',
|
|
74
|
-
uri: string,
|
|
75
|
-
type: string | undefined,
|
|
76
|
-
};*/
|
|
77
|
-
function b64Digit(number /*: number*/) /*: string*/{
|
|
25
|
+
function b64Digit(number) {
|
|
78
26
|
if (number < 26) {
|
|
79
27
|
return String.fromCharCode(65 + number);
|
|
80
28
|
}
|
|
@@ -99,7 +47,7 @@ function b64Digit(number /*: number*/) /*: string*/{
|
|
|
99
47
|
*
|
|
100
48
|
* @alias Parse.File
|
|
101
49
|
*/
|
|
102
|
-
|
|
50
|
+
class ParseFile {
|
|
103
51
|
/**
|
|
104
52
|
* @param name {String} The file's name. This will be prefixed by a unique
|
|
105
53
|
* value once the file has finished saving. The file name must begin with
|
|
@@ -130,8 +78,7 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
130
78
|
* @param metadata {object} Optional key value pairs to be stored with file object
|
|
131
79
|
* @param tags {object} Optional key value pairs to be stored with file object
|
|
132
80
|
*/
|
|
133
|
-
|
|
134
|
-
(0, _classCallCheck2.default)(this, ParseFile);
|
|
81
|
+
constructor(name, data, type, metadata, tags) {
|
|
135
82
|
(0, _defineProperty2.default)(this, "_name", void 0);
|
|
136
83
|
(0, _defineProperty2.default)(this, "_url", void 0);
|
|
137
84
|
(0, _defineProperty2.default)(this, "_source", void 0);
|
|
@@ -140,7 +87,7 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
140
87
|
(0, _defineProperty2.default)(this, "_requestTask", void 0);
|
|
141
88
|
(0, _defineProperty2.default)(this, "_metadata", void 0);
|
|
142
89
|
(0, _defineProperty2.default)(this, "_tags", void 0);
|
|
143
|
-
|
|
90
|
+
const specifiedType = type || '';
|
|
144
91
|
this._name = name;
|
|
145
92
|
this._metadata = metadata || {};
|
|
146
93
|
this._tags = tags || {};
|
|
@@ -166,12 +113,12 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
166
113
|
};
|
|
167
114
|
} else if (data && typeof data.base64 === 'string') {
|
|
168
115
|
var _context, _context2, _context3;
|
|
169
|
-
|
|
170
|
-
|
|
116
|
+
const base64 = (0, _slice.default)(_context = data.base64.split(',')).call(_context, -1)[0];
|
|
117
|
+
const dataType = specifiedType || (0, _slice.default)(_context2 = (0, _slice.default)(_context3 = data.base64.split(';')).call(_context3, 0, 1)[0].split(':')).call(_context2, 1, 2)[0] || 'text/plain';
|
|
171
118
|
this._data = base64;
|
|
172
119
|
this._source = {
|
|
173
120
|
format: 'base64',
|
|
174
|
-
base64
|
|
121
|
+
base64,
|
|
175
122
|
type: dataType
|
|
176
123
|
};
|
|
177
124
|
} else {
|
|
@@ -187,398 +134,308 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
187
134
|
*
|
|
188
135
|
* @returns {Promise} Promise that is resolve with base64 data
|
|
189
136
|
*/
|
|
190
|
-
(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
var _getData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
194
|
-
var _this = this;
|
|
195
|
-
var options, controller, result;
|
|
196
|
-
return _regenerator.default.wrap(function (_context4) {
|
|
197
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
198
|
-
case 0:
|
|
199
|
-
if (!this._data) {
|
|
200
|
-
_context4.next = 2;
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
return _context4.abrupt("return", this._data);
|
|
204
|
-
case 2:
|
|
205
|
-
if (this._url) {
|
|
206
|
-
_context4.next = 4;
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
210
|
-
case 4:
|
|
211
|
-
options = {
|
|
212
|
-
requestTask: function (task) {
|
|
213
|
-
return _this._requestTask = task;
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
controller = _CoreManager.default.getFileController();
|
|
217
|
-
_context4.next = 8;
|
|
218
|
-
return controller.download(this._url, options);
|
|
219
|
-
case 8:
|
|
220
|
-
result = _context4.sent;
|
|
221
|
-
this._data = result.base64;
|
|
222
|
-
return _context4.abrupt("return", this._data);
|
|
223
|
-
case 11:
|
|
224
|
-
case "end":
|
|
225
|
-
return _context4.stop();
|
|
226
|
-
}
|
|
227
|
-
}, _callee, this);
|
|
228
|
-
}));
|
|
229
|
-
function getData() {
|
|
230
|
-
return _getData.apply(this, arguments);
|
|
231
|
-
}
|
|
232
|
-
return getData;
|
|
233
|
-
}()
|
|
234
|
-
/**
|
|
235
|
-
* Gets the name of the file. Before save is called, this is the filename
|
|
236
|
-
* given by the user. After save is called, that name gets prefixed with a
|
|
237
|
-
* unique identifier.
|
|
238
|
-
*
|
|
239
|
-
* @returns {string}
|
|
240
|
-
*/
|
|
241
|
-
}, {
|
|
242
|
-
key: "name",
|
|
243
|
-
value: function () /*: string*/{
|
|
244
|
-
return this._name;
|
|
137
|
+
async getData() {
|
|
138
|
+
if (this._data) {
|
|
139
|
+
return this._data;
|
|
245
140
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
* Gets the url of the file. It is only available after you save the file or
|
|
249
|
-
* after you get the file from a Parse.Object.
|
|
250
|
-
*
|
|
251
|
-
* @param {object} options An object to specify url options
|
|
252
|
-
* @param {boolean} [options.forceSecure] force the url to be secure
|
|
253
|
-
* @returns {string | undefined}
|
|
254
|
-
*/
|
|
255
|
-
}, {
|
|
256
|
-
key: "url",
|
|
257
|
-
value: function (options /*:: ?: { forceSecure?: boolean }*/) /*: string | undefined*/{
|
|
258
|
-
options = options || {};
|
|
259
|
-
if (!this._url) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
if (options.forceSecure) {
|
|
263
|
-
return this._url.replace(/^http:\/\//i, 'https://');
|
|
264
|
-
} else {
|
|
265
|
-
return this._url;
|
|
266
|
-
}
|
|
141
|
+
if (!this._url) {
|
|
142
|
+
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
267
143
|
}
|
|
144
|
+
const controller = _CoreManager.default.getFileController();
|
|
145
|
+
const result = await controller.download(this._url, {
|
|
146
|
+
requestTask: task => this._requestTask = task
|
|
147
|
+
});
|
|
148
|
+
this._data = result.base64;
|
|
149
|
+
return this._data;
|
|
150
|
+
}
|
|
268
151
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Gets the name of the file. Before save is called, this is the filename
|
|
154
|
+
* given by the user. After save is called, that name gets prefixed with a
|
|
155
|
+
* unique identifier.
|
|
156
|
+
*
|
|
157
|
+
* @returns {string}
|
|
158
|
+
*/
|
|
159
|
+
name() {
|
|
160
|
+
return this._name;
|
|
161
|
+
}
|
|
279
162
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
163
|
+
/**
|
|
164
|
+
* Gets the url of the file. It is only available after you save the file or
|
|
165
|
+
* after you get the file from a Parse.Object.
|
|
166
|
+
*
|
|
167
|
+
* @param {object} options An object to specify url options
|
|
168
|
+
* @param {boolean} [options.forceSecure] force the url to be secure
|
|
169
|
+
* @returns {string | undefined}
|
|
170
|
+
*/
|
|
171
|
+
url(options) {
|
|
172
|
+
options = options || {};
|
|
173
|
+
if (!this._url) {
|
|
174
|
+
return;
|
|
289
175
|
}
|
|
176
|
+
if (options.forceSecure) {
|
|
177
|
+
return this._url.replace(/^http:\/\//i, 'https://');
|
|
178
|
+
} else {
|
|
179
|
+
return this._url;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
290
182
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Gets the metadata of the file.
|
|
185
|
+
*
|
|
186
|
+
* @returns {object}
|
|
187
|
+
*/
|
|
188
|
+
metadata() {
|
|
189
|
+
return this._metadata;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Gets the tags of the file.
|
|
194
|
+
*
|
|
195
|
+
* @returns {object}
|
|
196
|
+
*/
|
|
197
|
+
tags() {
|
|
198
|
+
return this._tags;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Saves the file to the Parse cloud.
|
|
203
|
+
*
|
|
204
|
+
* @param {object} options
|
|
205
|
+
* Valid options are:<ul>
|
|
206
|
+
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
207
|
+
* be used for this request.
|
|
208
|
+
* <li>sessionToken: A valid session token, used for making a request on
|
|
209
|
+
* behalf of a specific user.
|
|
210
|
+
* <li>progress: In Browser only, callback for upload progress. For example:
|
|
211
|
+
* <pre>
|
|
212
|
+
* let parseFile = new Parse.File(name, file);
|
|
213
|
+
* parseFile.save({
|
|
214
|
+
* progress: (progressValue, loaded, total, { type }) => {
|
|
215
|
+
* if (type === "upload" && progressValue !== null) {
|
|
216
|
+
* // Update the UI using progressValue
|
|
217
|
+
* }
|
|
218
|
+
* }
|
|
219
|
+
* });
|
|
220
|
+
* </pre>
|
|
221
|
+
* </ul>
|
|
222
|
+
* @returns {Promise | undefined} Promise that is resolved when the save finishes.
|
|
223
|
+
*/
|
|
224
|
+
save(options) {
|
|
225
|
+
options = options || {};
|
|
226
|
+
options.requestTask = task => this._requestTask = task;
|
|
227
|
+
options.metadata = this._metadata;
|
|
228
|
+
options.tags = this._tags;
|
|
229
|
+
const controller = _CoreManager.default.getFileController();
|
|
230
|
+
if (!this._previousSave) {
|
|
231
|
+
if (this._source.format === 'file') {
|
|
232
|
+
this._previousSave = controller.saveFile(this._name, this._source, options).then(res => {
|
|
233
|
+
this._name = res.name;
|
|
234
|
+
this._url = res.url;
|
|
235
|
+
this._data = null;
|
|
236
|
+
this._requestTask = null;
|
|
237
|
+
return this;
|
|
238
|
+
});
|
|
239
|
+
} else if (this._source.format === 'uri') {
|
|
240
|
+
this._previousSave = controller.download(this._source.uri, options).then(result => {
|
|
241
|
+
if (!(result && result.base64)) {
|
|
242
|
+
return {};
|
|
243
|
+
}
|
|
244
|
+
const newSource = {
|
|
245
|
+
format: 'base64',
|
|
246
|
+
base64: result.base64,
|
|
247
|
+
type: result.contentType
|
|
248
|
+
};
|
|
249
|
+
this._data = result.base64;
|
|
250
|
+
this._requestTask = null;
|
|
251
|
+
return controller.saveBase64(this._name, newSource, options);
|
|
252
|
+
}).then(res => {
|
|
253
|
+
this._name = res.name;
|
|
254
|
+
this._url = res.url;
|
|
255
|
+
this._requestTask = null;
|
|
256
|
+
return this;
|
|
257
|
+
});
|
|
258
|
+
} else {
|
|
259
|
+
this._previousSave = controller.saveBase64(this._name, this._source, options).then(res => {
|
|
260
|
+
this._name = res.name;
|
|
261
|
+
this._url = res.url;
|
|
262
|
+
this._requestTask = null;
|
|
263
|
+
return this;
|
|
264
|
+
});
|
|
364
265
|
}
|
|
365
266
|
}
|
|
267
|
+
if (this._previousSave) {
|
|
268
|
+
return this._previousSave;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
366
271
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
this._requestTask._aborted = true;
|
|
375
|
-
this._requestTask.abort();
|
|
376
|
-
}
|
|
377
|
-
this._requestTask = null;
|
|
272
|
+
/**
|
|
273
|
+
* Aborts the request if it has already been sent.
|
|
274
|
+
*/
|
|
275
|
+
cancel() {
|
|
276
|
+
if (this._requestTask && typeof this._requestTask.abort === 'function') {
|
|
277
|
+
this._requestTask._aborted = true;
|
|
278
|
+
this._requestTask.abort();
|
|
378
279
|
}
|
|
280
|
+
this._requestTask = null;
|
|
281
|
+
}
|
|
379
282
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
var options /*: FullOptions*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
396
|
-
if (!this._name) {
|
|
397
|
-
throw new _ParseError.default(_ParseError.default.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
|
|
398
|
-
}
|
|
399
|
-
var destroyOptions = {
|
|
400
|
-
useMasterKey: true
|
|
401
|
-
};
|
|
402
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
403
|
-
destroyOptions.useMasterKey = !!options.useMasterKey;
|
|
404
|
-
}
|
|
405
|
-
var controller = _CoreManager.default.getFileController();
|
|
406
|
-
return controller.deleteFile(this._name, destroyOptions).then(function () {
|
|
407
|
-
_this3._data = undefined;
|
|
408
|
-
_this3._requestTask = null;
|
|
409
|
-
return _this3;
|
|
410
|
-
});
|
|
283
|
+
/**
|
|
284
|
+
* Deletes the file from the Parse cloud.
|
|
285
|
+
* In Cloud Code and Node only with Master Key.
|
|
286
|
+
*
|
|
287
|
+
* @param {object} options
|
|
288
|
+
* Valid options are:<ul>
|
|
289
|
+
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
|
|
290
|
+
* be used for this request.
|
|
291
|
+
* <pre>
|
|
292
|
+
* @returns {Promise} Promise that is resolved when the delete finishes.
|
|
293
|
+
*/
|
|
294
|
+
destroy() {
|
|
295
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
296
|
+
if (!this._name) {
|
|
297
|
+
throw new _ParseError.default(_ParseError.default.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
|
|
411
298
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
name: this._name,
|
|
418
|
-
url: this._url
|
|
419
|
-
};
|
|
299
|
+
const destroyOptions = {
|
|
300
|
+
useMasterKey: true
|
|
301
|
+
};
|
|
302
|
+
if (options.hasOwnProperty('useMasterKey')) {
|
|
303
|
+
destroyOptions.useMasterKey = !!options.useMasterKey;
|
|
420
304
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
305
|
+
const controller = _CoreManager.default.getFileController();
|
|
306
|
+
return controller.deleteFile(this._name, destroyOptions).then(() => {
|
|
307
|
+
this._data = undefined;
|
|
308
|
+
this._requestTask = null;
|
|
309
|
+
return this;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
toJSON() {
|
|
313
|
+
return {
|
|
314
|
+
__type: 'File',
|
|
315
|
+
name: this._name,
|
|
316
|
+
url: this._url
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
equals(other) {
|
|
320
|
+
if (this === other) {
|
|
321
|
+
return true;
|
|
429
322
|
}
|
|
323
|
+
// Unsaved Files are never equal, since they will be saved to different URLs
|
|
324
|
+
return other instanceof ParseFile && this.name() === other.name() && this.url() === other.url() && typeof this.url() !== 'undefined';
|
|
325
|
+
}
|
|
430
326
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
(0, _forEach.default)(_context5 = (0, _keys.default)(metadata)).call(_context5, function (key) {
|
|
443
|
-
_this4.addMetadata(key, metadata[key]);
|
|
444
|
-
});
|
|
445
|
-
}
|
|
327
|
+
/**
|
|
328
|
+
* Sets metadata to be saved with file object. Overwrites existing metadata
|
|
329
|
+
*
|
|
330
|
+
* @param {object} metadata Key value pairs to be stored with file object
|
|
331
|
+
*/
|
|
332
|
+
setMetadata(metadata) {
|
|
333
|
+
if (metadata && typeof metadata === 'object') {
|
|
334
|
+
var _context4;
|
|
335
|
+
(0, _forEach.default)(_context4 = (0, _keys.default)(metadata)).call(_context4, key => {
|
|
336
|
+
this.addMetadata(key, metadata[key]);
|
|
337
|
+
});
|
|
446
338
|
}
|
|
339
|
+
}
|
|
447
340
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
key
|
|
456
|
-
|
|
457
|
-
if (typeof key === 'string') {
|
|
458
|
-
this._metadata[key] = value;
|
|
459
|
-
}
|
|
341
|
+
/**
|
|
342
|
+
* Sets metadata to be saved with file object. Adds to existing metadata.
|
|
343
|
+
*
|
|
344
|
+
* @param {string} key key to store the metadata
|
|
345
|
+
* @param {*} value metadata
|
|
346
|
+
*/
|
|
347
|
+
addMetadata(key, value) {
|
|
348
|
+
if (typeof key === 'string') {
|
|
349
|
+
this._metadata[key] = value;
|
|
460
350
|
}
|
|
351
|
+
}
|
|
461
352
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
(0, _forEach.default)(_context6 = (0, _keys.default)(tags)).call(_context6, function (key) {
|
|
474
|
-
_this5.addTag(key, tags[key]);
|
|
475
|
-
});
|
|
476
|
-
}
|
|
353
|
+
/**
|
|
354
|
+
* Sets tags to be saved with file object. Overwrites existing tags
|
|
355
|
+
*
|
|
356
|
+
* @param {object} tags Key value pairs to be stored with file object
|
|
357
|
+
*/
|
|
358
|
+
setTags(tags) {
|
|
359
|
+
if (tags && typeof tags === 'object') {
|
|
360
|
+
var _context5;
|
|
361
|
+
(0, _forEach.default)(_context5 = (0, _keys.default)(tags)).call(_context5, key => {
|
|
362
|
+
this.addTag(key, tags[key]);
|
|
363
|
+
});
|
|
477
364
|
}
|
|
365
|
+
}
|
|
478
366
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
key
|
|
487
|
-
|
|
488
|
-
if (typeof key === 'string') {
|
|
489
|
-
this._tags[key] = value;
|
|
490
|
-
}
|
|
367
|
+
/**
|
|
368
|
+
* Sets tags to be saved with file object. Adds to existing tags.
|
|
369
|
+
*
|
|
370
|
+
* @param {string} key key to store tags
|
|
371
|
+
* @param {*} value tag
|
|
372
|
+
*/
|
|
373
|
+
addTag(key, value) {
|
|
374
|
+
if (typeof key === 'string') {
|
|
375
|
+
this._tags[key] = value;
|
|
491
376
|
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
throw new TypeError('JSON object does not represent a ParseFile');
|
|
497
|
-
}
|
|
498
|
-
var file = new ParseFile(obj.name);
|
|
499
|
-
file._url = obj.url;
|
|
500
|
-
return file;
|
|
377
|
+
}
|
|
378
|
+
static fromJSON(obj) {
|
|
379
|
+
if (obj.__type !== 'File') {
|
|
380
|
+
throw new TypeError('JSON object does not represent a ParseFile');
|
|
501
381
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
382
|
+
const file = new ParseFile(obj.name);
|
|
383
|
+
file._url = obj.url;
|
|
384
|
+
return file;
|
|
385
|
+
}
|
|
386
|
+
static encodeBase64(bytes) {
|
|
387
|
+
const chunks = [];
|
|
388
|
+
chunks.length = Math.ceil(bytes.length / 3);
|
|
389
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
390
|
+
const b1 = bytes[i * 3];
|
|
391
|
+
const b2 = bytes[i * 3 + 1] || 0;
|
|
392
|
+
const b3 = bytes[i * 3 + 2] || 0;
|
|
393
|
+
const has2 = i * 3 + 1 < bytes.length;
|
|
394
|
+
const has3 = i * 3 + 2 < bytes.length;
|
|
395
|
+
chunks[i] = [b64Digit(b1 >> 2 & 0x3f), b64Digit(b1 << 4 & 0x30 | b2 >> 4 & 0x0f), has2 ? b64Digit(b2 << 2 & 0x3c | b3 >> 6 & 0x03) : '=', has3 ? b64Digit(b3 & 0x3f) : '='].join('');
|
|
516
396
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
saveFile: function () {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
return _regenerator.default.wrap(function (_context7) {
|
|
525
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
526
|
-
case 0:
|
|
527
|
-
if (!(source.format !== 'file')) {
|
|
528
|
-
_context7.next = 2;
|
|
529
|
-
break;
|
|
530
|
-
}
|
|
531
|
-
throw new Error('saveFile can only be used with File-type sources.');
|
|
532
|
-
case 2:
|
|
533
|
-
_context7.next = 4;
|
|
534
|
-
return new _promise.default(function (res, rej) {
|
|
535
|
-
// eslint-disable-next-line no-undef
|
|
536
|
-
var reader = new FileReader();
|
|
537
|
-
reader.onload = function () {
|
|
538
|
-
return res(reader.result);
|
|
539
|
-
};
|
|
540
|
-
reader.onerror = function (error) {
|
|
541
|
-
return rej(error);
|
|
542
|
-
};
|
|
543
|
-
reader.readAsDataURL(source.file);
|
|
544
|
-
});
|
|
545
|
-
case 4:
|
|
546
|
-
base64Data = _context7.sent;
|
|
547
|
-
// we only want the data after the comma
|
|
548
|
-
// For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
|
|
549
|
-
_base64Data$split = base64Data.split(','), _base64Data$split2 = (0, _slicedToArray2.default)(_base64Data$split, 2), first = _base64Data$split2[0], second = _base64Data$split2[1]; // in the event there is no 'data:application/pdf;base64,' at the beginning of the base64 string
|
|
550
|
-
// use the entire string instead
|
|
551
|
-
data = second ? second : first;
|
|
552
|
-
newSource = {
|
|
553
|
-
format: 'base64',
|
|
554
|
-
base64: data,
|
|
555
|
-
type: source.type || (source.file ? source.file.type : undefined)
|
|
556
|
-
};
|
|
557
|
-
_context7.next = 10;
|
|
558
|
-
return DefaultController.saveBase64(name, newSource, options);
|
|
559
|
-
case 10:
|
|
560
|
-
return _context7.abrupt("return", _context7.sent);
|
|
561
|
-
case 11:
|
|
562
|
-
case "end":
|
|
563
|
-
return _context7.stop();
|
|
564
|
-
}
|
|
565
|
-
}, _callee2);
|
|
566
|
-
}));
|
|
567
|
-
function saveFile() {
|
|
568
|
-
return _saveFile.apply(this, arguments);
|
|
397
|
+
return chunks.join('');
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
const DefaultController = {
|
|
401
|
+
saveFile: async function (name, source, options) {
|
|
402
|
+
if (source.format !== 'file') {
|
|
403
|
+
throw new Error('saveFile can only be used with File-type sources.');
|
|
569
404
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
405
|
+
const base64Data = await new _promise.default((res, rej) => {
|
|
406
|
+
// eslint-disable-next-line no-undef
|
|
407
|
+
const reader = new FileReader();
|
|
408
|
+
reader.onload = () => res(reader.result);
|
|
409
|
+
reader.onerror = error => rej(error);
|
|
410
|
+
reader.readAsDataURL(source.file);
|
|
411
|
+
});
|
|
412
|
+
// we only want the data after the comma
|
|
413
|
+
// For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
|
|
414
|
+
const [first, second] = base64Data.split(',');
|
|
415
|
+
// in the event there is no 'data:application/pdf;base64,' at the beginning of the base64 string
|
|
416
|
+
// use the entire string instead
|
|
417
|
+
const data = second ? second : first;
|
|
418
|
+
const newSource = {
|
|
419
|
+
format: 'base64',
|
|
420
|
+
base64: data,
|
|
421
|
+
type: source.type || (source.file ? source.file.type : undefined)
|
|
422
|
+
};
|
|
423
|
+
return await DefaultController.saveBase64(name, newSource, options);
|
|
424
|
+
},
|
|
425
|
+
saveBase64: function (name, source) {
|
|
426
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
574
427
|
if (source.format !== 'base64') {
|
|
575
428
|
throw new Error('saveBase64 can only be used with Base64-type sources.');
|
|
576
429
|
}
|
|
577
|
-
|
|
430
|
+
const data = {
|
|
578
431
|
base64: source.base64,
|
|
579
432
|
fileData: {
|
|
580
|
-
metadata:
|
|
581
|
-
|
|
433
|
+
metadata: {
|
|
434
|
+
...options.metadata
|
|
435
|
+
},
|
|
436
|
+
tags: {
|
|
437
|
+
...options.tags
|
|
438
|
+
}
|
|
582
439
|
}
|
|
583
440
|
};
|
|
584
441
|
delete options.metadata;
|
|
@@ -595,9 +452,9 @@ var DefaultController = {
|
|
|
595
452
|
return _promise.default.reject('Cannot make a request: No definition of XMLHttpRequest was found.');
|
|
596
453
|
}
|
|
597
454
|
},
|
|
598
|
-
downloadAjax: function (uri
|
|
599
|
-
return new _promise.default(
|
|
600
|
-
|
|
455
|
+
downloadAjax: function (uri, options) {
|
|
456
|
+
return new _promise.default((resolve, reject) => {
|
|
457
|
+
const xhr = new XHR();
|
|
601
458
|
xhr.open('GET', uri, true);
|
|
602
459
|
xhr.responseType = 'arraybuffer';
|
|
603
460
|
xhr.onerror = function (e) {
|
|
@@ -610,7 +467,7 @@ var DefaultController = {
|
|
|
610
467
|
if (!this.response) {
|
|
611
468
|
return resolve({});
|
|
612
469
|
}
|
|
613
|
-
|
|
470
|
+
const bytes = new Uint8Array(this.response);
|
|
614
471
|
resolve({
|
|
615
472
|
base64: ParseFile.encodeBase64(bytes),
|
|
616
473
|
contentType: xhr.getResponseHeader('content-type')
|
|
@@ -620,19 +477,19 @@ var DefaultController = {
|
|
|
620
477
|
xhr.send();
|
|
621
478
|
});
|
|
622
479
|
},
|
|
623
|
-
deleteFile: function (name
|
|
624
|
-
|
|
480
|
+
deleteFile: function (name, options) {
|
|
481
|
+
const headers = {
|
|
625
482
|
'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID')
|
|
626
483
|
};
|
|
627
484
|
if (options.useMasterKey) {
|
|
628
485
|
headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
|
|
629
486
|
}
|
|
630
|
-
|
|
487
|
+
let url = _CoreManager.default.get('SERVER_URL');
|
|
631
488
|
if (url[url.length - 1] !== '/') {
|
|
632
489
|
url += '/';
|
|
633
490
|
}
|
|
634
491
|
url += 'files/' + name;
|
|
635
|
-
return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(
|
|
492
|
+
return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(response => {
|
|
636
493
|
// TODO: return JSON object in server
|
|
637
494
|
if (!response || response === 'SyntaxError: Unexpected end of JSON input') {
|
|
638
495
|
return _promise.default.resolve();
|
|
@@ -641,14 +498,13 @@ var DefaultController = {
|
|
|
641
498
|
}
|
|
642
499
|
});
|
|
643
500
|
},
|
|
644
|
-
_setXHR
|
|
501
|
+
_setXHR(xhr) {
|
|
645
502
|
XHR = xhr;
|
|
646
503
|
},
|
|
647
|
-
_getXHR
|
|
504
|
+
_getXHR() {
|
|
648
505
|
return XHR;
|
|
649
506
|
}
|
|
650
507
|
};
|
|
651
508
|
_CoreManager.default.setFileController(DefaultController);
|
|
652
|
-
var _default = ParseFile;
|
|
653
|
-
exports.default = _default;
|
|
509
|
+
var _default = exports.default = ParseFile;
|
|
654
510
|
exports.b64Digit = b64Digit;
|