@abtnode/ux 1.15.17 → 1.16.0-beta-b16cb035
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/lib/actions.js +111 -0
- package/lib/blocklet/access/config-access.js +303 -0
- package/lib/blocklet/access/index.js +221 -0
- package/lib/blocklet/actions.js +438 -0
- package/lib/blocklet/add-cert.js +191 -0
- package/lib/blocklet/agreement-app.js +30 -0
- package/lib/blocklet/agreement.js +72 -0
- package/lib/blocklet/app-avatar.js +74 -0
- package/lib/blocklet/audit-logs.js +197 -0
- package/lib/blocklet/blocklet-source.js +56 -0
- package/lib/blocklet/bundle-avatar.js +80 -0
- package/lib/blocklet/component/add.js +1063 -0
- package/lib/blocklet/component/configuration.js +124 -0
- package/lib/blocklet/component/delete.js +117 -0
- package/lib/blocklet/component/environment.js +289 -0
- package/lib/blocklet/component/expiration.js +53 -0
- package/lib/blocklet/component/index.js +804 -0
- package/lib/blocklet/component/line.js +28 -0
- package/lib/blocklet/component/navigation/locale-tabs.js +218 -0
- package/lib/blocklet/component/navigation/navigation-actions.js +120 -0
- package/lib/blocklet/component/navigation/navigation-dialog.js +620 -0
- package/lib/blocklet/component/navigation/navigation-preview.js +102 -0
- package/lib/blocklet/component/navigation/simple-select.js +131 -0
- package/lib/blocklet/component/select-store.js +153 -0
- package/lib/blocklet/component/setting.js +151 -0
- package/lib/blocklet/component/sortable-tree.js +138 -0
- package/lib/blocklet/component/space-gateway-selector.js +174 -0
- package/lib/blocklet/component/store-blocklet-list.js +205 -0
- package/lib/blocklet/config-navigation.js +344 -0
- package/lib/blocklet/configuration.js +574 -0
- package/lib/blocklet/disk-info.js +91 -0
- package/lib/blocklet/icons.js +26 -0
- package/lib/blocklet/install-from-url.js +347 -0
- package/lib/blocklet/log.js +62 -0
- package/lib/blocklet/migration.js +153 -0
- package/lib/blocklet/mode.js +35 -0
- package/lib/blocklet/monitor.js +186 -0
- package/lib/blocklet/overview.js +236 -0
- package/lib/blocklet/preferences/app-sk.js +131 -0
- package/lib/blocklet/preferences/index.js +238 -0
- package/lib/blocklet/preferences/wallet-type.js +107 -0
- package/lib/blocklet/purchase/common.js +103 -0
- package/lib/blocklet/purchase/component-purchase.js +253 -0
- package/lib/blocklet/purchase/index.js +13 -0
- package/lib/blocklet/router/action/add-domain-alias.js +173 -0
- package/lib/blocklet/router/action/add-rule.js +204 -0
- package/lib/blocklet/router/action/config-routing-rule.js +129 -0
- package/lib/blocklet/router/action/delete-domain-alias.js +107 -0
- package/lib/blocklet/router/action/delete-rule.js +114 -0
- package/lib/blocklet/router/action/update-rule.js +203 -0
- package/lib/blocklet/router/domain-actions.js +71 -0
- package/lib/blocklet/router/domain-status.js +96 -0
- package/lib/blocklet/router/rule-actions.js +77 -0
- package/lib/blocklet/router/rule-list.js +181 -0
- package/lib/blocklet/router/util.js +146 -0
- package/lib/blocklet/runtime-info.js +87 -0
- package/lib/blocklet/status.js +105 -0
- package/lib/blocklet/storage.js +322 -0
- package/lib/blocklet/types.js +25 -0
- package/lib/blocklet/util.js +213 -0
- package/lib/blocklet/version.js +156 -0
- package/lib/card-selector.js +109 -0
- package/lib/certificate.js +110 -0
- package/lib/click-to-copy.js +38 -0
- package/lib/confirm.js +149 -0
- package/lib/contexts/audit-log.js +141 -0
- package/lib/contexts/blocklet.js +19 -0
- package/lib/contexts/deleting-blocklets.js +78 -0
- package/lib/contexts/node.js +30 -0
- package/lib/contexts/session.js +20 -0
- package/lib/contexts/team.js +19 -0
- package/lib/delete-confirm.js +127 -0
- package/lib/did-address.js +77 -0
- package/lib/dot.js +18 -0
- package/lib/form/form-text-input.js +266 -0
- package/lib/form/form-wrapper.js +13 -0
- package/lib/form/required.js +13 -0
- package/lib/hooks/blocklet.js +231 -0
- package/lib/hooks/mobile-width.js +19 -0
- package/lib/hooks/url-evaluation.js +168 -0
- package/lib/hooks/use-app-logo.js +25 -0
- package/lib/hooks/use-bundle-logo.js +36 -0
- package/lib/hooks/use-navigation.js +355 -0
- package/lib/hooks/use-passport-id.js +21 -0
- package/lib/hooks/use-subscription.js +28 -0
- package/lib/icons/long-arrow.svg +5 -0
- package/lib/index.js +0 -3
- package/lib/invitation/invitation-app.js +51 -0
- package/lib/invitation/invitation-login.js +47 -0
- package/lib/invitation/invitation-passport.js +130 -0
- package/lib/invitation/invitation-receive.js +108 -0
- package/lib/invitation/invitation-success.js +82 -0
- package/lib/invitation/invitation-user.js +79 -0
- package/lib/invitation/invitation.js +80 -0
- package/lib/issue-passport.js +84 -84
- package/lib/launch-blocklet/content-layout.js +33 -0
- package/lib/launch-blocklet/page-header.js +38 -0
- package/lib/layout/addon.js +100 -0
- package/lib/layout/feedback.js +55 -0
- package/lib/locales/en.js +1221 -10
- package/lib/locales/index.js +3 -4
- package/lib/locales/zh.js +1232 -15
- package/lib/logs/clock.js +19 -0
- package/lib/logs/download.js +139 -0
- package/lib/logs/log-terminal.js +183 -0
- package/lib/lost-passport.js +191 -195
- package/lib/monitor/card.js +73 -0
- package/lib/monitor/cpu.js +109 -0
- package/lib/monitor/disk.js +122 -0
- package/lib/monitor/memory.js +144 -0
- package/lib/nav-logo.js +120 -0
- package/lib/passport-tag.js +43 -0
- package/lib/permission.js +70 -0
- package/lib/relative-time.js +61 -0
- package/lib/schema-form/color-input.js +105 -0
- package/lib/schema-form/common-prop-types.js +21 -0
- package/lib/schema-form/index.js +229 -0
- package/lib/schema-form/passport-input.js +66 -0
- package/lib/schema-form/text-input.js +72 -0
- package/lib/store/add.js +185 -0
- package/lib/store/delete.js +102 -0
- package/lib/store/item.js +84 -0
- package/lib/table-icons.js +42 -0
- package/lib/table.js +13 -0
- package/lib/tag.js +37 -0
- package/lib/team/members/actions.js +99 -0
- package/lib/team/members/index.js +503 -0
- package/lib/team/members/invitations.js +196 -0
- package/lib/team/members/invite-member.js +212 -0
- package/lib/team/members/issue-passport.js +155 -0
- package/lib/team/members/member.js +300 -0
- package/lib/team/members/passport-issuances.js +154 -0
- package/lib/team/members/passports.js +336 -0
- package/lib/team/members/toggle-user-approval.js +128 -0
- package/lib/team/members/transfer-node.js +262 -0
- package/lib/team/members/util.js +20 -0
- package/lib/team/passports/color.js +132 -0
- package/lib/team/passports/detail.js +271 -0
- package/lib/team/passports/index.js +233 -0
- package/lib/team/passports/mutate-role.js +204 -0
- package/lib/team/passports/trusted-issuer.js +297 -0
- package/lib/team/passports/trusted-issuers.js +240 -0
- package/lib/team/search-input.js +38 -0
- package/lib/team/styles/dialog.js +13 -0
- package/lib/team/styles/list-header.js +13 -0
- package/lib/toast.js +86 -0
- package/lib/util/api.js +21 -0
- package/lib/util/constants.js +10 -0
- package/lib/util/index.js +703 -0
- package/lib/util/locales.js +28 -0
- package/lib/util/mode.js +11 -0
- package/lib/who-can-access/config.js +46 -0
- package/lib/wrap-locale.js +12 -13
- package/package.json +69 -17
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = BlockletStatus;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
|
|
10
|
+
var _Tooltip = _interopRequireDefault(require("@mui/material/Tooltip"));
|
|
11
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
12
|
+
var _dot = _interopRequireDefault(require("../dot"));
|
|
13
|
+
var _tag = _interopRequireDefault(require("../tag"));
|
|
14
|
+
var _util = require("../util");
|
|
15
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
16
|
+
const _excluded = ["status", "variant", "source"];
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
22
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
23
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
24
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
25
|
+
const colors = {
|
|
26
|
+
yellow: '#FFCF71',
|
|
27
|
+
grey: '#888888'
|
|
28
|
+
};
|
|
29
|
+
function BlockletStatus(_ref) {
|
|
30
|
+
let {
|
|
31
|
+
status,
|
|
32
|
+
variant,
|
|
33
|
+
source
|
|
34
|
+
} = _ref,
|
|
35
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
36
|
+
const {
|
|
37
|
+
t
|
|
38
|
+
} = (0, _react.useContext)(_context.LocaleContext);
|
|
39
|
+
const map = {
|
|
40
|
+
added: 'primary',
|
|
41
|
+
waiting: 'warning',
|
|
42
|
+
downloading: 'warning',
|
|
43
|
+
downloaded: 'primary',
|
|
44
|
+
installing: 'warning',
|
|
45
|
+
installed: 'primary',
|
|
46
|
+
starting: 'warning',
|
|
47
|
+
running: 'success',
|
|
48
|
+
stopping: 'warning',
|
|
49
|
+
stopped: 'reverse',
|
|
50
|
+
error: 'error',
|
|
51
|
+
upgrading: 'warning',
|
|
52
|
+
restarting: 'warning',
|
|
53
|
+
corrupted: 'error',
|
|
54
|
+
deleting: 'warning'
|
|
55
|
+
};
|
|
56
|
+
const colorMap = {
|
|
57
|
+
added: colors.grey,
|
|
58
|
+
waiting: colors.yellow,
|
|
59
|
+
downloading: colors.yellow,
|
|
60
|
+
downloaded: colors.grey,
|
|
61
|
+
installing: colors.yellow,
|
|
62
|
+
installed: colors.grey,
|
|
63
|
+
starting: colors.yellow,
|
|
64
|
+
running: 'success',
|
|
65
|
+
stopping: colors.yellow,
|
|
66
|
+
stopped: colors.grey,
|
|
67
|
+
error: 'error',
|
|
68
|
+
upgrading: colors.yellow,
|
|
69
|
+
restarting: colors.yellow,
|
|
70
|
+
corrupted: 'error',
|
|
71
|
+
deleting: colors.yellow
|
|
72
|
+
};
|
|
73
|
+
const inProgress = (0, _util.isInProgress)(status);
|
|
74
|
+
const statusTxt = t("blocklet.status.".concat(status));
|
|
75
|
+
if (variant === 'dot') {
|
|
76
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tooltip.default, {
|
|
77
|
+
title: t('blocklet.statusTip', {
|
|
78
|
+
status: statusTxt
|
|
79
|
+
}),
|
|
80
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_dot.default, _objectSpread({
|
|
81
|
+
color: colorMap[status]
|
|
82
|
+
}, rest))
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_tag.default, _objectSpread(_objectSpread({
|
|
86
|
+
type: map[status]
|
|
87
|
+
}, rest), {}, {
|
|
88
|
+
children: [inProgress && /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
|
|
89
|
+
size: 12,
|
|
90
|
+
color: "inherit",
|
|
91
|
+
style: {
|
|
92
|
+
marginRight: 5
|
|
93
|
+
}
|
|
94
|
+
}), statusTxt]
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
BlockletStatus.propTypes = {
|
|
98
|
+
status: _propTypes.default.string.isRequired,
|
|
99
|
+
variant: _propTypes.default.oneOf(['dot', 'tag']),
|
|
100
|
+
source: _propTypes.default.string
|
|
101
|
+
};
|
|
102
|
+
BlockletStatus.defaultProps = {
|
|
103
|
+
variant: 'tag',
|
|
104
|
+
source: ''
|
|
105
|
+
};
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = Storage;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _Box = _interopRequireDefault(require("@mui/material/Box"));
|
|
9
|
+
var _Connect = _interopRequireDefault(require("@arcblock/did-connect/lib/Connect"));
|
|
10
|
+
var _context = require("@arcblock/ux/lib/Locale/context");
|
|
11
|
+
var _constant = require("@blocklet/constant");
|
|
12
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
13
|
+
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
14
|
+
var _styled = _interopRequireDefault(require("@emotion/styled"));
|
|
15
|
+
var _lodash = require("lodash");
|
|
16
|
+
var _Typography = _interopRequireDefault(require("@mui/material/Typography"));
|
|
17
|
+
var _material = require("@mui/material");
|
|
18
|
+
var _Button = _interopRequireDefault(require("@arcblock/ux/lib/Button"));
|
|
19
|
+
var _util = require("@blocklet/meta/lib/util");
|
|
20
|
+
var _blocklet = require("../../lib/contexts/blocklet");
|
|
21
|
+
var _node = require("../contexts/node");
|
|
22
|
+
var _toast = _interopRequireDefault(require("../../lib/toast"));
|
|
23
|
+
var _spaceGatewaySelector = _interopRequireDefault(require("./component/space-gateway-selector"));
|
|
24
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
+
var _templateObject;
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
32
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
33
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
34
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
35
|
+
const Container = (0, _styled.default)('div')(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n height: 100%;\n overflow-y: auto;\n"])));
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description 实时显示备份的进度
|
|
39
|
+
* @param {{appDid: string}} {appDid}
|
|
40
|
+
* @return {{message: string, progress: number, completed: boolean}}
|
|
41
|
+
*/
|
|
42
|
+
function useBackupProgress(_ref) {
|
|
43
|
+
let {
|
|
44
|
+
appDid
|
|
45
|
+
} = _ref;
|
|
46
|
+
const [progress, setProgress] = (0, _react.useState)({
|
|
47
|
+
message: '',
|
|
48
|
+
progress: 0,
|
|
49
|
+
completed: false
|
|
50
|
+
});
|
|
51
|
+
const node = (0, _node.useNodeContext)();
|
|
52
|
+
const webSocketClient = node.ws.getWsClient();
|
|
53
|
+
(0, _react.useEffect)(() => {
|
|
54
|
+
webSocketClient.on(_constant.BlockletEvents.backupProgress, data => {
|
|
55
|
+
if (appDid === (data === null || data === void 0 ? void 0 : data.appDid)) {
|
|
56
|
+
setProgress(preValue => _objectSpread(_objectSpread({}, preValue), data));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return () => {
|
|
60
|
+
webSocketClient.off(_constant.BlockletEvents.backupProgress);
|
|
61
|
+
};
|
|
62
|
+
}, [appDid, webSocketClient]);
|
|
63
|
+
return progress;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
*
|
|
69
|
+
* @param {import('@abtnode/client').BlockletState} blocklet
|
|
70
|
+
* @return {*}
|
|
71
|
+
*/
|
|
72
|
+
function useAppUrl(blocklet) {
|
|
73
|
+
var _blocklet$site, _blocklet$site$domain, _blocklet$site$domain2;
|
|
74
|
+
const appUrls = blocklet === null || blocklet === void 0 ? void 0 : (_blocklet$site = blocklet.site) === null || _blocklet$site === void 0 ? void 0 : (_blocklet$site$domain = _blocklet$site.domainAliases) === null || _blocklet$site$domain === void 0 ? void 0 : (_blocklet$site$domain2 = _blocklet$site$domain.sort((a, b) => {
|
|
75
|
+
if (a.accessibility.accessible && b.accessibility.accessible) {
|
|
76
|
+
return +a.isProtected - +b.isProtected;
|
|
77
|
+
}
|
|
78
|
+
return +b.accessibility.accessible - +a.accessibility.accessible;
|
|
79
|
+
})) === null || _blocklet$site$domain2 === void 0 ? void 0 : _blocklet$site$domain2.map(domainAlias => {
|
|
80
|
+
var _domainAlias$domainSt;
|
|
81
|
+
const protocol = domainAlias !== null && domainAlias !== void 0 && (_domainAlias$domainSt = domainAlias.domainStatus) !== null && _domainAlias$domainSt !== void 0 && _domainAlias$domainSt.isHttps ? 'https://' : 'http://';
|
|
82
|
+
const value = domainAlias === null || domainAlias === void 0 ? void 0 : domainAlias.value;
|
|
83
|
+
return "".concat(protocol).concat(value);
|
|
84
|
+
}).filter(Boolean);
|
|
85
|
+
const appUrl = appUrls === null || appUrls === void 0 ? void 0 : appUrls[0];
|
|
86
|
+
|
|
87
|
+
// 授权的时候提供 appUrl, 因为 appUrl 可能很久都拿不到值,所以加一个 loading 效果过渡一下
|
|
88
|
+
return {
|
|
89
|
+
appUrl,
|
|
90
|
+
isReady: Boolean(appUrl)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function Storage() {
|
|
94
|
+
var _blocklet$environment;
|
|
95
|
+
/** @type {{ api: import('@abtnode/client').ABTNodeClient, info: import('@abtnode/client').NodeState }} */
|
|
96
|
+
const {
|
|
97
|
+
api,
|
|
98
|
+
info
|
|
99
|
+
} = (0, _node.useNodeContext)();
|
|
100
|
+
const nodeDid = info.did;
|
|
101
|
+
const {
|
|
102
|
+
t,
|
|
103
|
+
locale
|
|
104
|
+
} = (0, _react.useContext)(_context.LocaleContext);
|
|
105
|
+
/** @type {{ blocklet: import('@abtnode/client').BlockletState }} */
|
|
106
|
+
const {
|
|
107
|
+
blocklet
|
|
108
|
+
} = (0, _blocklet.useBlockletContext)();
|
|
109
|
+
const [gatewayUrl, setGatewayUrl] = (0, _react.useState)('');
|
|
110
|
+
const [endpoint, setEndpoint] = (0, _react.useState)(((_blocklet$environment = blocklet.environments.find(e => e.key === _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACE_ENDPOINT)) === null || _blocklet$environment === void 0 ? void 0 : _blocklet$environment.value) || '');
|
|
111
|
+
const progress = useBackupProgress({
|
|
112
|
+
appDid: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appDid
|
|
113
|
+
});
|
|
114
|
+
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
115
|
+
const appName = (0, _util.getAppName)(blocklet);
|
|
116
|
+
const appDescription = (0, _util.getAppDescription)(blocklet);
|
|
117
|
+
const {
|
|
118
|
+
appUrl,
|
|
119
|
+
isReady
|
|
120
|
+
} = useAppUrl(blocklet);
|
|
121
|
+
async function saveStorageEndpoint(did, storageEndpoint) {
|
|
122
|
+
await api.configBlocklet({
|
|
123
|
+
input: {
|
|
124
|
+
did: [did],
|
|
125
|
+
configs: [{
|
|
126
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACES_URL,
|
|
127
|
+
value: gatewayUrl
|
|
128
|
+
}, {
|
|
129
|
+
key: _constant.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACE_ENDPOINT,
|
|
130
|
+
value: storageEndpoint
|
|
131
|
+
}]
|
|
132
|
+
}
|
|
133
|
+
}).then(() => {
|
|
134
|
+
_toast.default.success(t('storage.spaces.connected', locale));
|
|
135
|
+
}).catch(error => {
|
|
136
|
+
console.error(error);
|
|
137
|
+
_toast.default.error(error.message);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const onAuthorizeConnectSuccess = async (response, decrypt) => {
|
|
141
|
+
setEndpoint(decrypt(response.endpoint));
|
|
142
|
+
await saveStorageEndpoint(blocklet.meta.did, decrypt(response.endpoint));
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
145
|
+
open: false
|
|
146
|
+
}));
|
|
147
|
+
}, 3000);
|
|
148
|
+
};
|
|
149
|
+
const [authorizeConnect, setAuthorizeConnect] = (0, _react.useState)({
|
|
150
|
+
open: false
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// eslint-disable-next-line no-shadow
|
|
154
|
+
const handleOnClickAuthorize = async gatewayUrl => {
|
|
155
|
+
if ((0, _lodash.isEmpty)(gatewayUrl)) {
|
|
156
|
+
_toast.default.error(t('storage.spaces.addressCannotEmpty', locale));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
setGatewayUrl(gatewayUrl);
|
|
160
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
161
|
+
action: 'one-click-authorization',
|
|
162
|
+
checkTimeout: 1000 * 300,
|
|
163
|
+
prefix: (0, _urlJoin.default)(gatewayUrl, 'space/api/did'),
|
|
164
|
+
baseUrl: new URL(gatewayUrl).origin,
|
|
165
|
+
checkFn: _axios.default.create({
|
|
166
|
+
baseURL: (0, _urlJoin.default)(gatewayUrl, 'space')
|
|
167
|
+
}).get,
|
|
168
|
+
extraParams: {
|
|
169
|
+
appDid: blocklet.appDid,
|
|
170
|
+
appName,
|
|
171
|
+
appDescription,
|
|
172
|
+
scopes: 'list:object read:object write:object',
|
|
173
|
+
appUrl,
|
|
174
|
+
referrer: window.location.href,
|
|
175
|
+
nodeDid
|
|
176
|
+
},
|
|
177
|
+
onClose: () => {
|
|
178
|
+
// eslint-disable-next-line no-shadow
|
|
179
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
180
|
+
open: false
|
|
181
|
+
}));
|
|
182
|
+
},
|
|
183
|
+
open: true
|
|
184
|
+
}));
|
|
185
|
+
};
|
|
186
|
+
const onBackup = async () => {
|
|
187
|
+
try {
|
|
188
|
+
if (isLoading) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
setIsLoading(true);
|
|
192
|
+
await api.backupToSpaces({
|
|
193
|
+
input: {
|
|
194
|
+
appDid: blocklet.appDid
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
_toast.default.success(t('storage.spaces.backupSuccessfully'));
|
|
198
|
+
} catch (error) {
|
|
199
|
+
_toast.default.error(error.message);
|
|
200
|
+
console.error(error);
|
|
201
|
+
} finally {
|
|
202
|
+
setIsLoading(false);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
(0, _react.useEffect)(() => {
|
|
206
|
+
setAuthorizeConnect(preValue => _objectSpread(_objectSpread({}, preValue), {}, {
|
|
207
|
+
messages: {
|
|
208
|
+
title: t('storage.spaces.authorize.title', {
|
|
209
|
+
appName
|
|
210
|
+
}),
|
|
211
|
+
scan: t('storage.spaces.authorize.scan', {
|
|
212
|
+
appName
|
|
213
|
+
}),
|
|
214
|
+
confirm: '',
|
|
215
|
+
success: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
216
|
+
gutterBottom: true,
|
|
217
|
+
children: t('storage.spaces.authorize.success')
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
}));
|
|
221
|
+
}, [appName, locale, t]);
|
|
222
|
+
(0, _react.useEffect)(() => {
|
|
223
|
+
if (progress !== null && progress !== void 0 && progress.completed) {
|
|
224
|
+
setIsLoading(false);
|
|
225
|
+
if (progress !== null && progress !== void 0 && progress.progress) {
|
|
226
|
+
progress.progress = 0;
|
|
227
|
+
}
|
|
228
|
+
} else if (progress !== null && progress !== void 0 && progress.message) {
|
|
229
|
+
setIsLoading(true);
|
|
230
|
+
}
|
|
231
|
+
}, [progress]);
|
|
232
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, {
|
|
233
|
+
style: {
|
|
234
|
+
maxWidth: '720px'
|
|
235
|
+
},
|
|
236
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_spaceGatewaySelector.default, {
|
|
237
|
+
sx: {
|
|
238
|
+
marginTop: '24px',
|
|
239
|
+
marginBottom: '40px'
|
|
240
|
+
},
|
|
241
|
+
onSelect: handleOnClickAuthorize,
|
|
242
|
+
endpoint: endpoint,
|
|
243
|
+
loading: !isReady
|
|
244
|
+
}), endpoint && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
245
|
+
mt: 3,
|
|
246
|
+
display: "flex",
|
|
247
|
+
alignItems: "center",
|
|
248
|
+
justifyContent: "space-between",
|
|
249
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
250
|
+
display: "inline",
|
|
251
|
+
children: [t('storage.spaces.tips'), ": \xA0", ' ', /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
252
|
+
display: "inline",
|
|
253
|
+
color: "primary.main",
|
|
254
|
+
fontWeight: "fontWeightBold",
|
|
255
|
+
children: t('storage.spaces.connected')
|
|
256
|
+
})]
|
|
257
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
|
|
258
|
+
onClick: onBackup,
|
|
259
|
+
loading: isLoading,
|
|
260
|
+
variant: "contained",
|
|
261
|
+
color: "primary",
|
|
262
|
+
"data-cy": "add-domain-alias",
|
|
263
|
+
disabled: !endpoint || isLoading,
|
|
264
|
+
children: t('storage.spaces.backup')
|
|
265
|
+
})]
|
|
266
|
+
}), isLoading && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
267
|
+
sx: {
|
|
268
|
+
overflow: 'hidden'
|
|
269
|
+
},
|
|
270
|
+
display: "flex",
|
|
271
|
+
flexDirection: "column",
|
|
272
|
+
justifyContent: "center",
|
|
273
|
+
textAlign: "center",
|
|
274
|
+
marginTop: "16px",
|
|
275
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
|
|
276
|
+
color: "primary",
|
|
277
|
+
children: progress === null || progress === void 0 ? void 0 : progress.message
|
|
278
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
|
|
279
|
+
sx: {
|
|
280
|
+
display: 'flex',
|
|
281
|
+
alignItems: 'center'
|
|
282
|
+
},
|
|
283
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
284
|
+
sx: {
|
|
285
|
+
width: '100%',
|
|
286
|
+
mr: 1
|
|
287
|
+
},
|
|
288
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.LinearProgress, {
|
|
289
|
+
color: "primary",
|
|
290
|
+
variant: "indeterminate",
|
|
291
|
+
value: progress === null || progress === void 0 ? void 0 : progress.progress
|
|
292
|
+
})
|
|
293
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
|
|
294
|
+
sx: {
|
|
295
|
+
minWidth: 35
|
|
296
|
+
},
|
|
297
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Typography.default, {
|
|
298
|
+
variant: "body2",
|
|
299
|
+
color: "text.secondary",
|
|
300
|
+
children: [progress === null || progress === void 0 ? void 0 : progress.progress, "%"]
|
|
301
|
+
})
|
|
302
|
+
})]
|
|
303
|
+
})]
|
|
304
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
|
|
305
|
+
forceConnected: false,
|
|
306
|
+
saveConnect: false,
|
|
307
|
+
prefix: authorizeConnect.prefix,
|
|
308
|
+
open: authorizeConnect.open,
|
|
309
|
+
popup: true,
|
|
310
|
+
action: authorizeConnect.action,
|
|
311
|
+
baseUrl: authorizeConnect.baseUrl,
|
|
312
|
+
checkFn: authorizeConnect.checkFn,
|
|
313
|
+
onSuccess: onAuthorizeConnectSuccess,
|
|
314
|
+
onClose: authorizeConnect.onClose,
|
|
315
|
+
checkTimeout: authorizeConnect.checkTimeout,
|
|
316
|
+
extraParams: authorizeConnect.extraParams,
|
|
317
|
+
messages: authorizeConnect.messages,
|
|
318
|
+
locale: locale
|
|
319
|
+
})]
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
Storage.propTypes = {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DomainType = void 0;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
// eslint-disable-next-line import/prefer-default-export
|
|
10
|
+
const DomainType = _propTypes.default.shape({
|
|
11
|
+
href: _propTypes.default.string,
|
|
12
|
+
accessibility: _propTypes.default.shape({
|
|
13
|
+
loading: _propTypes.default.bool,
|
|
14
|
+
accessible: _propTypes.default.bool
|
|
15
|
+
}),
|
|
16
|
+
domainStatus: _propTypes.default.shape({
|
|
17
|
+
isHttps: _propTypes.default.bool,
|
|
18
|
+
matchedCert: _propTypes.default.object
|
|
19
|
+
}),
|
|
20
|
+
dns: _propTypes.default.shape({
|
|
21
|
+
resolved: _propTypes.default.bool,
|
|
22
|
+
ip: _propTypes.default.string
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
exports.DomainType = DomainType;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.downloadExportedSource = downloadExportedSource;
|
|
7
|
+
exports.fixBlocklet = exports.ensureDomainAliases = void 0;
|
|
8
|
+
exports.genExportedMeta = genExportedMeta;
|
|
9
|
+
exports.getLaunchAgreementUrl = void 0;
|
|
10
|
+
exports.getNameByTitle = getNameByTitle;
|
|
11
|
+
exports.getServerUrl = void 0;
|
|
12
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
13
|
+
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
14
|
+
var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
|
|
15
|
+
var _sortBy = _interopRequireDefault(require("lodash/sortBy"));
|
|
16
|
+
var _jszip = _interopRequireDefault(require("jszip"));
|
|
17
|
+
var _jsYaml = _interopRequireDefault(require("js-yaml"));
|
|
18
|
+
var _fileSaver = _interopRequireDefault(require("file-saver"));
|
|
19
|
+
var _urlJoin = _interopRequireDefault(require("url-join"));
|
|
20
|
+
var _didMotif = require("@arcblock/did-motif");
|
|
21
|
+
var _normalizePathPrefix = _interopRequireDefault(require("@abtnode/util/lib/normalize-path-prefix"));
|
|
22
|
+
var _did = _interopRequireDefault(require("@blocklet/meta/lib/did"));
|
|
23
|
+
var _util = require("@blocklet/meta/lib/util");
|
|
24
|
+
var _constant = require("@abtnode/constant");
|
|
25
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
|
+
const base64ToArrayBuffer = base64 => {
|
|
27
|
+
const bufStr = window.atob(base64);
|
|
28
|
+
const bytes = new Uint8Array(bufStr.length);
|
|
29
|
+
for (let i = 0; i < bufStr.length; i++) {
|
|
30
|
+
bytes[i] = bufStr.charCodeAt(i);
|
|
31
|
+
}
|
|
32
|
+
return bytes;
|
|
33
|
+
};
|
|
34
|
+
const getLogo = did => {
|
|
35
|
+
const url = (0, _didMotif.toDataURL)(did, {
|
|
36
|
+
size: 256
|
|
37
|
+
});
|
|
38
|
+
const base64 = url.replace(/^[^,]*,/, '');
|
|
39
|
+
return base64ToArrayBuffer(base64);
|
|
40
|
+
};
|
|
41
|
+
function getNameByTitle(title) {
|
|
42
|
+
return title.replace(/[\s/@_]/g, '-').replace(/[^a-zA-Z0-9_-]/g, '').replace(/(^[-\s]+)|([-\s]+$)/g, '').toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
function genExportedMeta(name, blocklet) {
|
|
45
|
+
let meta = (0, _pick.default)((0, _cloneDeep.default)(blocklet.meta), ['title', 'description', 'group', 'version', 'capabilities', 'interfaces', 'requirements']);
|
|
46
|
+
|
|
47
|
+
// filter null or undefined
|
|
48
|
+
meta = (0, _pickBy.default)(meta, x => x !== null);
|
|
49
|
+
meta.requirements = (0, _pickBy.default)(meta.requirements, x => !!x);
|
|
50
|
+
meta.interfaces.forEach(x => {
|
|
51
|
+
if (!x.services) {
|
|
52
|
+
delete x.services;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
meta.name = name;
|
|
56
|
+
meta.did = (0, _did.default)(name);
|
|
57
|
+
meta.logo = 'logo.png';
|
|
58
|
+
meta.components = [];
|
|
59
|
+
blocklet.children.forEach(child => {
|
|
60
|
+
if (child.dynamic && child.bundleSource) {
|
|
61
|
+
meta.components.push({
|
|
62
|
+
name: child.meta.name,
|
|
63
|
+
source: child.bundleSource,
|
|
64
|
+
title: child.meta.title,
|
|
65
|
+
mountPoint: child.mountPoint
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
meta.environments = (blocklet.configs || []).map(x => ({
|
|
70
|
+
name: x.key,
|
|
71
|
+
description: 'Automatically generated when exporting',
|
|
72
|
+
required: !!x.required,
|
|
73
|
+
secure: !!x.secure,
|
|
74
|
+
default: x.secure ? '' : x.value || ''
|
|
75
|
+
}));
|
|
76
|
+
meta.capabilities.component = false;
|
|
77
|
+
return meta;
|
|
78
|
+
}
|
|
79
|
+
const license = holder => "Copyright \xA9 2022 ".concat(holder || '', "\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201CSoftware\u201D), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \u201CAS IS\u201D, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.");
|
|
80
|
+
const Gitignore = ".DS_Store\n.blocklet";
|
|
81
|
+
const GithubAction = "name: Deploy\n\non:\n push:\n branches:\n - main\n\njobs:\n Deploy:\n runs-on: ubuntu-latest\n\n steps:\n - name: Checkout repo\n uses: actions/checkout@v2\n\n - name: Blocklet workflow\n uses: blocklet/action-workflow@v1\n with:\n skip-upload: true\n skip-deploy: true\n bundle-command: blocklet bundle --create-release\n github-token: ${{ secrets.GITHUB_TOKEN }}";
|
|
82
|
+
async function downloadExportedSource(meta) {
|
|
83
|
+
let {
|
|
84
|
+
holder
|
|
85
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
|
+
const folderName = "".concat(meta.name.split('/').pop());
|
|
87
|
+
const readme = "# ".concat(meta.title, "\n\n## Introduction\n\n").concat(meta.description);
|
|
88
|
+
const zip = new _jszip.default();
|
|
89
|
+
const folder = zip.folder(folderName);
|
|
90
|
+
folder.file('blocklet.yml', _jsYaml.default.dump(meta));
|
|
91
|
+
folder.file('blocklet.md', readme);
|
|
92
|
+
folder.file('README.md', readme);
|
|
93
|
+
folder.file('logo.png', getLogo(meta.did));
|
|
94
|
+
folder.file('LICENSE', license(holder));
|
|
95
|
+
folder.file('.gitignore', Gitignore);
|
|
96
|
+
folder.folder('screenshots').file('.gitkeep', '');
|
|
97
|
+
folder.folder('.github').folder('workflows').file('main.yml', GithubAction);
|
|
98
|
+
await new Promise((resolve, reject) => {
|
|
99
|
+
zip.generateAsync({
|
|
100
|
+
type: 'blob'
|
|
101
|
+
}).then(content => {
|
|
102
|
+
(0, _fileSaver.default)(content, "".concat(folderName, ".zip"));
|
|
103
|
+
resolve();
|
|
104
|
+
}).catch(err => {
|
|
105
|
+
reject(err);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const getServerUrl = function getServerUrl(info) {
|
|
110
|
+
let encodeURI = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
111
|
+
const adminPath = process.env.NODE_ENV === 'production' ? info.routing.adminPath : '';
|
|
112
|
+
return encodeURI ? encodeURIComponent((0, _urlJoin.default)(window.location.origin, adminPath)) : (0, _urlJoin.default)(window.location.origin, adminPath);
|
|
113
|
+
};
|
|
114
|
+
exports.getServerUrl = getServerUrl;
|
|
115
|
+
const getLaunchAgreementUrl = (meta, info, storeUrl) => {
|
|
116
|
+
const serverUrl = getServerUrl(info);
|
|
117
|
+
const metaUrl = (0, _urlJoin.default)(storeUrl, "/api/blocklets/".concat(meta.did, "/blocklet.json"));
|
|
118
|
+
const url = new URL((0, _urlJoin.default)(serverUrl, '/launch-blocklet/agreement'));
|
|
119
|
+
url.searchParams.set('blocklet_meta_url', metaUrl);
|
|
120
|
+
url.searchParams.set('from', window.location.href);
|
|
121
|
+
return url.href;
|
|
122
|
+
};
|
|
123
|
+
exports.getLaunchAgreementUrl = getLaunchAgreementUrl;
|
|
124
|
+
const ensureDomainAliases = async function ensureDomainAliases(domainAliases) {
|
|
125
|
+
let {
|
|
126
|
+
getIP
|
|
127
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
128
|
+
if (!domainAliases || !domainAliases.length) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
if (!getIP) {
|
|
132
|
+
return domainAliases;
|
|
133
|
+
}
|
|
134
|
+
if (!domainAliases.some(x => x.value.includes(_constant.SLOT_FOR_IP_DNS_SITE))) {
|
|
135
|
+
return domainAliases;
|
|
136
|
+
}
|
|
137
|
+
const ip = await getIP();
|
|
138
|
+
if (!ip) {
|
|
139
|
+
return domainAliases;
|
|
140
|
+
}
|
|
141
|
+
return domainAliases.map(x => {
|
|
142
|
+
try {
|
|
143
|
+
x.value = (0, _util.replaceSlotToIp)(x.value, ip);
|
|
144
|
+
return x;
|
|
145
|
+
} catch (_unused) {
|
|
146
|
+
return x;
|
|
147
|
+
}
|
|
148
|
+
}).filter(Boolean);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {object} blocklet
|
|
153
|
+
* @param {{
|
|
154
|
+
* fixRuntime:boolean|string // true, 'merge-old'
|
|
155
|
+
* oldBlocklet: object
|
|
156
|
+
* getIP: function
|
|
157
|
+
* }}
|
|
158
|
+
*/
|
|
159
|
+
exports.ensureDomainAliases = ensureDomainAliases;
|
|
160
|
+
const fixBlocklet = async function fixBlocklet(blocklet) {
|
|
161
|
+
let {
|
|
162
|
+
fixRuntime = true,
|
|
163
|
+
oldBlocklet,
|
|
164
|
+
getIP
|
|
165
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
166
|
+
if (!blocklet.site) {
|
|
167
|
+
blocklet.site = {
|
|
168
|
+
domainAliases: [],
|
|
169
|
+
rules: []
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
blocklet.site.rules.forEach(rule => {
|
|
173
|
+
rule.from.pathPrefix = (0, _normalizePathPrefix.default)(rule.from.pathPrefix || '/');
|
|
174
|
+
});
|
|
175
|
+
blocklet.site.rules = (0, _sortBy.default)(blocklet.site.rules, i => i.from.pathPrefix);
|
|
176
|
+
if (fixRuntime === true) {
|
|
177
|
+
blocklet.site.domainAliases = await ensureDomainAliases(blocklet.site.domainAliases, {
|
|
178
|
+
getIP
|
|
179
|
+
});
|
|
180
|
+
if (blocklet.appRuntimeInfo) {
|
|
181
|
+
blocklet.appRuntimeInfo.startAt = new Date() - blocklet.appRuntimeInfo.uptime;
|
|
182
|
+
}
|
|
183
|
+
(0, _util.forEachBlockletSync)(blocklet, b => {
|
|
184
|
+
if (b.runtimeInfo) {
|
|
185
|
+
b.runtimeInfo.startAt = new Date() - b.runtimeInfo.uptime;
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
} else if (fixRuntime === 'merge-old' && oldBlocklet) {
|
|
189
|
+
blocklet.site.domainAliases = oldBlocklet.site.domainAliases;
|
|
190
|
+
blocklet.appRuntimeInfo = oldBlocklet.appRuntimeInfo;
|
|
191
|
+
const oldComponents = {};
|
|
192
|
+
(0, _util.forEachBlockletSync)(oldBlocklet, (component, _ref) => {
|
|
193
|
+
let {
|
|
194
|
+
id
|
|
195
|
+
} = _ref;
|
|
196
|
+
oldComponents[id] = component;
|
|
197
|
+
});
|
|
198
|
+
(0, _util.forEachBlockletSync)(blocklet, (component, _ref2) => {
|
|
199
|
+
let {
|
|
200
|
+
id
|
|
201
|
+
} = _ref2;
|
|
202
|
+
const oldComponent = oldComponents[id];
|
|
203
|
+
if (oldComponent) {
|
|
204
|
+
component.runtimeInfo = oldComponent.runtimeInfo;
|
|
205
|
+
component.diskInfo = oldComponent.diskInfo;
|
|
206
|
+
component.engine = oldComponent.engine;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
blocklet.site.domainAliases = [];
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
exports.fixBlocklet = fixBlocklet;
|