crabatool 1.0.426 → 1.0.427

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/apis/data.js CHANGED
@@ -162,8 +162,7 @@ class data {
162
162
  }
163
163
 
164
164
  async reverseData(req, pageName, body) {
165
- var db = this._getDb(req);
166
- var oldEntity = await db.get(body.name, body.data.id);
165
+ var oldEntity = await this._getDb(req).get(body.name, body.data.id);
167
166
  if (!oldEntity) {
168
167
  crabatool.utils.end(res, {
169
168
  code: 404,
@@ -171,8 +170,6 @@ class data {
171
170
  });
172
171
  return;
173
172
  }
174
-
175
- await this.fillData(body.name, [oldEntity], db, true);
176
173
  //退回联动老数据
177
174
  var rt = await this.pageSaveToDataLinkage(req, body.name, pageName, oldEntity, null, true);
178
175
  return {
@@ -187,25 +184,25 @@ class data {
187
184
  var pageName = body.pageName;
188
185
  var db = this._getDb(req);
189
186
  var rtData = JSON.parse(JSON.stringify(body.data));
187
+ var name = body.name;
190
188
  if (body.data.id) {
191
189
  var oldData = await this.reverseData(req, pageName, body);
192
190
  if (!oldData) {
193
191
  return;
194
192
  }
195
- await this.buildDataPrimaryAndForeignKey(body.name, body.data, true);
193
+ await this.buildDataPrimaryAndForeignKey(name, body.data, true);
196
194
  //更新联动新数据
197
- await this.pageSaveToDataLinkage(req, body.name, pageName, body.data, oldData);
198
- var name = body.name;
195
+ await this.pageSaveToDataLinkage(req, name, pageName, body.data, oldData);
199
196
  await this._saveRefData(name, body.data, rtData, db);
200
- await db.update(body.name, body.data.id, body.data);
197
+ await db.update(name, body.data.id, body.data);
201
198
  newData = body.data;
202
199
  } else {
203
200
  //提前制定ID
204
201
  body.data.id = cuid.newCuidString()
205
- await this.buildDataPrimaryAndForeignKey(body.name, body.data);
206
- await this.pageSaveToDataLinkage(req, body.name, pageName, body.data)
202
+ await this.buildDataPrimaryAndForeignKey(name, body.data);
203
+ await this.pageSaveToDataLinkage(req, name, pageName, body.data)
207
204
  await this._saveRefData(name, body.data, rtData, db);
208
- newData = await db.create(body.name, body.data);
205
+ newData = await db.create(name, body.data);
209
206
  }
210
207
 
211
208
  crabatool.utils.end(res, {
@@ -300,7 +297,7 @@ class data {
300
297
  //从原始数据中获取对应字段的数据
301
298
  var targetRef = _this.findFormateItem(item.filter.refField)
302
299
  var targetRefField = _this.findFormateItem(`#[${item.ref}.${item.field}]`)
303
- var targetValue = _this.findItemMapData(name, crabatool.stringUtils.getFullPinyinCode(item.ref), data, new Set([...targetRef, ...targetRefField, `${item.ref}.id`]));
300
+ var targetValue = _this.findItemMapData(name, crabatool.stringUtils.getFullPinyinCode(item.ref), data, new Set([...targetRef, ...targetRefField]));
304
301
  var refFieldName = this.matchFields(item.filter.refField)[0];
305
302
  var refFieldNamePy = crabatool.stringUtils.getFullPinyinCode(refFieldName);
306
303
  var targetArray = refFieldNamePy.split('.')
@@ -328,13 +325,7 @@ class data {
328
325
  //传入了老数据,当前计算的值可以直接取老数据的对应值,因为它已经排除本单
329
326
  var oldDataTemp = oldData[name][refNamePy];
330
327
  if (oldDataTemp instanceof Array) {
331
- target[refNamePy][fieldNamePy] = 0;
332
- for(var m = 0 ; m < oldDataTemp.length; m++){
333
- if(oldDataTemp[m].id == target[refNamePy].id){
334
- target[refNamePy][fieldNamePy] = oldDataTemp[m][fieldNamePy];
335
- break;
336
- }
337
- }
328
+ target[refNamePy][fieldNamePy] = oldDataTemp[0][fieldNamePy];//强制取第一行
338
329
  } else {
339
330
  target[refNamePy][fieldNamePy] = oldDataTemp[fieldNamePy] ? oldDataTemp[fieldNamePy] : 0;
340
331
  }
package/index.js CHANGED
@@ -11,6 +11,7 @@ exports.cuid = require('./lib/cuid.js');
11
11
  exports.JSONCRUD = require('./lib/jsoncrud.js');
12
12
  exports.DbHelper = require('./lib/db/dbHelper.js');
13
13
  exports.StringBuilder = require('./lib/stringBuilder.js');
14
+ exports.hashUtils = require('./tool/hash.js');
14
15
 
15
16
  start.initArgs();
16
17
 
@@ -51,6 +52,22 @@ function checkFast(args) {
51
52
 
52
53
  config.progress = 0; // 通过命令行启动,默认不显示进度条
53
54
 
55
+ // 上传ngp的图标库和皮肤
56
+ if (args.includes('-uploadSkin')) {
57
+ start.bindAndCheckConfig('-skinPath');
58
+ start.bindAndCheckConfig('-version');
59
+ require('./tool/ngpSkinUtils.js').upload();
60
+ return false;
61
+ }
62
+
63
+ // 更新ngp的图标库和皮肤
64
+ if (args.includes('-updateSkin')) {
65
+ start.bindAndCheckConfig('-skinPath');
66
+ start.bindAndCheckConfig('-version');
67
+ require('./tool/ngpSkinUtils.js').update();
68
+ return false;
69
+ }
70
+
54
71
  if (args.includes('-checkjs')) {
55
72
  start.bindConfigByArgv('-ignoreFiles', 'array');
56
73
  start.bindConfigByArgv('-cssFiles', 'array');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.426",
3
+ "version": "1.0.427",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
package/res/login.html CHANGED
@@ -11,6 +11,7 @@
11
11
  <body>
12
12
  <script>
13
13
  var modeName = '${modName}'; // 按各组的模块名称修改
14
+ var rv = new Date().getTime();
14
15
 
15
16
  function startPage() { // 供agency内部调用
16
17
  var authorization = $common.getCookie('ngp-authorization');
@@ -36,8 +37,8 @@
36
37
  }
37
38
 
38
39
  var srcs = [];
39
- srcs.push('shell/js/help.plug.js?rv=' + Math.random());
40
- srcs.push('shell/js/init.js?rv=' + Math.random());
40
+ srcs.push('shell/js/help.plug.js?_v_=' + rv);
41
+ srcs.push('shell/js/init.js?_v_=' + rv);
41
42
  $common.loadScript(srcs, function() {
42
43
  showMainPage();
43
44
  });
@@ -88,11 +89,11 @@
88
89
  document.getElementsByTagName('HEAD')[0].appendChild(script);
89
90
  }
90
91
 
91
- var agencyUrl = 'js/agency.js?vc=' + (new Date()).getTime(); // 加时间戳防止浏览器缓存
92
+ var agencyUrl = 'js/agency.js?_v_=' + rv; // 加时间戳防止浏览器缓存
92
93
  loadScript(agencyUrl, function() {
93
94
  $agency.load(['js/craba.min.js',
94
95
  'js/crabaEx.min.js',
95
- 'js/math.min.js',
96
+ 'js/math.min.js?_v_=5.2.0',
96
97
  'js/crabaNgp.js'
97
98
  ], {}, startPage); // 这里写死首页脚本,agency内部使用。所有脚本由agency内部版本号防止浏览器缓存
98
99
  });
package/tool/hash.js CHANGED
@@ -87,4 +87,12 @@ function makeHash(str, name) {
87
87
  const hash = crypto.createHash(name);
88
88
  hash.update(str);
89
89
  return hash.digest('base64');
90
+ }
91
+
92
+ module.exports.makeHash = function(filePath) {
93
+ if (!fs.existsSync(filePath)) {
94
+ return 0;
95
+ }
96
+ var content = fs.readFileSync(filePath);
97
+ return makeHash(content, 'sha384');
90
98
  }
@@ -0,0 +1,136 @@
1
+
2
+ var config = require('../lib/config.js');
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var utils = require('../lib/utils.js');
6
+ var axios = require('axios');
7
+ const FormData = require('form-data');
8
+ var _zipName = path.join(config.TempPath, 'uploadShellSkin', config.version + '.zip');
9
+ var _zipName2 = path.join(config.TempPath, 'updateShellSkin', config.version + '.zip');
10
+ var ngpSkinCache = path.join(config.TempPath, 'ngpSkinCache');
11
+
12
+ // 上传图标库
13
+ module.exports.upload = function() {
14
+ doZip();
15
+ }
16
+
17
+ function doZip() {
18
+ utils.mkdirsSync(_zipName);
19
+
20
+ // 将demo文件一起打包
21
+ utils.copyFiles(path.join(_jsPath, 'demo'), _tempPath);
22
+
23
+ // 打包平台资源
24
+ utils.zip(config.skinPath, _zipName, function() {
25
+ console.log('压缩完成');
26
+ doUpload(); // 根据配置上传到服务端指定路径(分支)下
27
+ }, { ignoreBase: true }); // 忽略跟路径
28
+ }
29
+
30
+ function doUpload() {
31
+ console.log('上传资源');
32
+ var host = config.host || config.SourceHost;
33
+ var apis = utils.joinPath(host, '/apis/publish/saveSkin');
34
+
35
+ console.log(apis);
36
+
37
+ const formData = new FormData();
38
+ formData.append('my_field', 'my value');
39
+ formData.append('my_file', fs.createReadStream(_zipName));
40
+ var headers = formData.getHeaders();
41
+
42
+ axios({
43
+ method: 'POST',
44
+ url: apis,
45
+ data: formData,
46
+ headers: {
47
+ ...headers,
48
+ version: config.version,
49
+ token: 'wssf2021' // 临时授权码
50
+ }
51
+ }).then(function(response) {
52
+ console.log(response.data);
53
+ doEnd();
54
+ }).catch(function(err) {
55
+ utils.postWeebhooks('shell皮肤发布失败');
56
+ console.log(err);
57
+ });
58
+ }
59
+
60
+ function doEnd() {
61
+ var text = new Date().toString() + "shell皮肤和图标库打包完成,上传资源到" + config.version;
62
+ console.log(text);
63
+ utils.postWeebhooks(text);
64
+ }
65
+
66
+
67
+
68
+ // 更新图标库
69
+ module.exports.update = function() {
70
+ if (fs.existsSync(_zipName2)) {
71
+ checkUpdate();
72
+ } else {
73
+ doDownload();
74
+ }
75
+ }
76
+
77
+ function checkUpdate() {
78
+ console.log('检查皮肤是否有更新');
79
+
80
+ var host = config.host || config.SourceHost;
81
+ var apis = utils.joinPath(host, '/apis/publish/checkSkin');
82
+ var headers = formData.getHeaders();
83
+ var hashUtils = require('./hash.js');
84
+
85
+ axios({
86
+ method: 'POST',
87
+ url: apis,
88
+ data: {
89
+ version: config.version,
90
+ hash: hashUtils.makeHash(_zipName2)
91
+ },
92
+ headers: {
93
+ ...headers,
94
+ version: config.version,
95
+ token: 'wssf2021' // 临时授权码
96
+ }
97
+ }).then(function(response) {
98
+ //console.log(response.data);
99
+ if (response.data.code == 200) {
100
+ doDownload();
101
+ } else {
102
+ console.log(response.data.msg);
103
+ }
104
+ }).catch(function(err) {
105
+ console.log(err);
106
+ });
107
+ }
108
+
109
+ function doDownload() {
110
+ console.log('开始下载皮肤和图标库');
111
+ utils.downloadFile(getZipFileUrl(), _zipName2, downloadOk);
112
+ }
113
+
114
+ function getZipFileUrl() {
115
+ return utils.joinPath(config.SourceHost, "setup/shellSkin/" + config.version + ".zip");
116
+ }
117
+
118
+ function downloadOk(filePath) {
119
+ if (!fs.existsSync(filePath)) {// 检查文件
120
+ console.log(":::服务不可用,拉取皮肤文件失败,请联系平台管理员:::");
121
+ return;
122
+ }
123
+
124
+ console.log('皮肤数据包下载完成');
125
+ utils.unzip(filePath, ngpSkinCache, _copyFiles);
126
+ }
127
+
128
+ function _copyFiles() {
129
+ var ignores = [];
130
+ console.log("拷贝文件中..");
131
+ utils.copyFiles(ngpSkinCache, config.skinPath, ignores, function(fileName) {
132
+ utils.debug('拷贝文件', fileName);
133
+ });
134
+
135
+ console.log('图标库和皮肤更新完成');
136
+ }