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