coolcare-lite-scada-component 4.1.4 → 4.1.5

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.
@@ -0,0 +1,819 @@
1
+ var _excluded = ["_row"];
2
+ function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof Symbol && Symbol.iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
4
+ 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); }
5
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
6
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
7
+ 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; }
8
+ 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; }
9
+ 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; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
11
+ 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); }
12
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
13
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
14
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
15
+ 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."); }
16
+ 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; } }
17
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
18
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
19
+ 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; }
20
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
21
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
22
+ import seedData from "./resource-seed.json";
23
+ import { isThreeResourceGroup } from "./resource-groups";
24
+ var images = '/api/ProductMicro/ConfigurationImg';
25
+ var groups = '/api/ProductMicro/ConfigurationImgGroup';
26
+ var marker = 'coolcare-resource-3d';
27
+ var clone = function clone(value) {
28
+ return JSON.parse(JSON.stringify(value));
29
+ };
30
+ function resourceUrl(value) {
31
+ if (typeof value !== 'string') throw new Error('资源文件地址无效。');
32
+ var url = new URL(value);
33
+ if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password) throw new Error('资源文件地址无效。');
34
+ return url.href;
35
+ }
36
+
37
+ /** 使用二维的分组、图片记录与通用上传接口;不新增接口或数据库字段。 */
38
+ export function createResourceAdapter(request) {
39
+ var fetchFile = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fetch;
40
+ function call(_x, _x2) {
41
+ return _call.apply(this, arguments);
42
+ }
43
+ function _call() {
44
+ _call = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(path, data) {
45
+ var result;
46
+ return _regenerator().w(function (_context2) {
47
+ while (1) switch (_context2.n) {
48
+ case 0:
49
+ _context2.n = 1;
50
+ return request(path, {
51
+ method: 'POST',
52
+ data: data,
53
+ timeout: 40000
54
+ });
55
+ case 1:
56
+ result = _context2.v;
57
+ if (result === null || result === void 0 ? void 0 : result.success) {
58
+ _context2.n = 2;
59
+ break;
60
+ }
61
+ throw new Error((result === null || result === void 0 ? void 0 : result.message) || '资源操作失败,请重试。');
62
+ case 2:
63
+ return _context2.a(2, result.data);
64
+ }
65
+ }, _callee2);
66
+ }));
67
+ return _call.apply(this, arguments);
68
+ }
69
+ function pages(_x3, _x4) {
70
+ return _pages.apply(this, arguments);
71
+ }
72
+ function _pages() {
73
+ _pages = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(path, query) {
74
+ var rows, pageNumber, _result$pagingInfo, result;
75
+ return _regenerator().w(function (_context3) {
76
+ while (1) switch (_context3.n) {
77
+ case 0:
78
+ rows = [];
79
+ pageNumber = 1;
80
+ case 1:
81
+ if (!(pageNumber <= 1000)) {
82
+ _context3.n = 5;
83
+ break;
84
+ }
85
+ _context3.n = 2;
86
+ return call(path, _objectSpread(_objectSpread({}, query), {}, {
87
+ pageNumber: pageNumber,
88
+ pageSize: 100
89
+ }));
90
+ case 2:
91
+ result = _context3.v;
92
+ if (Array.isArray(result === null || result === void 0 ? void 0 : result.list)) {
93
+ _context3.n = 3;
94
+ break;
95
+ }
96
+ throw new Error('资源列表返回格式无效。');
97
+ case 3:
98
+ rows.push.apply(rows, _toConsumableArray(result.list));
99
+ if ((_result$pagingInfo = result.pagingInfo) === null || _result$pagingInfo === void 0 ? void 0 : _result$pagingInfo.hasNext) {
100
+ _context3.n = 4;
101
+ break;
102
+ }
103
+ return _context3.a(2, rows);
104
+ case 4:
105
+ pageNumber++;
106
+ _context3.n = 1;
107
+ break;
108
+ case 5:
109
+ throw new Error('资源列表过大,请缩小资源分组。');
110
+ case 6:
111
+ return _context3.a(2);
112
+ }
113
+ }, _callee3);
114
+ }));
115
+ return _pages.apply(this, arguments);
116
+ }
117
+ function allGroups() {
118
+ return _allGroups.apply(this, arguments);
119
+ }
120
+ function _allGroups() {
121
+ _allGroups = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
122
+ return _regenerator().w(function (_context4) {
123
+ while (1) switch (_context4.n) {
124
+ case 0:
125
+ _context4.n = 1;
126
+ return pages("".concat(groups, "/GetConfigurationImgGroupPage"), {
127
+ isGetSystem: true
128
+ });
129
+ case 1:
130
+ return _context4.a(2, _context4.v.filter(isThreeResourceGroup));
131
+ }
132
+ }, _callee4);
133
+ }));
134
+ return _allGroups.apply(this, arguments);
135
+ }
136
+ function category(row) {
137
+ var match = /^\[3D:(model|hdri|material)\](.*)$/.exec(row.configurationImgGroupName);
138
+ return {
139
+ id: "legacy-group-".concat(row.configurationImgGroupId),
140
+ kind: match[1],
141
+ name: match[2],
142
+ sort: row.index || 0,
143
+ version: 1
144
+ };
145
+ }
146
+ function upload(_x5, _x6) {
147
+ return _upload.apply(this, arguments);
148
+ }
149
+ function _upload() {
150
+ _upload = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(blob, name) {
151
+ var data, urls;
152
+ return _regenerator().w(function (_context5) {
153
+ while (1) switch (_context5.n) {
154
+ case 0:
155
+ data = new FormData();
156
+ data.append('BucketName', 'coolcare-scada');
157
+ data.append('ObjectName', '组态资源/三维/');
158
+ // 通用上传器会创建新对象名,每次保存的参数文件均不可变。
159
+ data.append('file', blob, name);
160
+ _context5.n = 1;
161
+ return call('/api/CommonMicro/Uploader/Upload', data);
162
+ case 1:
163
+ urls = _context5.v;
164
+ if (!(!Array.isArray(urls) || urls.length !== 1)) {
165
+ _context5.n = 2;
166
+ break;
167
+ }
168
+ throw new Error('上传未返回文件地址。');
169
+ case 2:
170
+ return _context5.a(2, resourceUrl(urls[0]));
171
+ }
172
+ }, _callee5);
173
+ }));
174
+ return _upload.apply(this, arguments);
175
+ }
176
+ function readManifest(_x7) {
177
+ return _readManifest.apply(this, arguments);
178
+ }
179
+ function _readManifest() {
180
+ _readManifest = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(url) {
181
+ var response, text, value;
182
+ return _regenerator().w(function (_context6) {
183
+ while (1) switch (_context6.n) {
184
+ case 0:
185
+ _context6.n = 1;
186
+ return fetchFile(resourceUrl(url), {
187
+ credentials: 'omit',
188
+ referrerPolicy: 'no-referrer',
189
+ signal: AbortSignal.timeout(20000)
190
+ });
191
+ case 1:
192
+ response = _context6.v;
193
+ if (response.ok) {
194
+ _context6.n = 2;
195
+ break;
196
+ }
197
+ throw new Error('资源参数文件读取失败,请检查存储地址及跨域配置。');
198
+ case 2:
199
+ _context6.n = 3;
200
+ return response.text();
201
+ case 3:
202
+ text = _context6.v;
203
+ if (!(text.length > 500000)) {
204
+ _context6.n = 4;
205
+ break;
206
+ }
207
+ throw new Error('资源参数文件过大。');
208
+ case 4:
209
+ value = JSON.parse(text);
210
+ if (!(value.format !== marker || !value.draft || _typeof(value.draft) !== 'object')) {
211
+ _context6.n = 5;
212
+ break;
213
+ }
214
+ throw new Error('资源参数文件格式无效。');
215
+ case 5:
216
+ return _context6.a(2, value);
217
+ }
218
+ }, _callee6);
219
+ }));
220
+ return _readManifest.apply(this, arguments);
221
+ }
222
+ function descriptor(row) {
223
+ var _value;
224
+ var value;
225
+ try {
226
+ value = JSON.parse(row.config);
227
+ } catch (_unused) {
228
+ throw new Error("\u8D44\u6E90\u201C".concat(row.name, "\u201D\u914D\u7F6E\u635F\u574F\u3002"));
229
+ }
230
+ if (((_value = value) === null || _value === void 0 ? void 0 : _value.format) !== marker || !['model', 'hdri', 'material'].includes(value.kind)) throw new Error("\u8D44\u6E90\u201C".concat(row.name, "\u201D\u683C\u5F0F\u4E0D\u53D7\u652F\u6301\u3002"));
231
+ resourceUrl(value.url);
232
+ return value;
233
+ }
234
+ function catalog() {
235
+ return _catalog.apply(this, arguments);
236
+ }
237
+ function _catalog() {
238
+ _catalog = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
239
+ var rawGroups, storedCategories, seed, categories, builtins, resources, _iterator, _step, _loop, overrides, _t9;
240
+ return _regenerator().w(function (_context9) {
241
+ while (1) switch (_context9.p = _context9.n) {
242
+ case 0:
243
+ _context9.n = 1;
244
+ return allGroups();
245
+ case 1:
246
+ rawGroups = _context9.v;
247
+ storedCategories = rawGroups.map(category);
248
+ seed = clone(seedData);
249
+ categories = [].concat(_toConsumableArray(storedCategories), _toConsumableArray(seed.categories.filter(function (c) {
250
+ return !storedCategories.some(function (s) {
251
+ return s.kind === c.kind && s.name === c.name;
252
+ });
253
+ })));
254
+ builtins = seed.resources.map(function (r) {
255
+ var original = seed.categories.find(function (c) {
256
+ return c.id === r.draft.categoryId;
257
+ });
258
+ var mapped = categories.find(function (c) {
259
+ return c.kind === original.kind && c.name === original.name;
260
+ });
261
+ r.draft.categoryId = mapped.id;
262
+ r.published.categoryId = mapped.id;
263
+ return r;
264
+ });
265
+ resources = []; // 限制并发,避免打开目录同时触发几十次存储请求。
266
+ _iterator = _createForOfIteratorHelper(rawGroups);
267
+ _context9.p = 2;
268
+ _loop = /*#__PURE__*/_regenerator().m(function _loop() {
269
+ var group, rows, offset, loaded;
270
+ return _regenerator().w(function (_context8) {
271
+ while (1) switch (_context8.n) {
272
+ case 0:
273
+ group = _step.value;
274
+ _context8.n = 1;
275
+ return pages("".concat(images, "/GetConfigurationImgPage"), {
276
+ configurationImgGroupId: group.configurationImgGroupId,
277
+ sortType: 0
278
+ });
279
+ case 1:
280
+ rows = _context8.v;
281
+ offset = 0;
282
+ case 2:
283
+ if (!(offset < rows.length)) {
284
+ _context8.n = 5;
285
+ break;
286
+ }
287
+ _context8.n = 3;
288
+ return Promise.all(rows.slice(offset, offset + 6).map(/*#__PURE__*/function () {
289
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(row) {
290
+ var config, manifest, c, draft, revision;
291
+ return _regenerator().w(function (_context7) {
292
+ while (1) switch (_context7.n) {
293
+ case 0:
294
+ config = descriptor(row);
295
+ _context7.n = 1;
296
+ return readManifest(config.url);
297
+ case 1:
298
+ manifest = _context7.v;
299
+ c = category(group);
300
+ if (!(config.kind !== c.kind || manifest.kind !== c.kind)) {
301
+ _context7.n = 2;
302
+ break;
303
+ }
304
+ throw new Error("\u8D44\u6E90\u201C".concat(row.name, "\u201D\u7C7B\u578B\u4E0E\u5206\u7EC4\u4E0D\u5339\u914D\u3002"));
305
+ case 2:
306
+ draft = manifest.draft;
307
+ draft.name = row.name;
308
+ draft.categoryId = c.id;
309
+ draft.sort = row.index || 0;
310
+ revision = Number.isSafeInteger(config.revision) && config.revision > 0 ? config.revision : 1;
311
+ return _context7.a(2, _objectSpread(_objectSpread({
312
+ id: "legacy-resource-".concat(row.configurationImgId),
313
+ kind: c.kind
314
+ }, config.builtinKey ? {
315
+ builtinKey: config.builtinKey
316
+ } : {}), {}, {
317
+ draft: draft,
318
+ published: clone(draft),
319
+ draftVersion: revision,
320
+ publishedDraftVersion: revision,
321
+ revision: revision,
322
+ archived: false,
323
+ updatedAt: manifest.updatedAt || '',
324
+ _row: row
325
+ }));
326
+ }
327
+ }, _callee7);
328
+ }));
329
+ return function (_x12) {
330
+ return _ref3.apply(this, arguments);
331
+ };
332
+ }()));
333
+ case 3:
334
+ loaded = _context8.v;
335
+ resources.push.apply(resources, _toConsumableArray(loaded));
336
+ case 4:
337
+ offset += 6;
338
+ _context8.n = 2;
339
+ break;
340
+ case 5:
341
+ return _context8.a(2);
342
+ }
343
+ }, _loop);
344
+ });
345
+ _iterator.s();
346
+ case 3:
347
+ if ((_step = _iterator.n()).done) {
348
+ _context9.n = 5;
349
+ break;
350
+ }
351
+ return _context9.d(_regeneratorValues(_loop()), 4);
352
+ case 4:
353
+ _context9.n = 3;
354
+ break;
355
+ case 5:
356
+ _context9.n = 7;
357
+ break;
358
+ case 6:
359
+ _context9.p = 6;
360
+ _t9 = _context9.v;
361
+ _iterator.e(_t9);
362
+ case 7:
363
+ _context9.p = 7;
364
+ _iterator.f();
365
+ return _context9.f(7);
366
+ case 8:
367
+ overrides = new Set(resources.filter(function (r) {
368
+ return r.builtinKey;
369
+ }).map(function (r) {
370
+ return "".concat(r.kind, ":").concat(r.builtinKey);
371
+ }));
372
+ return _context9.a(2, {
373
+ categories: categories,
374
+ resources: [].concat(_toConsumableArray(builtins.filter(function (r) {
375
+ return !overrides.has("".concat(r.kind, ":").concat(r.builtinKey));
376
+ })), resources),
377
+ rawGroups: rawGroups
378
+ });
379
+ }
380
+ }, _callee8, null, [[2, 6, 7, 8]]);
381
+ }));
382
+ return _catalog.apply(this, arguments);
383
+ }
384
+ function ensureCategory(_x8, _x9, _x0) {
385
+ return _ensureCategory.apply(this, arguments);
386
+ }
387
+ function _ensureCategory() {
388
+ _ensureCategory = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(id, kind, state) {
389
+ var seedCategory, c, name, match;
390
+ return _regenerator().w(function (_context0) {
391
+ while (1) switch (_context0.n) {
392
+ case 0:
393
+ seedCategory = seedData.categories.find(function (c) {
394
+ return c.id === id && c.kind === kind;
395
+ });
396
+ c = state.categories.find(function (c) {
397
+ return c.id === id && c.kind === kind;
398
+ }) || seedCategory && state.categories.find(function (c) {
399
+ return c.kind === kind && c.name === seedCategory.name;
400
+ });
401
+ if (c) {
402
+ _context0.n = 1;
403
+ break;
404
+ }
405
+ throw new Error('请选择对应类型的资源分组。');
406
+ case 1:
407
+ if (!c.id.startsWith('legacy-group-')) {
408
+ _context0.n = 2;
409
+ break;
410
+ }
411
+ return _context0.a(2, c);
412
+ case 2:
413
+ name = "[3D:".concat(kind, "]").concat(c.name);
414
+ _context0.n = 3;
415
+ return call("".concat(groups, "/AddOrUpdateConfigurationImgGroup"), [{
416
+ configurationImgGroupName: name,
417
+ isSystem: true,
418
+ index: c.sort
419
+ }]);
420
+ case 3:
421
+ _context0.n = 4;
422
+ return allGroups();
423
+ case 4:
424
+ match = _context0.v.find(function (g) {
425
+ return g.configurationImgGroupName === name;
426
+ });
427
+ if (match) {
428
+ _context0.n = 5;
429
+ break;
430
+ }
431
+ throw new Error('分组已提交,但未能重新读取,请刷新核对。');
432
+ case 5:
433
+ return _context0.a(2, category(match));
434
+ }
435
+ }, _callee9);
436
+ }));
437
+ return _ensureCategory.apply(this, arguments);
438
+ }
439
+ function validateDraft(input, kind) {
440
+ var draft = clone(input);
441
+ if (!draft || typeof draft.name !== 'string' || !draft.name.trim() || draft.name.length > 50) throw new Error('资源名称需为1至50字。');
442
+ if (!['model', 'hdri', 'material'].includes(kind) || !draft[kind]) throw new Error('资源参数无效。');
443
+ if (!Number.isFinite(draft.sort) || draft.sort < 0 || draft.sort > 99999) throw new Error('资源排序无效。');
444
+ for (var _i = 0, _arr = [draft.file, draft.cover].concat(_toConsumableArray(Object.values(((_draft$material = draft.material) === null || _draft$material === void 0 ? void 0 : _draft$material.maps) || {}))); _i < _arr.length; _i++) {
445
+ var _draft$material;
446
+ var file = _arr[_i];
447
+ if (file) resourceUrl(file.url);
448
+ }
449
+ if (JSON.stringify(draft).length > 200000) throw new Error('资源参数过大。');
450
+ return draft;
451
+ }
452
+ function saveResource(_x1, _x10) {
453
+ return _saveResource.apply(this, arguments);
454
+ }
455
+ function _saveResource() {
456
+ _saveResource = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(id, body) {
457
+ var _draft$cover, _draft$file, _previous$_row, _draft$cover2, _draft$cover3;
458
+ var state, previous, draft, c, revision, manifest, url, config, image, row, persisted;
459
+ return _regenerator().w(function (_context1) {
460
+ while (1) switch (_context1.n) {
461
+ case 0:
462
+ _context1.n = 1;
463
+ return catalog();
464
+ case 1:
465
+ state = _context1.v;
466
+ previous = id ? state.resources.find(function (r) {
467
+ return r.id === id;
468
+ }) : undefined;
469
+ if (!(id && !previous)) {
470
+ _context1.n = 2;
471
+ break;
472
+ }
473
+ throw new Error('资源已不存在,请刷新。');
474
+ case 2:
475
+ if (!(previous && previous.kind !== body.kind)) {
476
+ _context1.n = 3;
477
+ break;
478
+ }
479
+ throw new Error('不能更改资源类型。');
480
+ case 3:
481
+ draft = validateDraft(body.draft, body.kind);
482
+ if (!(!(previous === null || previous === void 0 ? void 0 : previous.builtinKey) && body.kind !== 'material' && !draft.file)) {
483
+ _context1.n = 4;
484
+ break;
485
+ }
486
+ throw new Error('请先上传资源文件。');
487
+ case 4:
488
+ if (!((previous === null || previous === void 0 ? void 0 : previous.builtinKey) && body.kind === 'model' && draft.file)) {
489
+ _context1.n = 5;
490
+ break;
491
+ }
492
+ throw new Error('内置模型不能替换文件,请新建模型资源。');
493
+ case 5:
494
+ _context1.n = 6;
495
+ return ensureCategory(draft.categoryId, body.kind, state);
496
+ case 6:
497
+ c = _context1.v;
498
+ draft.categoryId = c.id;
499
+ revision = Math.min(((previous === null || previous === void 0 ? void 0 : previous.revision) || 0) + 1, 999999999);
500
+ manifest = {
501
+ format: marker,
502
+ kind: body.kind,
503
+ draft: draft,
504
+ updatedAt: new Date().toISOString()
505
+ };
506
+ _context1.n = 7;
507
+ return upload(new Blob([JSON.stringify(manifest)], {
508
+ type: 'application/json'
509
+ }), 'resource.json');
510
+ case 7:
511
+ url = _context1.v;
512
+ config = JSON.stringify(_objectSpread({
513
+ format: marker,
514
+ kind: body.kind,
515
+ url: url,
516
+ revision: revision
517
+ }, (previous === null || previous === void 0 ? void 0 : previous.builtinKey) ? {
518
+ builtinKey: previous.builtinKey
519
+ } : {}));
520
+ if (!(config.length > 400)) {
521
+ _context1.n = 8;
522
+ break;
523
+ }
524
+ throw new Error('上传地址过长,超出现有资源配置容量,请使用较短的OSS访问域名。');
525
+ case 8:
526
+ image = ((_draft$cover = draft.cover) === null || _draft$cover === void 0 ? void 0 : _draft$cover.url) || ((_draft$file = draft.file) === null || _draft$file === void 0 ? void 0 : _draft$file.url) || '';
527
+ if (!(image.length > 255)) {
528
+ _context1.n = 9;
529
+ break;
530
+ }
531
+ throw new Error('资源地址超出现有图片地址字段容量。');
532
+ case 9:
533
+ row = {
534
+ configurationImgId: (previous === null || previous === void 0 ? void 0 : (_previous$_row = previous._row) === null || _previous$_row === void 0 ? void 0 : _previous$_row.configurationImgId) || 0,
535
+ configurationImgGroupId: Number(c.id.replace('legacy-group-', '')),
536
+ img: image,
537
+ name: draft.name.trim(),
538
+ width: ((_draft$cover2 = draft.cover) === null || _draft$cover2 === void 0 ? void 0 : _draft$cover2.width) || 0,
539
+ height: ((_draft$cover3 = draft.cover) === null || _draft$cover3 === void 0 ? void 0 : _draft$cover3.height) || 0,
540
+ previewWidthPercent: 100,
541
+ previewHeightPercent: 100,
542
+ config: config,
543
+ index: Math.round(draft.sort)
544
+ };
545
+ _context1.n = 10;
546
+ return call("".concat(images, "/AddOrUpdateConfigurationImg"), [row]);
547
+ case 10:
548
+ _context1.n = 11;
549
+ return pages("".concat(images, "/GetConfigurationImgPage"), {
550
+ configurationImgGroupId: row.configurationImgGroupId
551
+ });
552
+ case 11:
553
+ persisted = _context1.v.find(function (r) {
554
+ return r.config === config;
555
+ });
556
+ if (persisted) {
557
+ _context1.n = 12;
558
+ break;
559
+ }
560
+ throw new Error('保存已提交,但未能重新读取,请刷新核对后再操作。');
561
+ case 12:
562
+ return _context1.a(2, _objectSpread(_objectSpread({
563
+ id: "legacy-resource-".concat(persisted.configurationImgId),
564
+ kind: body.kind
565
+ }, (previous === null || previous === void 0 ? void 0 : previous.builtinKey) ? {
566
+ builtinKey: previous.builtinKey
567
+ } : {}), {}, {
568
+ draft: draft,
569
+ published: clone(draft),
570
+ revision: revision,
571
+ draftVersion: revision,
572
+ publishedDraftVersion: revision,
573
+ archived: false,
574
+ updatedAt: manifest.updatedAt
575
+ }));
576
+ }
577
+ }, _callee0);
578
+ }));
579
+ return _saveResource.apply(this, arguments);
580
+ }
581
+ var json = function json(value) {
582
+ var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
583
+ return {
584
+ status: status,
585
+ contentType: 'application/json',
586
+ text: JSON.stringify(value)
587
+ };
588
+ };
589
+ return /*#__PURE__*/function () {
590
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(payload) {
591
+ var _path, method, body, state, _name$split$pop, name, format, blob, hash, url, r, _state, record, c, _state2, existing, groupId, kind, _name, _detail, _detail2, _error$response2, detail, _error$response, _t, _t2, _t3, _t4, _t5, _t6, _t7, _t8;
592
+ return _regenerator().w(function (_context) {
593
+ while (1) switch (_context.p = _context.n) {
594
+ case 0:
595
+ _context.p = 0;
596
+ _path = String(payload.path || ''), method = String(payload.method || 'GET').toUpperCase();
597
+ body = payload.body ? JSON.parse(typeof payload.body === 'string' ? payload.body : '{}') : {};
598
+ if (!(_path === '/api/admin/session' && method === 'GET')) {
599
+ _context.n = 2;
600
+ break;
601
+ }
602
+ _context.n = 1;
603
+ return allGroups();
604
+ case 1:
605
+ return _context.a(2, json({
606
+ initialized: true,
607
+ user: {
608
+ id: 'business',
609
+ username: '已登录业务账号',
610
+ role: 'admin'
611
+ },
612
+ csrf: 'platform-bearer'
613
+ }));
614
+ case 2:
615
+ if (!(['/api/resources', '/api/admin/resources'].includes(_path) && method === 'GET')) {
616
+ _context.n = 4;
617
+ break;
618
+ }
619
+ _context.n = 3;
620
+ return catalog();
621
+ case 3:
622
+ state = _context.v;
623
+ return _context.a(2, json({
624
+ categories: state.categories,
625
+ resources: state.resources.map(function (_ref2) {
626
+ var _row = _ref2._row,
627
+ r = _objectWithoutProperties(_ref2, _excluded);
628
+ return _path === '/api/resources' ? _objectSpread(_objectSpread({}, r.published), {}, {
629
+ id: r.id,
630
+ kind: r.kind,
631
+ builtinKey: r.builtinKey,
632
+ revision: r.revision
633
+ }) : r;
634
+ })
635
+ }));
636
+ case 4:
637
+ if (!(_path.startsWith('/api/admin/files?') && method === 'POST')) {
638
+ _context.n = 9;
639
+ break;
640
+ }
641
+ name = new URL(_path, 'https://scada.invalid').searchParams.get('name') || '';
642
+ format = ((_name$split$pop = name.split('.').pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase().replace('jpeg', 'jpg')) || '';
643
+ blob = new Blob([payload.body]);
644
+ if (!(!['glb', 'hdr', 'exr', 'png', 'jpg', 'webp'].includes(format) || !blob.size || blob.size > (format === 'glb' ? 10000000 : ['hdr', 'exr'].includes(format) ? 32000000 : 2000000))) {
645
+ _context.n = 5;
646
+ break;
647
+ }
648
+ throw new Error('文件格式或大小不符合资源要求。');
649
+ case 5:
650
+ _t = Array;
651
+ _t2 = Uint8Array;
652
+ _t3 = crypto.subtle;
653
+ _context.n = 6;
654
+ return blob.arrayBuffer();
655
+ case 6:
656
+ _context.n = 7;
657
+ return _t3.digest.call(_t3, 'SHA-256', _context.v);
658
+ case 7:
659
+ _t4 = _context.v;
660
+ hash = _t.from.call(_t, new _t2(_t4)).map(function (b) {
661
+ return b.toString(16).padStart(2, '0');
662
+ }).join('');
663
+ _context.n = 8;
664
+ return upload(blob, name);
665
+ case 8:
666
+ url = _context.v;
667
+ return _context.a(2, json({
668
+ file: {
669
+ id: "".concat(hash, ".").concat(format),
670
+ name: name,
671
+ format: format,
672
+ size: blob.size,
673
+ url: url
674
+ }
675
+ }));
676
+ case 9:
677
+ r = /^\/api\/admin\/resources(?:\/([a-zA-Z0-9-]+))?$/.exec(_path);
678
+ if (!(r && (method === 'POST' && !r[1] || method === 'PUT' && r[1]))) {
679
+ _context.n = 11;
680
+ break;
681
+ }
682
+ _t5 = json;
683
+ _context.n = 10;
684
+ return saveResource(r[1], body);
685
+ case 10:
686
+ _t6 = _context.v;
687
+ return _context.a(2, _t5({
688
+ resource: _t6
689
+ }));
690
+ case 11:
691
+ if (!((r === null || r === void 0 ? void 0 : r[1]) && method === 'DELETE')) {
692
+ _context.n = 15;
693
+ break;
694
+ }
695
+ _context.n = 12;
696
+ return catalog();
697
+ case 12:
698
+ _state = _context.v;
699
+ record = _state.resources.find(function (x) {
700
+ return x.id === r[1];
701
+ });
702
+ if (record === null || record === void 0 ? void 0 : record._row) {
703
+ _context.n = 13;
704
+ break;
705
+ }
706
+ throw new Error('内置资源不可删除。');
707
+ case 13:
708
+ _context.n = 14;
709
+ return call("".concat(images, "/DeleteConfigurationImg"), [record._row.configurationImgId]);
710
+ case 14:
711
+ return _context.a(2, json({
712
+ ok: true
713
+ }));
714
+ case 15:
715
+ c = /^\/api\/admin\/categories(?:\/([a-zA-Z0-9-]+))?$/.exec(_path);
716
+ if (!(c && (method === 'POST' && !c[1] || method === 'PUT' && c[1] || method === 'DELETE' && c[1]))) {
717
+ _context.n = 25;
718
+ break;
719
+ }
720
+ _context.n = 16;
721
+ return catalog();
722
+ case 16:
723
+ _state2 = _context.v;
724
+ existing = _state2.categories.find(function (x) {
725
+ return x.id === c[1];
726
+ });
727
+ if (!(c[1] && !c[1].startsWith('legacy-group-'))) {
728
+ _context.n = 17;
729
+ break;
730
+ }
731
+ throw new Error('内置分类无需维护,请新建分组。');
732
+ case 17:
733
+ if (!(c[1] && !existing)) {
734
+ _context.n = 18;
735
+ break;
736
+ }
737
+ throw new Error('分组已不存在。');
738
+ case 18:
739
+ groupId = existing ? Number(existing.id.replace('legacy-group-', '')) : 0;
740
+ if (!(method === 'DELETE')) {
741
+ _context.n = 21;
742
+ break;
743
+ }
744
+ if (!_state2.resources.some(function (x) {
745
+ return x._row && x.draft.categoryId === c[1];
746
+ })) {
747
+ _context.n = 19;
748
+ break;
749
+ }
750
+ throw new Error('请先移走或删除分组中的资源。');
751
+ case 19:
752
+ _context.n = 20;
753
+ return call("".concat(groups, "/DeleteConfigurationImgGroup"), [groupId]);
754
+ case 20:
755
+ return _context.a(2, json({
756
+ ok: true
757
+ }));
758
+ case 21:
759
+ kind = body.kind, _name = String(body.name || '').trim();
760
+ if (!(!['model', 'hdri', 'material'].includes(kind) || existing && existing.kind !== kind || !_name || _name.length > 35)) {
761
+ _context.n = 22;
762
+ break;
763
+ }
764
+ throw new Error('分组名称需为1至35字,类型不能更改。');
765
+ case 22:
766
+ if (!_state2.categories.some(function (x) {
767
+ return x.kind === kind && x.name === _name && x.id !== c[1];
768
+ })) {
769
+ _context.n = 23;
770
+ break;
771
+ }
772
+ throw new Error('同类型分组名称已存在。');
773
+ case 23:
774
+ _context.n = 24;
775
+ return call("".concat(groups, "/AddOrUpdateConfigurationImgGroup"), [{
776
+ configurationImgGroupId: groupId,
777
+ configurationImgGroupName: "[3D:".concat(kind, "]").concat(_name),
778
+ isSystem: true,
779
+ index: Number(body.sort) || 0
780
+ }]);
781
+ case 24:
782
+ return _context.a(2, json({
783
+ ok: true
784
+ }));
785
+ case 25:
786
+ throw new Error('此资源操作不适用于现有二维资源接口。');
787
+ case 26:
788
+ _context.p = 26;
789
+ _t7 = _context.v;
790
+ detail = _t7 === null || _t7 === void 0 ? void 0 : _t7.data;
791
+ _context.p = 27;
792
+ if (!(_t7 === null || _t7 === void 0 ? void 0 : (_error$response = _t7.response) === null || _error$response === void 0 ? void 0 : _error$response.clone)) {
793
+ _context.n = 29;
794
+ break;
795
+ }
796
+ _context.n = 28;
797
+ return _t7.response.clone().json();
798
+ case 28:
799
+ detail = _context.v;
800
+ case 29:
801
+ _context.n = 31;
802
+ break;
803
+ case 30:
804
+ _context.p = 30;
805
+ _t8 = _context.v;
806
+ case 31:
807
+ return _context.a(2, json({
808
+ error: ((_detail = detail) === null || _detail === void 0 ? void 0 : _detail.error) || ((_detail2 = detail) === null || _detail2 === void 0 ? void 0 : _detail2.message) || (_t7 === null || _t7 === void 0 ? void 0 : _t7.message) || '资源操作失败,请重试。'
809
+ }, (_t7 === null || _t7 === void 0 ? void 0 : (_error$response2 = _t7.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.status) || 400));
810
+ case 32:
811
+ return _context.a(2);
812
+ }
813
+ }, _callee, null, [[27, 30], [0, 26]]);
814
+ }));
815
+ return function (_x11) {
816
+ return _ref.apply(this, arguments);
817
+ };
818
+ }();
819
+ }