@scaleflex/widget-core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7324 -0
- package/LICENSE +21 -0
- package/README.md +1089 -0
- package/dist/style.css +190 -0
- package/dist/style.min.css +1 -0
- package/lib/Client.js +390 -0
- package/lib/Plugin.js +298 -0
- package/lib/Providers.js +112 -0
- package/lib/SassKeyRenewer.js +332 -0
- package/lib/_common.scss +240 -0
- package/lib/_utils.scss +38 -0
- package/lib/_variables.scss +64 -0
- package/lib/createStore.js +45 -0
- package/lib/defaultLocale.js +66 -0
- package/lib/hooks/index.js +7 -0
- package/lib/hooks/useContextMenu.js +42 -0
- package/lib/hooks/useContextMenuData.js +17 -0
- package/lib/hooks/useCore.js +10 -0
- package/lib/hooks/useModal.js +72 -0
- package/lib/hooks/useModalData.js +7 -0
- package/lib/hooks/usePlugin.js +20 -0
- package/lib/hooks/usePluginsType.js +18 -0
- package/lib/index.js +1918 -0
- package/lib/loggers.js +45 -0
- package/lib/slices/common.slice.js +90 -0
- package/lib/slices/index.js +12 -0
- package/lib/slices/info.slice.js +52 -0
- package/lib/slices/uploads.slice.js +294 -0
- package/lib/slices/user.slice.js +256 -0
- package/lib/style.scss +3 -0
- package/lib/supportsUploadProgress.js +42 -0
- package/lib/utils/calculateTotalEta.js +21 -0
- package/package.json +38 -0
- package/types/index.d.ts +301 -0
package/lib/loggers.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
|
|
2
|
+
import getTimeStamp from '@scaleflex/widget-utils/lib/getTimeStamp';
|
|
3
|
+
|
|
4
|
+
// Swallow all logs, except errors.
|
|
5
|
+
// default if logger is not set or debug: false
|
|
6
|
+
var justErrorsLogger = {
|
|
7
|
+
debug: function debug() {},
|
|
8
|
+
warn: function warn() {},
|
|
9
|
+
error: function error() {
|
|
10
|
+
var _console;
|
|
11
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
12
|
+
args[_key] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
return (_console = console).error.apply(_console, ["[Filerobot] [".concat(getTimeStamp(), "]")].concat(args));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Print logs to console with namespace + timestamp,
|
|
19
|
+
// set by logger: Filerobot.debugLogger or debug: true
|
|
20
|
+
var debugLogger = {
|
|
21
|
+
debug: function debug() {
|
|
22
|
+
var _debug;
|
|
23
|
+
// IE 10 doesn’t support console.debug
|
|
24
|
+
var debug = console.debug || console.log;
|
|
25
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
26
|
+
args[_key2] = arguments[_key2];
|
|
27
|
+
}
|
|
28
|
+
(_debug = debug).call.apply(_debug, [console, "[Filerobot] [".concat(getTimeStamp(), "]")].concat(args));
|
|
29
|
+
},
|
|
30
|
+
warn: function warn() {
|
|
31
|
+
var _console2;
|
|
32
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
33
|
+
args[_key3] = arguments[_key3];
|
|
34
|
+
}
|
|
35
|
+
return (_console2 = console).warn.apply(_console2, ["[Filerobot] [".concat(getTimeStamp(), "]")].concat(args));
|
|
36
|
+
},
|
|
37
|
+
error: function error() {
|
|
38
|
+
var _console3;
|
|
39
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
40
|
+
args[_key4] = arguments[_key4];
|
|
41
|
+
}
|
|
42
|
+
return (_console3 = console).error.apply(_console3, ["[Filerobot] [".concat(getTimeStamp(), "]")].concat(args));
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export { justErrorsLogger, debugLogger };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
8
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
9
|
+
import getActionErrorState from '@scaleflex/widget-utils/lib/getActionErrorState';
|
|
10
|
+
import { fetchUserAuthState, generateUserKey } from './user.slice';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The order of the code in slice file is:
|
|
14
|
+
* 1. initialState (*No* export needed)
|
|
15
|
+
* 2. automated thunks functions -- uses createThunk API-- (export needed)
|
|
16
|
+
* 3. createSlice (*No* export needed)
|
|
17
|
+
* 4. actions exports
|
|
18
|
+
* 5. selectors (export needed)
|
|
19
|
+
* 6. default reducer export
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export var slicePropName = 'common';
|
|
23
|
+
var sliceName = "".concat(PLUGINS_IDS.CORE, "/").concat(slicePropName);
|
|
24
|
+
var initialState = {
|
|
25
|
+
loading: true,
|
|
26
|
+
companion: {},
|
|
27
|
+
xhrUpload: {},
|
|
28
|
+
imageProcessor: {},
|
|
29
|
+
videoTranscoding: {},
|
|
30
|
+
fromDragging: false,
|
|
31
|
+
dndTargetFolderPath: '',
|
|
32
|
+
isDragging: false,
|
|
33
|
+
isRelevanceAvailable: false,
|
|
34
|
+
isDevEnv: false // retrieved from opts.dev
|
|
35
|
+
// isRelevanceAvailable: localStorage.getItem('show-relevance') === 'true' (needed in explorer only)
|
|
36
|
+
};
|
|
37
|
+
var commonSlice = createSlice({
|
|
38
|
+
name: sliceName,
|
|
39
|
+
initialState: initialState,
|
|
40
|
+
reducers: {
|
|
41
|
+
loadingSet: function loadingSet(state, action) {
|
|
42
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
43
|
+
loading: action.payload
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
coreCommonStateUpdated: function coreCommonStateUpdated(state, action) {
|
|
47
|
+
return _objectSpread(_objectSpread({}, state), action.payload);
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
extraReducers: function extraReducers(builder) {
|
|
51
|
+
builder
|
|
52
|
+
// We don't need to add extraReducer for .pending case, as by default the app starts in loading: true state,
|
|
53
|
+
// User might hit the refreshment of sass key generation before getting expired, so we don't need to set loading to true
|
|
54
|
+
// to avoid bothering the user, it's better to done in the background.
|
|
55
|
+
.addMatcher(function (_ref) {
|
|
56
|
+
var type = _ref.type;
|
|
57
|
+
return [generateUserKey.fulfilled.type, fetchUserAuthState.fulfilled.type].includes(type);
|
|
58
|
+
}, function (state, action) {
|
|
59
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
60
|
+
loading: false
|
|
61
|
+
});
|
|
62
|
+
}).addMatcher(function (_ref2) {
|
|
63
|
+
var type = _ref2.type;
|
|
64
|
+
return [generateUserKey.rejected.type, fetchUserAuthState.rejected.type].includes(type);
|
|
65
|
+
}, function (state, action) {
|
|
66
|
+
return getActionErrorState(state, action);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
var _commonSlice$actions = commonSlice.actions,
|
|
71
|
+
loadingSet = _commonSlice$actions.loadingSet,
|
|
72
|
+
coreCommonStateUpdated = _commonSlice$actions.coreCommonStateUpdated;
|
|
73
|
+
export { loadingSet, coreCommonStateUpdated };
|
|
74
|
+
export var selectCommonState = function selectCommonState(state) {
|
|
75
|
+
return state[PLUGINS_IDS.CORE][slicePropName];
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// !TODO: This is not appropriate as it will be undefined in-case explorer isn't there, so maybe better to remove it.
|
|
79
|
+
// Local selector "selectCurrentFolderPath" was created because of the error "failed to initialize ..." if we try to import via @filerobot..../slice.. inside core/src/index.js
|
|
80
|
+
export var selectCurrentFolderPath = function selectCurrentFolderPath(state) {
|
|
81
|
+
var _state$PLUGINS_IDS$EX, _state$PLUGINS_IDS$EX2, _state$PLUGINS_IDS$EX3, _state$PLUGINS_IDS$EX4, _state$PLUGINS_IDS$EX5;
|
|
82
|
+
return ((_state$PLUGINS_IDS$EX = state[PLUGINS_IDS.EXPLORER]) === null || _state$PLUGINS_IDS$EX === void 0 ? void 0 : (_state$PLUGINS_IDS$EX2 = _state$PLUGINS_IDS$EX.folders) === null || _state$PLUGINS_IDS$EX2 === void 0 ? void 0 : (_state$PLUGINS_IDS$EX3 = _state$PLUGINS_IDS$EX2.currentFolder) === null || _state$PLUGINS_IDS$EX3 === void 0 ? void 0 : _state$PLUGINS_IDS$EX3.path) || ((_state$PLUGINS_IDS$EX4 = state[PLUGINS_IDS.EXPLORER]) === null || _state$PLUGINS_IDS$EX4 === void 0 ? void 0 : (_state$PLUGINS_IDS$EX5 = _state$PLUGINS_IDS$EX4.folders) === null || _state$PLUGINS_IDS$EX5 === void 0 ? void 0 : _state$PLUGINS_IDS$EX5.baseFolderPath);
|
|
83
|
+
};
|
|
84
|
+
export var selectCoreLoading = function selectCoreLoading(state) {
|
|
85
|
+
return selectCommonState(state).loading;
|
|
86
|
+
};
|
|
87
|
+
export var selectIsRelevanceAvailable = function selectIsRelevanceAvailable(state) {
|
|
88
|
+
return selectCommonState(state).isRelevanceAvailable;
|
|
89
|
+
};
|
|
90
|
+
export default commonSlice.reducer;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { combineReducers } from '@reduxjs/toolkit';
|
|
2
|
+
import common from './common.slice';
|
|
3
|
+
import uploads from './uploads.slice';
|
|
4
|
+
import info from './info.slice';
|
|
5
|
+
import user from './user.slice';
|
|
6
|
+
var coreReducer = combineReducers({
|
|
7
|
+
common: common,
|
|
8
|
+
uploads: uploads,
|
|
9
|
+
info: info,
|
|
10
|
+
user: user
|
|
11
|
+
});
|
|
12
|
+
export default coreReducer;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { createSlice } from '@reduxjs/toolkit';
|
|
8
|
+
import { PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The order of the code in slice file is:
|
|
12
|
+
* 1. initialState (*No* export needed)
|
|
13
|
+
* 2. automated thunks functions -- uses createThunk API-- (export needed)
|
|
14
|
+
* 3. createSlice (*No* export needed)
|
|
15
|
+
* 4. actions exports
|
|
16
|
+
* 5. selectors (export needed)
|
|
17
|
+
|
|
18
|
+
* 7. default reducer export
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var slicePropName = 'info';
|
|
22
|
+
var sliceName = "".concat(PLUGINS_IDS.CORE, "/").concat(slicePropName);
|
|
23
|
+
var initialState = {
|
|
24
|
+
isHidden: true,
|
|
25
|
+
type: 'info',
|
|
26
|
+
message: '',
|
|
27
|
+
details: ''
|
|
28
|
+
};
|
|
29
|
+
var infoSlice = createSlice({
|
|
30
|
+
name: sliceName,
|
|
31
|
+
initialState: initialState,
|
|
32
|
+
reducers: {
|
|
33
|
+
infoSet: function infoSet(state, action) {
|
|
34
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
35
|
+
isHidden: false
|
|
36
|
+
}, action.payload);
|
|
37
|
+
},
|
|
38
|
+
infoHid: function infoHid(state) {
|
|
39
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
40
|
+
isHidden: true
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
var _infoSlice$actions = infoSlice.actions,
|
|
46
|
+
infoSet = _infoSlice$actions.infoSet,
|
|
47
|
+
infoHid = _infoSlice$actions.infoHid;
|
|
48
|
+
export { infoSet, infoHid };
|
|
49
|
+
export var selectInfo = function selectInfo(state) {
|
|
50
|
+
return state[PLUGINS_IDS.CORE][slicePropName];
|
|
51
|
+
};
|
|
52
|
+
export default infoSlice.reducer;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
5
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
6
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
7
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
import { createSelector, createSlice } from '@reduxjs/toolkit';
|
|
14
|
+
import { UPLOAD_CONNECTOR_SERVER, PLUGINS_IDS } from '@scaleflex/widget-utils/lib/constants';
|
|
15
|
+
import deepMerge from '@scaleflex/widget-utils/lib/deepMerge';
|
|
16
|
+
import createThunk from '@scaleflex/widget-utils/lib/createThunk';
|
|
17
|
+
import supportsUploadProgress from '../supportsUploadProgress';
|
|
18
|
+
import { Filerobot } from '../';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The order of the code in slice file is:
|
|
22
|
+
* 1. initialState (*No* export needed)
|
|
23
|
+
* 2. automated thunks functions -- uses createThunk API-- (export needed)
|
|
24
|
+
* 3. createSlice (*No* export needed)
|
|
25
|
+
* 4. actions exports
|
|
26
|
+
* 5. selectors (export needed)
|
|
27
|
+
* 6. default reducer export
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
var slicePropName = 'uploads';
|
|
31
|
+
var sliceName = "".concat(PLUGINS_IDS.CORE, "/").concat(slicePropName);
|
|
32
|
+
var initialState = {
|
|
33
|
+
ids: [],
|
|
34
|
+
files: {},
|
|
35
|
+
capabilities: {
|
|
36
|
+
allowUploadProgress: supportsUploadProgress(),
|
|
37
|
+
allowIndividualCancellation: true,
|
|
38
|
+
allowResumableUploads: false,
|
|
39
|
+
allowNewUpload: true,
|
|
40
|
+
allowMultipleUploads: true
|
|
41
|
+
},
|
|
42
|
+
error: null
|
|
43
|
+
};
|
|
44
|
+
export var updateUploadInfoMetaTags = createThunk(function (_ref, thunkApi) {
|
|
45
|
+
var filesIds = _ref.filesIds,
|
|
46
|
+
meta = _ref.meta,
|
|
47
|
+
tags = _ref.tags,
|
|
48
|
+
info = _ref.info,
|
|
49
|
+
tagsForceUpdate = _ref.tagsForceUpdate,
|
|
50
|
+
deepMergeMeta = _ref.deepMergeMeta,
|
|
51
|
+
removeMeta = _ref.removeMeta;
|
|
52
|
+
var updatedFiles = _objectSpread({}, selectUploads(thunkApi.getState()));
|
|
53
|
+
filesIds.forEach(function (fileId) {
|
|
54
|
+
var newFile = _objectSpread({}, updatedFiles[fileId]);
|
|
55
|
+
if (info) {
|
|
56
|
+
newFile.info = _objectSpread(_objectSpread({}, newFile.info), info);
|
|
57
|
+
if (info !== null && info !== void 0 && info.name) {
|
|
58
|
+
newFile.name = info.name;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (meta) {
|
|
62
|
+
if (deepMergeMeta) {
|
|
63
|
+
newFile.meta = deepMerge(newFile.meta, meta, {
|
|
64
|
+
considerArray: true,
|
|
65
|
+
removeFromArray: removeMeta,
|
|
66
|
+
dismissArrayIfSourceNotArray: removeMeta
|
|
67
|
+
});
|
|
68
|
+
} else {
|
|
69
|
+
newFile.meta = _objectSpread(_objectSpread({}, newFile.meta), meta);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (tags) {
|
|
73
|
+
newFile.tags = tagsForceUpdate ? tags : deepMerge(newFile.tags, tags, {
|
|
74
|
+
considerArray: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
updatedFiles[fileId] = newFile;
|
|
78
|
+
});
|
|
79
|
+
thunkApi.dispatch(uploadsReplaced(updatedFiles));
|
|
80
|
+
return updatedFiles;
|
|
81
|
+
});
|
|
82
|
+
export var getResumableUploadFastestServer = createThunk(async function (_, thunkApi) {
|
|
83
|
+
var adminApiEndpoint = thunkApi.extra.filerobot.opts.adminApiEndpoint;
|
|
84
|
+
var apiUrl = "".concat(adminApiEndpoint, "/constants/uploaders.connectors.endpoints/items");
|
|
85
|
+
var fetchEndpoints = async function fetchEndpoints() {
|
|
86
|
+
var response = await fetch(apiUrl);
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
throw new Error('Failed to fetch connector endpoints.');
|
|
89
|
+
}
|
|
90
|
+
return response.json();
|
|
91
|
+
};
|
|
92
|
+
var pingServer = async function pingServer(serverUrl) {
|
|
93
|
+
var responseTimes = await Promise.all(_toConsumableArray(new Array(3)).map(async function () {
|
|
94
|
+
var startTime = performance.now();
|
|
95
|
+
try {
|
|
96
|
+
var response = await fetch("https://".concat(serverUrl, "/ping"));
|
|
97
|
+
if (!response.ok) throw new Error('Ping failed');
|
|
98
|
+
var endTime = performance.now();
|
|
99
|
+
return endTime - startTime;
|
|
100
|
+
} catch (_unused) {
|
|
101
|
+
return null; // null means the ping failed
|
|
102
|
+
}
|
|
103
|
+
}));
|
|
104
|
+
return {
|
|
105
|
+
serverUrl: serverUrl,
|
|
106
|
+
responseTimes: responseTimes
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
// Fetch the list of connector servers
|
|
111
|
+
var servers = await fetchEndpoints();
|
|
112
|
+
|
|
113
|
+
// Ping each server asynchronously
|
|
114
|
+
var pingResults = await Promise.all(servers === null || servers === void 0 ? void 0 : servers.items.map(pingServer));
|
|
115
|
+
|
|
116
|
+
// Filter servers with 100% successful responses
|
|
117
|
+
var successfulPings = pingResults.filter(function (_ref2) {
|
|
118
|
+
var responseTimes = _ref2.responseTimes;
|
|
119
|
+
return responseTimes.every(function (time) {
|
|
120
|
+
return time !== null;
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
if (successfulPings.length === 0) {
|
|
124
|
+
throw new Error('No servers with 100% successful ping responses.');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Calculate average ping times
|
|
128
|
+
var serversAverages = successfulPings.map(function (_ref3) {
|
|
129
|
+
var serverUrl = _ref3.serverUrl,
|
|
130
|
+
responseTimes = _ref3.responseTimes;
|
|
131
|
+
var validPings = responseTimes.slice(1); // Ignore the first ping
|
|
132
|
+
var pingsAvgTime = validPings.reduce(function (totalPingsTime, pingTime) {
|
|
133
|
+
return totalPingsTime + pingTime;
|
|
134
|
+
}, 0) / validPings.length;
|
|
135
|
+
return {
|
|
136
|
+
serverUrl: serverUrl,
|
|
137
|
+
pingsAvgTime: pingsAvgTime
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Find the server with the lowest average time
|
|
142
|
+
var closestServer = serversAverages.reduce(function (fastestServer, currentServer) {
|
|
143
|
+
return currentServer.pingsAvgTime < fastestServer.pingsAvgTime ? currentServer : fastestServer;
|
|
144
|
+
});
|
|
145
|
+
sessionStorage.setItem(UPLOAD_CONNECTOR_SERVER, "https://".concat(closestServer.serverUrl));
|
|
146
|
+
return "https://".concat(closestServer.serverUrl);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
// Retry logic
|
|
149
|
+
var retryCount = 0;
|
|
150
|
+
var MAX_RETRIES = 1;
|
|
151
|
+
if (error.message.includes('No servers') && retryCount < MAX_RETRIES) {
|
|
152
|
+
retryCount++;
|
|
153
|
+
try {
|
|
154
|
+
return await getResumableUploadFastestServer();
|
|
155
|
+
} catch (retryError) {
|
|
156
|
+
thunkApi.extra.filerobot.info(thunkApi.extra.filerobot.i18n('explorerResumableUploadFastestServerError'), 'error');
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
var uploadsSlice = createSlice({
|
|
164
|
+
name: sliceName,
|
|
165
|
+
initialState: initialState,
|
|
166
|
+
reducers: {
|
|
167
|
+
uploadsAdded: function uploadsAdded(state, action) {
|
|
168
|
+
var addedFiles = action.payload.files || action.payload;
|
|
169
|
+
var newFiles = addedFiles.reduce(function (filesByIds, file) {
|
|
170
|
+
return _objectSpread(_objectSpread({}, filesByIds), {}, _defineProperty({}, file.id, file));
|
|
171
|
+
}, {});
|
|
172
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
173
|
+
ids: _toConsumableArray(new Set([].concat(_toConsumableArray(state.ids), _toConsumableArray(Object.keys(newFiles))))),
|
|
174
|
+
files: _objectSpread(_objectSpread({}, state.files), newFiles)
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
uploadsReplaced: function uploadsReplaced(state, action) {
|
|
178
|
+
var files = action.payload;
|
|
179
|
+
var newFiles = Array.isArray(files) ? files.reduce(function (filesByIds, file) {
|
|
180
|
+
return _objectSpread(_objectSpread({}, filesByIds), {}, _defineProperty({}, file.id, file));
|
|
181
|
+
}, {}) : files;
|
|
182
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
183
|
+
ids: Object.keys(newFiles),
|
|
184
|
+
files: newFiles
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
uploadsRemoved: function uploadsRemoved(state, action) {
|
|
188
|
+
// If no payload is provided with the filesIds to be removed, then all the files will get removed.
|
|
189
|
+
var removedFilesIds = action.payload || [];
|
|
190
|
+
var shouldRemoveAllFiles = removedFilesIds.length === 0;
|
|
191
|
+
var updatedFiles = shouldRemoveAllFiles ? {} : _objectSpread({}, state.files);
|
|
192
|
+
var updatedIds = shouldRemoveAllFiles ? [] : state.ids;
|
|
193
|
+
removedFilesIds.forEach(function (fileId) {
|
|
194
|
+
updatedIds = updatedIds.filter(function (id) {
|
|
195
|
+
return id !== fileId;
|
|
196
|
+
});
|
|
197
|
+
delete updatedFiles[fileId];
|
|
198
|
+
});
|
|
199
|
+
var isAllUploadsRemoved = Object.keys(updatedFiles).length === 0;
|
|
200
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
201
|
+
ids: updatedIds,
|
|
202
|
+
files: updatedFiles,
|
|
203
|
+
capabilities: _objectSpread(_objectSpread({}, state.capabilities), {}, {
|
|
204
|
+
allowNewUpload: isAllUploadsRemoved || state.capabilities.allowNewUpload
|
|
205
|
+
})
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
uploadUpdated: function uploadUpdated(state, action) {
|
|
209
|
+
var fileId = action.payload.id;
|
|
210
|
+
var updatedFiles = _objectSpread({}, state.files);
|
|
211
|
+
updatedFiles[fileId] = _objectSpread(_objectSpread({}, state.files[fileId]), action.payload);
|
|
212
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
213
|
+
files: updatedFiles
|
|
214
|
+
});
|
|
215
|
+
},
|
|
216
|
+
allUploadsCancelled: function allUploadsCancelled(state, action) {
|
|
217
|
+
var _ref4 = action.payload || {},
|
|
218
|
+
_ref4$capabilities = _ref4.capabilities,
|
|
219
|
+
capabilities = _ref4$capabilities === void 0 ? {} : _ref4$capabilities;
|
|
220
|
+
return _objectSpread(_objectSpread({}, initialState), {}, {
|
|
221
|
+
capabilities: _objectSpread(_objectSpread({}, state.capabilities), capabilities)
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
allUploadsRemoved: function allUploadsRemoved(state) {
|
|
225
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
226
|
+
ids: [],
|
|
227
|
+
files: {}
|
|
228
|
+
});
|
|
229
|
+
},
|
|
230
|
+
uploadCapabilitiesUpdated: function uploadCapabilitiesUpdated(state, action) {
|
|
231
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
232
|
+
capabilities: _objectSpread(_objectSpread({}, state.capabilities), action.payload)
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
var _uploadsSlice$actions = uploadsSlice.actions,
|
|
238
|
+
uploadsAdded = _uploadsSlice$actions.uploadsAdded,
|
|
239
|
+
uploadsReplaced = _uploadsSlice$actions.uploadsReplaced,
|
|
240
|
+
uploadsRemoved = _uploadsSlice$actions.uploadsRemoved,
|
|
241
|
+
uploadUpdated = _uploadsSlice$actions.uploadUpdated,
|
|
242
|
+
allUploadsRemoved = _uploadsSlice$actions.allUploadsRemoved,
|
|
243
|
+
allUploadsCancelled = _uploadsSlice$actions.allUploadsCancelled,
|
|
244
|
+
uploadCapabilitiesUpdated = _uploadsSlice$actions.uploadCapabilitiesUpdated;
|
|
245
|
+
export { uploadsAdded, uploadsReplaced, uploadsRemoved, uploadUpdated, allUploadsRemoved, allUploadsCancelled, uploadCapabilitiesUpdated };
|
|
246
|
+
export var selectUploadsState = function selectUploadsState(state) {
|
|
247
|
+
return state[PLUGINS_IDS.CORE][slicePropName];
|
|
248
|
+
};
|
|
249
|
+
export var selectUploadCapabilities = function selectUploadCapabilities(state, property) {
|
|
250
|
+
return property ? selectUploadsState(state).capabilities[property] : selectUploadsState(state).capabilities;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// Note: this selector doesn't contain the data [File/Blob instance] in the property for avoiding always rerendering in case of state changing.
|
|
254
|
+
export var selectUploads = function selectUploads(state) {
|
|
255
|
+
return selectUploadsState(state).files;
|
|
256
|
+
};
|
|
257
|
+
export var selectUploadsIds = function selectUploadsIds(state) {
|
|
258
|
+
return selectUploadsState(state).ids;
|
|
259
|
+
};
|
|
260
|
+
export var selectUploadsArray = createSelector(selectUploads, function (files) {
|
|
261
|
+
return Object.keys(files).map(function (fileId) {
|
|
262
|
+
return files[fileId] ? _objectSpread(_objectSpread({}, files[fileId]), {}, {
|
|
263
|
+
data: Filerobot.uploadFilesData[fileId]
|
|
264
|
+
}) : undefined;
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
export var selectUploadById = createSelector([selectUploads, function (_state, fileId) {
|
|
268
|
+
return fileId;
|
|
269
|
+
}], function (files, fileId) {
|
|
270
|
+
return files[fileId] ? _objectSpread(_objectSpread({}, files[fileId]), {}, {
|
|
271
|
+
data: Filerobot.uploadFilesData[fileId]
|
|
272
|
+
}) : undefined;
|
|
273
|
+
});
|
|
274
|
+
export var selectUploadsByIds = createSelector([selectUploads, function (_state, filesIds) {
|
|
275
|
+
return filesIds;
|
|
276
|
+
}], function (files, filesIds) {
|
|
277
|
+
return filesIds.map(function (fileId) {
|
|
278
|
+
return files[fileId] ? _objectSpread(_objectSpread({}, files[fileId]), {}, {
|
|
279
|
+
data: Filerobot.uploadFilesData[fileId]
|
|
280
|
+
}) : undefined;
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
export var selectUploadsCount = function selectUploadsCount(state) {
|
|
284
|
+
return Object.keys(selectUploads(state)).length;
|
|
285
|
+
};
|
|
286
|
+
export var selectIsNewUploadAllowed = function selectIsNewUploadAllowed(state, maxNumberOfFiles) {
|
|
287
|
+
if (!maxNumberOfFiles) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
var files = selectUploadsArray(state);
|
|
291
|
+
var allowNewUploadByDefault = selectUploadCapabilities(state, 'allowNewUpload');
|
|
292
|
+
return allowNewUploadByDefault && files.length < maxNumberOfFiles;
|
|
293
|
+
};
|
|
294
|
+
export default uploadsSlice.reducer;
|