parse 5.1.1-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 +10186 -14918
- package/dist/parse.min.js +2 -2
- package/dist/parse.weapp.js +10180 -15057
- 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 +24 -46
- 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 -446
- package/lib/browser/LiveQuerySubscription.js +25 -28
- package/lib/browser/LocalDatastore.js +254 -578
- package/lib/browser/LocalDatastoreController.default.js +48 -227
- package/lib/browser/LocalDatastoreController.js +11 -1
- package/lib/browser/LocalDatastoreController.react-native.js +72 -164
- package/lib/browser/LocalDatastoreUtils.js +4 -12
- package/lib/browser/ObjectStateMutations.js +89 -95
- package/lib/browser/OfflineQuery.js +106 -198
- package/lib/browser/Parse.js +45 -61
- package/lib/browser/ParseACL.js +242 -288
- package/lib/browser/ParseCLP.js +372 -580
- package/lib/browser/ParseConfig.js +115 -138
- package/lib/browser/ParseError.js +85 -182
- package/lib/browser/ParseFile.js +296 -444
- package/lib/browser/ParseGeoPoint.js +121 -140
- package/lib/browser/ParseHooks.js +12 -14
- package/lib/browser/ParseInstallation.js +226 -354
- package/lib/browser/ParseLiveQuery.js +74 -148
- package/lib/browser/ParseObject.js +2017 -2622
- package/lib/browser/ParseOp.js +343 -484
- package/lib/browser/ParsePolygon.js +101 -120
- package/lib/browser/ParseQuery.js +1722 -2068
- package/lib/browser/ParseRelation.js +99 -118
- package/lib/browser/ParseRole.js +88 -144
- package/lib/browser/ParseSchema.js +372 -434
- package/lib/browser/ParseSession.js +62 -110
- package/lib/browser/ParseUser.js +942 -1270
- package/lib/browser/Push.js +16 -44
- 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 +37 -49
- 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 -12
- 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 +18 -37
- package/lib/node/FacebookUtils.js +1 -5
- package/lib/node/IndexedDBStorageController.js +14 -10
- package/lib/node/InstallationController.js +7 -8
- package/lib/node/LiveQueryClient.js +20 -32
- package/lib/node/LiveQuerySubscription.js +3 -4
- package/lib/node/LocalDatastore.js +20 -24
- package/lib/node/LocalDatastoreController.default.js +12 -11
- package/lib/node/LocalDatastoreController.js +14 -1
- package/lib/node/LocalDatastoreController.react-native.js +27 -22
- package/lib/node/LocalDatastoreUtils.js +4 -12
- package/lib/node/ObjectStateMutations.js +52 -36
- package/lib/node/OfflineQuery.js +37 -23
- package/lib/node/Parse.js +35 -49
- package/lib/node/ParseACL.js +18 -27
- package/lib/node/ParseCLP.js +38 -50
- package/lib/node/ParseConfig.js +7 -14
- package/lib/node/ParseError.js +457 -458
- package/lib/node/ParseFile.js +33 -66
- package/lib/node/ParseGeoPoint.js +22 -17
- package/lib/node/ParseHooks.js +0 -2
- package/lib/node/ParseInstallation.js +21 -8
- package/lib/node/ParseLiveQuery.js +6 -11
- package/lib/node/ParseObject.js +138 -167
- package/lib/node/ParseOp.js +32 -44
- package/lib/node/ParsePolygon.js +11 -17
- package/lib/node/ParseQuery.js +118 -164
- package/lib/node/ParseRelation.js +7 -16
- package/lib/node/ParseRole.js +7 -13
- package/lib/node/ParseSchema.js +26 -39
- package/lib/node/ParseSession.js +7 -8
- package/lib/node/ParseUser.js +70 -76
- package/lib/node/Push.js +5 -15
- 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 +8 -11
- 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/Cloud.js +0 -1
- 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 +51 -36
- package/lib/react-native/LiveQuerySubscription.js +2 -4
- package/lib/react-native/LocalDatastore.js +41 -17
- package/lib/react-native/LocalDatastoreController.default.js +6 -1
- package/lib/react-native/LocalDatastoreController.js +11 -1
- package/lib/react-native/LocalDatastoreController.react-native.js +16 -11
- package/lib/react-native/LocalDatastoreUtils.js +3 -6
- package/lib/react-native/ObjectStateMutations.js +30 -9
- 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 +5 -7
- package/lib/react-native/ParseConfig.js +4 -6
- package/lib/react-native/ParseError.js +13 -31
- package/lib/react-native/ParseFile.js +10 -10
- 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 +81 -90
- package/lib/react-native/ParseOp.js +41 -79
- package/lib/react-native/ParsePolygon.js +2 -4
- package/lib/react-native/ParseQuery.js +87 -81
- package/lib/react-native/ParseRelation.js +2 -4
- package/lib/react-native/ParseRole.js +14 -31
- package/lib/react-native/ParseSchema.js +3 -5
- package/lib/react-native/ParseSession.js +12 -29
- package/lib/react-native/ParseUser.js +32 -51
- 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 +8 -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 +24 -46
- 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 -446
- package/lib/weapp/LiveQuerySubscription.js +25 -28
- package/lib/weapp/LocalDatastore.js +254 -578
- package/lib/weapp/LocalDatastoreController.default.js +48 -227
- package/lib/weapp/LocalDatastoreController.js +11 -1
- package/lib/weapp/LocalDatastoreController.react-native.js +72 -164
- package/lib/weapp/LocalDatastoreUtils.js +4 -12
- package/lib/weapp/ObjectStateMutations.js +89 -95
- package/lib/weapp/OfflineQuery.js +106 -198
- package/lib/weapp/Parse.js +45 -60
- package/lib/weapp/ParseACL.js +242 -288
- package/lib/weapp/ParseCLP.js +372 -580
- package/lib/weapp/ParseConfig.js +115 -138
- package/lib/weapp/ParseError.js +85 -182
- package/lib/weapp/ParseFile.js +297 -446
- package/lib/weapp/ParseGeoPoint.js +121 -140
- package/lib/weapp/ParseHooks.js +12 -14
- package/lib/weapp/ParseInstallation.js +226 -354
- package/lib/weapp/ParseLiveQuery.js +74 -148
- package/lib/weapp/ParseObject.js +2017 -2622
- package/lib/weapp/ParseOp.js +343 -484
- package/lib/weapp/ParsePolygon.js +101 -120
- package/lib/weapp/ParseQuery.js +1722 -2068
- package/lib/weapp/ParseRelation.js +99 -118
- package/lib/weapp/ParseRole.js +88 -144
- package/lib/weapp/ParseSchema.js +372 -434
- package/lib/weapp/ParseSession.js +62 -110
- package/lib/weapp/ParseUser.js +942 -1270
- package/lib/weapp/Push.js +16 -44
- 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 +37 -49
- 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 +23 -30
package/lib/weapp/ParseFile.js
CHANGED
|
@@ -1,88 +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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return _Object$getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
-
})), keys.push.apply(keys, symbols);
|
|
37
|
-
}
|
|
38
|
-
return keys;
|
|
39
|
-
}
|
|
40
|
-
function _objectSpread(target) {
|
|
41
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
42
|
-
var _context8, _context9;
|
|
43
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
44
|
-
i % 2 ? _forEachInstanceProperty2(_context8 = ownKeys(Object(source), !0)).call(_context8, function (key) {
|
|
45
|
-
(0, _defineProperty2.default)(target, key, source[key]);
|
|
46
|
-
}) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty2(_context9 = ownKeys(Object(source))).call(_context9, function (key) {
|
|
47
|
-
_Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
return target;
|
|
51
|
-
} /**
|
|
52
|
-
* @flow
|
|
53
|
-
*/ /* global XMLHttpRequest, Blob */
|
|
54
|
-
/*:: import type { FullOptions } from './RESTController';*/
|
|
55
|
-
var ParseError = require('./ParseError').default;
|
|
56
|
-
var XHR = null;
|
|
17
|
+
var _ParseError = _interopRequireDefault(require("./ParseError"));
|
|
18
|
+
var _Xhr = _interopRequireDefault(require("./Xhr.weapp"));
|
|
19
|
+
/* global XMLHttpRequest, Blob */
|
|
20
|
+
|
|
21
|
+
let XHR = null;
|
|
57
22
|
if (typeof XMLHttpRequest !== 'undefined') {
|
|
58
23
|
XHR = XMLHttpRequest;
|
|
59
24
|
}
|
|
60
|
-
XHR =
|
|
61
|
-
|
|
62
|
-
/*:: type Base64 = { base64: string };*/
|
|
63
|
-
/*:: type Uri = { uri: string };*/
|
|
64
|
-
/*:: type FileData = Array<number> | Base64 | Blob | Uri;*/
|
|
65
|
-
/*:: export type FileSaveOptions = FullOptions & {
|
|
66
|
-
metadata?: { [key: string]: any },
|
|
67
|
-
tags?: { [key: string]: any },
|
|
68
|
-
};*/
|
|
69
|
-
/*:: export type FileSource =
|
|
70
|
-
| {
|
|
71
|
-
format: 'file',
|
|
72
|
-
file: Blob,
|
|
73
|
-
type: string,
|
|
74
|
-
}
|
|
75
|
-
| {
|
|
76
|
-
format: 'base64',
|
|
77
|
-
base64: string,
|
|
78
|
-
type: string,
|
|
79
|
-
}
|
|
80
|
-
| {
|
|
81
|
-
format: 'uri',
|
|
82
|
-
uri: string,
|
|
83
|
-
type: string,
|
|
84
|
-
};*/
|
|
85
|
-
function b64Digit(number /*: number*/) /*: string*/{
|
|
25
|
+
XHR = _Xhr.default;
|
|
26
|
+
function b64Digit(number) {
|
|
86
27
|
if (number < 26) {
|
|
87
28
|
return String.fromCharCode(65 + number);
|
|
88
29
|
}
|
|
@@ -107,7 +48,7 @@ function b64Digit(number /*: number*/) /*: string*/{
|
|
|
107
48
|
*
|
|
108
49
|
* @alias Parse.File
|
|
109
50
|
*/
|
|
110
|
-
|
|
51
|
+
class ParseFile {
|
|
111
52
|
/**
|
|
112
53
|
* @param name {String} The file's name. This will be prefixed by a unique
|
|
113
54
|
* value once the file has finished saving. The file name must begin with
|
|
@@ -135,11 +76,10 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
135
76
|
* @param type {String} Optional Content-Type header to use for the file. If
|
|
136
77
|
* this is omitted, the content type will be inferred from the name's
|
|
137
78
|
* extension.
|
|
138
|
-
* @param metadata {
|
|
139
|
-
* @param tags {
|
|
79
|
+
* @param metadata {object} Optional key value pairs to be stored with file object
|
|
80
|
+
* @param tags {object} Optional key value pairs to be stored with file object
|
|
140
81
|
*/
|
|
141
|
-
|
|
142
|
-
(0, _classCallCheck2.default)(this, ParseFile);
|
|
82
|
+
constructor(name, data, type, metadata, tags) {
|
|
143
83
|
(0, _defineProperty2.default)(this, "_name", void 0);
|
|
144
84
|
(0, _defineProperty2.default)(this, "_url", void 0);
|
|
145
85
|
(0, _defineProperty2.default)(this, "_source", void 0);
|
|
@@ -148,7 +88,7 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
148
88
|
(0, _defineProperty2.default)(this, "_requestTask", void 0);
|
|
149
89
|
(0, _defineProperty2.default)(this, "_metadata", void 0);
|
|
150
90
|
(0, _defineProperty2.default)(this, "_tags", void 0);
|
|
151
|
-
|
|
91
|
+
const specifiedType = type || '';
|
|
152
92
|
this._name = name;
|
|
153
93
|
this._metadata = metadata || {};
|
|
154
94
|
this._tags = tags || {};
|
|
@@ -174,12 +114,12 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
174
114
|
};
|
|
175
115
|
} else if (data && typeof data.base64 === 'string') {
|
|
176
116
|
var _context, _context2, _context3;
|
|
177
|
-
|
|
178
|
-
|
|
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';
|
|
179
119
|
this._data = base64;
|
|
180
120
|
this._source = {
|
|
181
121
|
format: 'base64',
|
|
182
|
-
base64
|
|
122
|
+
base64,
|
|
183
123
|
type: dataType
|
|
184
124
|
};
|
|
185
125
|
} else {
|
|
@@ -195,396 +135,308 @@ var ParseFile = /*#__PURE__*/function () {
|
|
|
195
135
|
*
|
|
196
136
|
* @returns {Promise} Promise that is resolve with base64 data
|
|
197
137
|
*/
|
|
198
|
-
(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var _getData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
202
|
-
var _this = this;
|
|
203
|
-
var options, controller, result;
|
|
204
|
-
return _regenerator.default.wrap(function (_context4) {
|
|
205
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
206
|
-
case 0:
|
|
207
|
-
if (!this._data) {
|
|
208
|
-
_context4.next = 2;
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
return _context4.abrupt("return", this._data);
|
|
212
|
-
case 2:
|
|
213
|
-
if (this._url) {
|
|
214
|
-
_context4.next = 4;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
218
|
-
case 4:
|
|
219
|
-
options = {
|
|
220
|
-
requestTask: function (task) {
|
|
221
|
-
return _this._requestTask = task;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
controller = _CoreManager.default.getFileController();
|
|
225
|
-
_context4.next = 8;
|
|
226
|
-
return controller.download(this._url, options);
|
|
227
|
-
case 8:
|
|
228
|
-
result = _context4.sent;
|
|
229
|
-
this._data = result.base64;
|
|
230
|
-
return _context4.abrupt("return", this._data);
|
|
231
|
-
case 11:
|
|
232
|
-
case "end":
|
|
233
|
-
return _context4.stop();
|
|
234
|
-
}
|
|
235
|
-
}, _callee, this);
|
|
236
|
-
}));
|
|
237
|
-
function getData() {
|
|
238
|
-
return _getData.apply(this, arguments);
|
|
239
|
-
}
|
|
240
|
-
return getData;
|
|
241
|
-
}()
|
|
242
|
-
/**
|
|
243
|
-
* Gets the name of the file. Before save is called, this is the filename
|
|
244
|
-
* given by the user. After save is called, that name gets prefixed with a
|
|
245
|
-
* unique identifier.
|
|
246
|
-
*
|
|
247
|
-
* @returns {string}
|
|
248
|
-
*/
|
|
249
|
-
}, {
|
|
250
|
-
key: "name",
|
|
251
|
-
value: function () /*: string*/{
|
|
252
|
-
return this._name;
|
|
138
|
+
async getData() {
|
|
139
|
+
if (this._data) {
|
|
140
|
+
return this._data;
|
|
253
141
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
* Gets the url of the file. It is only available after you save the file or
|
|
257
|
-
* after you get the file from a Parse.Object.
|
|
258
|
-
*
|
|
259
|
-
* @param {object} options An object to specify url options
|
|
260
|
-
* @returns {string | undefined}
|
|
261
|
-
*/
|
|
262
|
-
}, {
|
|
263
|
-
key: "url",
|
|
264
|
-
value: function (options /*:: ?: { forceSecure?: boolean }*/) /*: ?string*/{
|
|
265
|
-
options = options || {};
|
|
266
|
-
if (!this._url) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (options.forceSecure) {
|
|
270
|
-
return this._url.replace(/^http:\/\//i, 'https://');
|
|
271
|
-
} else {
|
|
272
|
-
return this._url;
|
|
273
|
-
}
|
|
142
|
+
if (!this._url) {
|
|
143
|
+
throw new Error('Cannot retrieve data for unsaved ParseFile.');
|
|
274
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
|
+
}
|
|
275
152
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
+
}
|
|
286
163
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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;
|
|
296
176
|
}
|
|
177
|
+
if (options.forceSecure) {
|
|
178
|
+
return this._url.replace(/^http:\/\//i, 'https://');
|
|
179
|
+
} else {
|
|
180
|
+
return this._url;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
297
183
|
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
+
});
|
|
371
266
|
}
|
|
372
267
|
}
|
|
268
|
+
if (this._previousSave) {
|
|
269
|
+
return this._previousSave;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
373
272
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
this._requestTask._aborted = true;
|
|
382
|
-
this._requestTask.abort();
|
|
383
|
-
}
|
|
384
|
-
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();
|
|
385
280
|
}
|
|
281
|
+
this._requestTask = null;
|
|
282
|
+
}
|
|
386
283
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
var options /*:: ?: FullOptions*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
403
|
-
if (!this._name) {
|
|
404
|
-
throw new ParseError(ParseError.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
|
|
405
|
-
}
|
|
406
|
-
var destroyOptions = {
|
|
407
|
-
useMasterKey: true
|
|
408
|
-
};
|
|
409
|
-
if (options.hasOwnProperty('useMasterKey')) {
|
|
410
|
-
destroyOptions.useMasterKey = options.useMasterKey;
|
|
411
|
-
}
|
|
412
|
-
var controller = _CoreManager.default.getFileController();
|
|
413
|
-
return controller.deleteFile(this._name, destroyOptions).then(function () {
|
|
414
|
-
_this3._data = null;
|
|
415
|
-
_this3._requestTask = null;
|
|
416
|
-
return _this3;
|
|
417
|
-
});
|
|
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.');
|
|
418
299
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
name: this._name,
|
|
425
|
-
url: this._url
|
|
426
|
-
};
|
|
300
|
+
const destroyOptions = {
|
|
301
|
+
useMasterKey: true
|
|
302
|
+
};
|
|
303
|
+
if (options.hasOwnProperty('useMasterKey')) {
|
|
304
|
+
destroyOptions.useMasterKey = !!options.useMasterKey;
|
|
427
305
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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;
|
|
436
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
|
+
}
|
|
437
327
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
(0, _forEach.default)(_context5 = (0, _keys.default)(metadata)).call(_context5, function (key) {
|
|
450
|
-
_this4.addMetadata(key, metadata[key]);
|
|
451
|
-
});
|
|
452
|
-
}
|
|
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
|
+
});
|
|
453
339
|
}
|
|
340
|
+
}
|
|
454
341
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
key
|
|
463
|
-
|
|
464
|
-
if (typeof key === 'string') {
|
|
465
|
-
this._metadata[key] = value;
|
|
466
|
-
}
|
|
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;
|
|
467
351
|
}
|
|
352
|
+
}
|
|
468
353
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
(0, _forEach.default)(_context6 = (0, _keys.default)(tags)).call(_context6, function (key) {
|
|
481
|
-
_this5.addTag(key, tags[key]);
|
|
482
|
-
});
|
|
483
|
-
}
|
|
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
|
+
});
|
|
484
365
|
}
|
|
366
|
+
}
|
|
485
367
|
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
key
|
|
494
|
-
|
|
495
|
-
if (typeof key === 'string') {
|
|
496
|
-
this._tags[key] = value;
|
|
497
|
-
}
|
|
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;
|
|
498
377
|
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
throw new TypeError('JSON object does not represent a ParseFile');
|
|
504
|
-
}
|
|
505
|
-
var file = new ParseFile(obj.name);
|
|
506
|
-
file._url = obj.url;
|
|
507
|
-
return file;
|
|
378
|
+
}
|
|
379
|
+
static fromJSON(obj) {
|
|
380
|
+
if (obj.__type !== 'File') {
|
|
381
|
+
throw new TypeError('JSON object does not represent a ParseFile');
|
|
508
382
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
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('');
|
|
523
397
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
saveFile: function () {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
return _regenerator.default.wrap(function (_context7) {
|
|
532
|
-
while (1) switch (_context7.prev = _context7.next) {
|
|
533
|
-
case 0:
|
|
534
|
-
if (!(source.format !== 'file')) {
|
|
535
|
-
_context7.next = 2;
|
|
536
|
-
break;
|
|
537
|
-
}
|
|
538
|
-
throw new Error('saveFile can only be used with File-type sources.');
|
|
539
|
-
case 2:
|
|
540
|
-
_context7.next = 4;
|
|
541
|
-
return new _promise.default(function (res, rej) {
|
|
542
|
-
// eslint-disable-next-line no-undef
|
|
543
|
-
var reader = new FileReader();
|
|
544
|
-
reader.onload = function () {
|
|
545
|
-
return res(reader.result);
|
|
546
|
-
};
|
|
547
|
-
reader.onerror = function (error) {
|
|
548
|
-
return rej(error);
|
|
549
|
-
};
|
|
550
|
-
reader.readAsDataURL(source.file);
|
|
551
|
-
});
|
|
552
|
-
case 4:
|
|
553
|
-
base64Data = _context7.sent;
|
|
554
|
-
// we only want the data after the comma
|
|
555
|
-
// For example: "data:application/pdf;base64,JVBERi0xLjQKJ..." we would only want "JVBERi0xLjQKJ..."
|
|
556
|
-
_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
|
|
557
|
-
// use the entire string instead
|
|
558
|
-
data = second ? second : first;
|
|
559
|
-
newSource = {
|
|
560
|
-
format: 'base64',
|
|
561
|
-
base64: data,
|
|
562
|
-
type: source.type || (source.file ? source.file.type : null)
|
|
563
|
-
};
|
|
564
|
-
_context7.next = 10;
|
|
565
|
-
return DefaultController.saveBase64(name, newSource, options);
|
|
566
|
-
case 10:
|
|
567
|
-
return _context7.abrupt("return", _context7.sent);
|
|
568
|
-
case 11:
|
|
569
|
-
case "end":
|
|
570
|
-
return _context7.stop();
|
|
571
|
-
}
|
|
572
|
-
}, _callee2);
|
|
573
|
-
}));
|
|
574
|
-
function saveFile() {
|
|
575
|
-
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.');
|
|
576
405
|
}
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
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] : {};
|
|
580
428
|
if (source.format !== 'base64') {
|
|
581
429
|
throw new Error('saveBase64 can only be used with Base64-type sources.');
|
|
582
430
|
}
|
|
583
|
-
|
|
431
|
+
const data = {
|
|
584
432
|
base64: source.base64,
|
|
585
433
|
fileData: {
|
|
586
|
-
metadata:
|
|
587
|
-
|
|
434
|
+
metadata: {
|
|
435
|
+
...options.metadata
|
|
436
|
+
},
|
|
437
|
+
tags: {
|
|
438
|
+
...options.tags
|
|
439
|
+
}
|
|
588
440
|
}
|
|
589
441
|
};
|
|
590
442
|
delete options.metadata;
|
|
@@ -602,8 +454,8 @@ var DefaultController = {
|
|
|
602
454
|
}
|
|
603
455
|
},
|
|
604
456
|
downloadAjax: function (uri, options) {
|
|
605
|
-
return new _promise.default(
|
|
606
|
-
|
|
457
|
+
return new _promise.default((resolve, reject) => {
|
|
458
|
+
const xhr = new XHR();
|
|
607
459
|
xhr.open('GET', uri, true);
|
|
608
460
|
xhr.responseType = 'arraybuffer';
|
|
609
461
|
xhr.onerror = function (e) {
|
|
@@ -616,7 +468,7 @@ var DefaultController = {
|
|
|
616
468
|
if (!this.response) {
|
|
617
469
|
return resolve({});
|
|
618
470
|
}
|
|
619
|
-
|
|
471
|
+
const bytes = new Uint8Array(this.response);
|
|
620
472
|
resolve({
|
|
621
473
|
base64: ParseFile.encodeBase64(bytes),
|
|
622
474
|
contentType: xhr.getResponseHeader('content-type')
|
|
@@ -626,19 +478,19 @@ var DefaultController = {
|
|
|
626
478
|
xhr.send();
|
|
627
479
|
});
|
|
628
480
|
},
|
|
629
|
-
deleteFile: function (name
|
|
630
|
-
|
|
481
|
+
deleteFile: function (name, options) {
|
|
482
|
+
const headers = {
|
|
631
483
|
'X-Parse-Application-ID': _CoreManager.default.get('APPLICATION_ID')
|
|
632
484
|
};
|
|
633
485
|
if (options.useMasterKey) {
|
|
634
486
|
headers['X-Parse-Master-Key'] = _CoreManager.default.get('MASTER_KEY');
|
|
635
487
|
}
|
|
636
|
-
|
|
488
|
+
let url = _CoreManager.default.get('SERVER_URL');
|
|
637
489
|
if (url[url.length - 1] !== '/') {
|
|
638
490
|
url += '/';
|
|
639
491
|
}
|
|
640
492
|
url += 'files/' + name;
|
|
641
|
-
return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(
|
|
493
|
+
return _CoreManager.default.getRESTController().ajax('DELETE', url, '', headers).catch(response => {
|
|
642
494
|
// TODO: return JSON object in server
|
|
643
495
|
if (!response || response === 'SyntaxError: Unexpected end of JSON input') {
|
|
644
496
|
return _promise.default.resolve();
|
|
@@ -647,14 +499,13 @@ var DefaultController = {
|
|
|
647
499
|
}
|
|
648
500
|
});
|
|
649
501
|
},
|
|
650
|
-
_setXHR
|
|
502
|
+
_setXHR(xhr) {
|
|
651
503
|
XHR = xhr;
|
|
652
504
|
},
|
|
653
|
-
_getXHR
|
|
505
|
+
_getXHR() {
|
|
654
506
|
return XHR;
|
|
655
507
|
}
|
|
656
508
|
};
|
|
657
509
|
_CoreManager.default.setFileController(DefaultController);
|
|
658
|
-
var _default = ParseFile;
|
|
659
|
-
exports.default = _default;
|
|
510
|
+
var _default = exports.default = ParseFile;
|
|
660
511
|
exports.b64Digit = b64Digit;
|