next-admin-svr 0.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.
- package/LICENSE +9 -0
- package/README.md +26 -0
- package/index.js +1 -0
- package/init.js +1 -0
- package/lib/db/complexity-db.js +120 -0
- package/lib/db/component-statistics-db.js +136 -0
- package/lib/db/image-db.js +48 -0
- package/lib/db/white-user-next-db.js +49 -0
- package/lib/index.js +38 -0
- package/lib/routes/component-statistics-open.js +18 -0
- package/lib/routes/component-statistics.js +208 -0
- package/lib/routes/cyclomatic-complexity-open.js +16 -0
- package/lib/routes/cyclomatic-complexity.js +130 -0
- package/lib/routes/image-open.js +153 -0
- package/lib/routes/image.js +302 -0
- package/lib/routes/pipeline.js +78 -0
- package/lib/routes/white-user-open.js +68 -0
- package/lib/routes/white-user.js +310 -0
- package/lib/utils/image/config.js +91 -0
- package/lib/utils/image/index.js +88 -0
- package/lib/utils/image/upload-core.js +103 -0
- package/lib/utils/init.js +28 -0
- package/lib/utils/tinypng.js +76 -0
- package/lib/utils/white-user/config.js +71 -0
- package/lib/utils/white-user/cron.js +30 -0
- package/lib/utils/white-user/update-cos.js +223 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 novlan1
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), 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:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Next Admin Server
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://img.shields.io/npm/dw/@plugin-light/next-admin-svr">
|
|
5
|
+
<img src="https://img.shields.io/npm/unpacked-size/@plugin-light/next-admin-svr">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/@plugin-light/next-admin-svr">
|
|
7
|
+
<img src="https://img.shields.io/npm/l/@plugin-light/next-admin-svr">
|
|
8
|
+
<img src="https://img.shields.io/github/last-commit/novlan1/plugin-light">
|
|
9
|
+
<img src="https://img.shields.io/github/created-at/novlan1/plugin-light">
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
Next Admin 服务端核心内容。
|
|
13
|
+
|
|
14
|
+
## 1. 作者
|
|
15
|
+
|
|
16
|
+
**novlan1**
|
|
17
|
+
|
|
18
|
+
## 2. 如何使用
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const { imageRouter } = require('next-admin-svr');
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## 3. 更新日志
|
|
25
|
+
|
|
26
|
+
[点此查看](./CHANGELOG.md)
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/index');
|
package/init.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/utils/init');
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const { mongodb: mongo } = require('../utils/init').coreModule.data;
|
|
2
|
+
|
|
3
|
+
const complexityDB = {};
|
|
4
|
+
const COLLECTION = 'complexity';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
complexityDB.getAll = async (where = {}) => {
|
|
8
|
+
const db = await mongo.connect();
|
|
9
|
+
const result = await mongo.get(db, COLLECTION, where);
|
|
10
|
+
db.close();
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
complexityDB.getList = async (start, limit, sort, where) => {
|
|
15
|
+
const db = await mongo.connect();
|
|
16
|
+
const result = await mongo.get(db, COLLECTION, where, sort, start, limit);
|
|
17
|
+
db.close();
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
complexityDB.get = async function (where = {}, start, limit, sort = {}) {
|
|
23
|
+
const db = await mongo.connect();
|
|
24
|
+
const result = await mongo.get(db, COLLECTION, where, sort, start, limit);
|
|
25
|
+
db.close();
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
complexityDB.getFromPrimaryKey = async function ({
|
|
30
|
+
primaryKey,
|
|
31
|
+
}) {
|
|
32
|
+
const db = await mongo.connect();
|
|
33
|
+
const where = { primaryKey };
|
|
34
|
+
const result = await mongo.get(db, COLLECTION, where, { start: -1 }, 0, 50);
|
|
35
|
+
db.close();
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
complexityDB.getCount = async (where = {}) => {
|
|
40
|
+
const db = await mongo.connect();
|
|
41
|
+
const result = await mongo.count(db, COLLECTION, where);
|
|
42
|
+
db.close();
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
complexityDB.insert = async (project) => {
|
|
47
|
+
const db = await mongo.connect();
|
|
48
|
+
if (!Array.isArray(project)) {
|
|
49
|
+
project = [project];
|
|
50
|
+
}
|
|
51
|
+
const validProjects = [];
|
|
52
|
+
const existProjects = [];
|
|
53
|
+
for (const item of project) {
|
|
54
|
+
if (!item.primaryKey) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const exist = await complexityDB.getFromPrimaryKey({
|
|
59
|
+
primaryKey: item.primaryKey,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!exist || !exist.length) {
|
|
63
|
+
validProjects.push({
|
|
64
|
+
...item,
|
|
65
|
+
createTime: Date.now(),
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
existProjects.push(item);
|
|
69
|
+
await mongo.updateOne(db, COLLECTION, {
|
|
70
|
+
primaryKey: item.primaryKey,
|
|
71
|
+
}, {
|
|
72
|
+
...item,
|
|
73
|
+
updateTime: Date.now(),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (validProjects.length) {
|
|
79
|
+
await mongo.insert(db, COLLECTION, validProjects);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
db.close();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
complexityDB.update = async function (projectKey, time, record) {
|
|
86
|
+
const db = await mongo.connect();
|
|
87
|
+
await mongo.update(db, COLLECTION, { projectKey, time }, record);
|
|
88
|
+
db.close();
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
complexityDB.delete = async (where) => {
|
|
92
|
+
const db = await mongo.connect();
|
|
93
|
+
await mongo.delete(db, COLLECTION, where);
|
|
94
|
+
db.close();
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
complexityDB.statistics = async (aggregateType, match = {}) => {
|
|
98
|
+
const db = await mongo.connect();
|
|
99
|
+
const res = await mongo.aggregate(db, COLLECTION, [
|
|
100
|
+
{
|
|
101
|
+
$match: match,
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
$group: {
|
|
105
|
+
_id: '$date',
|
|
106
|
+
count: { $sum: '$count' },
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
$sort: {
|
|
111
|
+
_id: 1,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
db.close();
|
|
116
|
+
return res;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
module.exports = complexityDB;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// const mongo = require('./mongodb');
|
|
2
|
+
const { mongodb: mongo } = require('../utils/init').coreModule.data;
|
|
3
|
+
|
|
4
|
+
const componentDB = {};
|
|
5
|
+
const COLLECTION = 'component';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
componentDB.getAll = async (where = {}) => {
|
|
9
|
+
const db = await mongo.connect();
|
|
10
|
+
const result = await mongo.get(db, COLLECTION, where);
|
|
11
|
+
db.close();
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
componentDB.getList = async (start, limit, sort, where) => {
|
|
16
|
+
const db = await mongo.connect();
|
|
17
|
+
const result = await mongo.get(db, COLLECTION, where, sort, start, limit);
|
|
18
|
+
// await mongo.delete(db, COLLECTION, {
|
|
19
|
+
// component: '//',
|
|
20
|
+
// });
|
|
21
|
+
db.close();
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
componentDB.get = async function (where = {}, start, limit, sort = {}) {
|
|
27
|
+
const db = await mongo.connect();
|
|
28
|
+
const result = await mongo.get(db, COLLECTION, where, sort, start, limit);
|
|
29
|
+
db.close();
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
componentDB.getFromPrimaryKey = async function ({
|
|
34
|
+
primaryKey,
|
|
35
|
+
}) {
|
|
36
|
+
const db = await mongo.connect();
|
|
37
|
+
const where = { primaryKey };
|
|
38
|
+
const result = await mongo.get(db, COLLECTION, where, { start: -1 }, 0, 50);
|
|
39
|
+
db.close();
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
componentDB.getCount = async (where = {}) => {
|
|
44
|
+
const db = await mongo.connect();
|
|
45
|
+
const result = await mongo.count(db, COLLECTION, where);
|
|
46
|
+
db.close();
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
componentDB.insert = async (project) => {
|
|
51
|
+
const db = await mongo.connect();
|
|
52
|
+
if (!Array.isArray(project)) {
|
|
53
|
+
project = [project];
|
|
54
|
+
}
|
|
55
|
+
const validProjects = [];
|
|
56
|
+
const existProjects = [];
|
|
57
|
+
for (const item of project) {
|
|
58
|
+
if (!item.primaryKey) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const exist = await componentDB.getFromPrimaryKey({
|
|
63
|
+
primaryKey: item.primaryKey,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (!exist || !exist.length) {
|
|
67
|
+
validProjects.push({
|
|
68
|
+
...item,
|
|
69
|
+
createTime: Date.now(),
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
existProjects.push(item);
|
|
73
|
+
await mongo.updateOne(db, COLLECTION, {
|
|
74
|
+
primaryKey: item.primaryKey,
|
|
75
|
+
}, {
|
|
76
|
+
...item,
|
|
77
|
+
updateTime: Date.now(),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (validProjects.length) {
|
|
83
|
+
await mongo.insert(db, COLLECTION, validProjects);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
db.close();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
componentDB.update = async function (projectKey, time, record) {
|
|
90
|
+
const db = await mongo.connect();
|
|
91
|
+
await mongo.update(db, COLLECTION, { projectKey, time }, record);
|
|
92
|
+
db.close();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
componentDB.delete = async (where) => {
|
|
96
|
+
const db = await mongo.connect();
|
|
97
|
+
await mongo.delete(db, COLLECTION, where);
|
|
98
|
+
db.close();
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
componentDB.statistics = async (aggregateType, match = {}) => {
|
|
102
|
+
const db = await mongo.connect();
|
|
103
|
+
const res = await mongo.aggregate(db, COLLECTION, [
|
|
104
|
+
{
|
|
105
|
+
$match: match,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
$group: {
|
|
109
|
+
_id: {
|
|
110
|
+
libraryName: '$libraryName',
|
|
111
|
+
date: '$date',
|
|
112
|
+
},
|
|
113
|
+
count: { $sum: '$count' },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
$project: {
|
|
118
|
+
libraryName: '$_id.libraryName',
|
|
119
|
+
date: '$_id.date',
|
|
120
|
+
count: 1,
|
|
121
|
+
_id: 0,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
$sort: {
|
|
126
|
+
date: 1,
|
|
127
|
+
libraryName: 1,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
]);
|
|
131
|
+
db.close();
|
|
132
|
+
return res;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
module.exports = componentDB;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { mongodb: mongo } = require('../utils/init').coreModule.data;
|
|
2
|
+
|
|
3
|
+
const imageDB = {};
|
|
4
|
+
const COLLECTION = 'image';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
imageDB.getAll = async (where = {}) => {
|
|
8
|
+
const db = await mongo.connect();
|
|
9
|
+
const result = await mongo.get(db, COLLECTION, where);
|
|
10
|
+
db.close();
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
imageDB.get = async function (where, start, limit, sort = {}) {
|
|
15
|
+
const db = await mongo.connect();
|
|
16
|
+
const result = await mongo.get(db, COLLECTION, where, sort, start, limit);
|
|
17
|
+
db.close();
|
|
18
|
+
return result;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
imageDB.getCount = async (where = {}) => {
|
|
22
|
+
const db = await mongo.connect();
|
|
23
|
+
const result = await mongo.count(db, COLLECTION, where);
|
|
24
|
+
db.close();
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
imageDB.update = async (where, record) => {
|
|
29
|
+
const db = await mongo.connect();
|
|
30
|
+
await mongo.update(db, COLLECTION, where, record);
|
|
31
|
+
db.close();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
imageDB.insert = async (project) => {
|
|
36
|
+
const db = await mongo.connect();
|
|
37
|
+
await mongo.insert(db, COLLECTION, [project]);
|
|
38
|
+
db.close();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
imageDB.delete = async (where) => {
|
|
42
|
+
const db = await mongo.connect();
|
|
43
|
+
await mongo.delete(db, COLLECTION, where);
|
|
44
|
+
db.close();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
module.exports = imageDB;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const { mongodb: mongo } = require('../utils/init').coreModule.data;
|
|
2
|
+
|
|
3
|
+
const WhiteUserDB = {};
|
|
4
|
+
const COLLECTION = 'whiteUser';
|
|
5
|
+
|
|
6
|
+
WhiteUserDB.getList = async function ({
|
|
7
|
+
start, limit, where,
|
|
8
|
+
}) {
|
|
9
|
+
const db = await mongo.connect();
|
|
10
|
+
const result = await mongo.get(db, COLLECTION, where, { startTime: -1 }, start, limit);
|
|
11
|
+
db.close();
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
WhiteUserDB.getCount = async (where = {}) => {
|
|
16
|
+
const db = await mongo.connect();
|
|
17
|
+
const result = await mongo.count(db, COLLECTION, where);
|
|
18
|
+
db.close();
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
WhiteUserDB.addItem = async function (info) {
|
|
24
|
+
const db = await mongo.connect();
|
|
25
|
+
await mongo.insert(db, COLLECTION, [info]);
|
|
26
|
+
db.close();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
WhiteUserDB.deleteItem = async function (where) {
|
|
30
|
+
const db = await mongo.connect();
|
|
31
|
+
await mongo.delete(db, COLLECTION, where);
|
|
32
|
+
db.close();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
WhiteUserDB.updateItem = async function (where, record) {
|
|
36
|
+
const db = await mongo.connect();
|
|
37
|
+
await mongo.update(db, COLLECTION, where, record);
|
|
38
|
+
db.close();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
WhiteUserDB.updateManyItem = async function (where, record) {
|
|
43
|
+
const db = await mongo.connect();
|
|
44
|
+
await mongo.updateMany(db, COLLECTION, where, record);
|
|
45
|
+
db.close();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
module.exports = WhiteUserDB;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const componentStatisticsRouter = require('./routes/component-statistics');
|
|
2
|
+
const componentStatisticsOpenRouter = require('./routes/component-statistics-open');
|
|
3
|
+
|
|
4
|
+
const cyclomaticComplexityRouter = require('./routes/cyclomatic-complexity');
|
|
5
|
+
const cyclomaticComplexityOpenRouter = require('./routes/cyclomatic-complexity-open');
|
|
6
|
+
|
|
7
|
+
const imageRouter = require('./routes/image');
|
|
8
|
+
const imageOpenRouter = require('./routes/image-open');
|
|
9
|
+
|
|
10
|
+
const pipelineRouter = require('./routes/pipeline');
|
|
11
|
+
|
|
12
|
+
const whiteUserRouter = require('./routes/white-user');
|
|
13
|
+
const whiteUserOpenRouter = require('./routes/white-user-open');
|
|
14
|
+
|
|
15
|
+
const { coreModule } = require('./utils/init');
|
|
16
|
+
|
|
17
|
+
const { createUpdateWhiteUserCosCron } = require('./utils/white-user/cron');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
componentStatisticsOpenRouter,
|
|
22
|
+
componentStatisticsRouter,
|
|
23
|
+
|
|
24
|
+
cyclomaticComplexityOpenRouter,
|
|
25
|
+
cyclomaticComplexityRouter,
|
|
26
|
+
|
|
27
|
+
imageRouter,
|
|
28
|
+
imageOpenRouter,
|
|
29
|
+
|
|
30
|
+
pipelineRouter,
|
|
31
|
+
|
|
32
|
+
whiteUserOpenRouter,
|
|
33
|
+
whiteUserRouter,
|
|
34
|
+
|
|
35
|
+
coreModule,
|
|
36
|
+
|
|
37
|
+
createUpdateWhiteUserCosCron,
|
|
38
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
|
|
3
|
+
const router = express.Router();
|
|
4
|
+
const componentDB = require('../db/component-statistics-db');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
router.post('/report', async (req, res) => {
|
|
8
|
+
const { data } = req.body;
|
|
9
|
+
console.log('[report] data', data);
|
|
10
|
+
componentDB.insert(data);
|
|
11
|
+
res.send({ r: 0 });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
module.exports = router;
|
|
16
|
+
// 原始 tabMap 结构如下:
|
|
17
|
+
// { time: { pressUI: { projectA:{ componentA: 3, componentB: 4, }, projectB: { componentA: 3, componentB: 4, }, }, }
|
|
18
|
+
// 入库的时候已经扁平
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
const { timeStampFormat } = require('t-comm');
|
|
2
|
+
const express = require('express');
|
|
3
|
+
const router = express.Router();
|
|
4
|
+
const { ObjectId } = require('mongodb');
|
|
5
|
+
|
|
6
|
+
const componentDB = require('../db/component-statistics-db');
|
|
7
|
+
const { operation: operationTool } = require('../utils/init').coreModule.data;
|
|
8
|
+
const { Auth, RET_CODE } = require('../utils/init').coreModule.data.auth;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function parseSearchText(text = '') {
|
|
12
|
+
text = text.replace(/\\/g, '');
|
|
13
|
+
|
|
14
|
+
if (!text.includes(':')) {
|
|
15
|
+
return {
|
|
16
|
+
$or: [
|
|
17
|
+
{ project: { $regex: text } },
|
|
18
|
+
{ component: { $regex: text } },
|
|
19
|
+
{ libraryName: { $regex: text } },
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const keys = [
|
|
24
|
+
['project:', 'project'],
|
|
25
|
+
['component:', 'component'],
|
|
26
|
+
['library:', 'libraryName'],
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const result = [];
|
|
30
|
+
text.replace(/\s+/, '').split(/[;,,]/)
|
|
31
|
+
.map(item => item.trim())
|
|
32
|
+
.map((item) => {
|
|
33
|
+
for (const key of keys) {
|
|
34
|
+
if (item.startsWith(key[0])) {
|
|
35
|
+
result.push({ [key[1]]: { $regex: item.replace(key[0], '') } });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
$and: result,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
router.get('/', async (req, res) => {
|
|
46
|
+
if (!(await Auth.can(req, 'query', 'componentStatistics'))) {
|
|
47
|
+
res.send({ r: RET_CODE.PERMISSION_DENY, msg: '没有权限' });
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const {
|
|
52
|
+
start,
|
|
53
|
+
limit,
|
|
54
|
+
searchText,
|
|
55
|
+
date,
|
|
56
|
+
sortBy,
|
|
57
|
+
descending,
|
|
58
|
+
} = req.query;
|
|
59
|
+
let condition = {};
|
|
60
|
+
|
|
61
|
+
if (date) {
|
|
62
|
+
condition.date = date;
|
|
63
|
+
}
|
|
64
|
+
if (searchText) {
|
|
65
|
+
condition = {
|
|
66
|
+
...condition,
|
|
67
|
+
...parseSearchText(searchText),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const staffName = req.header('staffname') ? req.header('staffname') : 'developer';
|
|
72
|
+
|
|
73
|
+
await operationTool.addByMapParam({
|
|
74
|
+
staffName,
|
|
75
|
+
type: 'GET_COMPONENT',
|
|
76
|
+
desc: [
|
|
77
|
+
start ? `Start:${start}` : '',
|
|
78
|
+
limit ? `Limit:${limit}` : '',
|
|
79
|
+
searchText ? `SearchText:${searchText}` : '',
|
|
80
|
+
date ? `Date:${date}` : '',
|
|
81
|
+
sortBy ? `SortBy:${sortBy}` : '',
|
|
82
|
+
descending ? `Descending:${descending}` : '',
|
|
83
|
+
].filter(Boolean).join(','),
|
|
84
|
+
status: 'success',
|
|
85
|
+
extra: {
|
|
86
|
+
start,
|
|
87
|
+
limit,
|
|
88
|
+
searchText,
|
|
89
|
+
date,
|
|
90
|
+
sortBy,
|
|
91
|
+
descending,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
let sort = {
|
|
97
|
+
createTime: -1,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
if (sortBy) {
|
|
101
|
+
sort = {
|
|
102
|
+
[sortBy]: descending == '1' ? -1 : 1,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const total = await componentDB.getCount(condition);
|
|
107
|
+
const list = await componentDB.getList(start, limit, sort, condition);
|
|
108
|
+
res.send({ r: 0, list, total });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
router.post('/delete', async (req, res) => {
|
|
112
|
+
if (!(await Auth.can(req, 'delete', 'componentStatistics'))) {
|
|
113
|
+
res.send({ r: RET_CODE.PERMISSION_DENY, msg: '没有权限' });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const { id } = req.body;
|
|
117
|
+
await componentDB.delete({ _id: ObjectId(id) });
|
|
118
|
+
res.send({ r: 0 });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
router.get('/line', async (req, res) => {
|
|
123
|
+
if (!(await Auth.can(req, 'query', 'statistics'))) {
|
|
124
|
+
res.send({ r: RET_CODE.PERMISSION_DENY, msg: '没有权限' });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
const {
|
|
130
|
+
dateRange,
|
|
131
|
+
type,
|
|
132
|
+
searchText,
|
|
133
|
+
} = req.query;
|
|
134
|
+
const startDate = dateRange[0];
|
|
135
|
+
const endDate = dateRange[1];
|
|
136
|
+
const staffName = req.header('staffname') ? req.header('staffname') : 'developer';
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
await operationTool.addByMapParam({
|
|
140
|
+
staffName,
|
|
141
|
+
type: 'GET_COMPONENT_LINE',
|
|
142
|
+
desc: [
|
|
143
|
+
`StartDate:${startDate || '-'}`,
|
|
144
|
+
`EndDate:${endDate || '-'}`,
|
|
145
|
+
`Type:${type || '-'}`,
|
|
146
|
+
`SearchText:${searchText || '-'}`,
|
|
147
|
+
].join(','),
|
|
148
|
+
status: 'success',
|
|
149
|
+
extra: {
|
|
150
|
+
dateRange,
|
|
151
|
+
type,
|
|
152
|
+
searchText,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
let match = {
|
|
158
|
+
date: {
|
|
159
|
+
$gte: startDate,
|
|
160
|
+
$lte: endDate,
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
if (type && type !== 'ALL') {
|
|
164
|
+
match.type = type;
|
|
165
|
+
}
|
|
166
|
+
if (searchText) {
|
|
167
|
+
match = {
|
|
168
|
+
...match,
|
|
169
|
+
...parseSearchText(searchText),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const dataBaseDate = await componentDB.statistics({
|
|
174
|
+
}, match);
|
|
175
|
+
|
|
176
|
+
const dates = [];
|
|
177
|
+
for (let d = new Date(startDate); d <= new Date(endDate); d.setDate(d.getDate() + 1)) {
|
|
178
|
+
dates.push(timeStampFormat(d, 'yyyy-MM-dd'));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const obj = dataBaseDate.reduce((acc, item) => ({
|
|
182
|
+
...acc,
|
|
183
|
+
[item.libraryName]: {
|
|
184
|
+
...(acc[item.libraryName] || {}),
|
|
185
|
+
[item.date]: item.count,
|
|
186
|
+
},
|
|
187
|
+
}), {});
|
|
188
|
+
|
|
189
|
+
const data = Object.keys(obj).reduce((acc, libraryName) => {
|
|
190
|
+
const value = obj[libraryName];
|
|
191
|
+
const data = dates.map(date => value[date]);
|
|
192
|
+
return [
|
|
193
|
+
...acc,
|
|
194
|
+
{
|
|
195
|
+
libraryName,
|
|
196
|
+
data,
|
|
197
|
+
},
|
|
198
|
+
];
|
|
199
|
+
}, []);
|
|
200
|
+
|
|
201
|
+
res.json({
|
|
202
|
+
r: 0,
|
|
203
|
+
data,
|
|
204
|
+
dates,
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
module.exports = router;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const express = require('express');
|
|
2
|
+
|
|
3
|
+
const router = express.Router();
|
|
4
|
+
const complexityDB = require('../db/complexity-db');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
router.post('/report', async (req, res) => {
|
|
8
|
+
const { data } = req.body;
|
|
9
|
+
console.log('[report] data', data);
|
|
10
|
+
complexityDB.insert(data);
|
|
11
|
+
res.send({ r: 0 });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
module.exports = router;
|
|
16
|
+
// { lessThan5: 1, greaterThan35: 1, project: '', date: '2025-12-04', funcTotal, fileTotal, tokenTotal, nLocTotal, locTotal }
|