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