@shun-js/vicvic-server 0.1.0
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/app.js +47 -0
- package/package.json +35 -0
- package/server/log-options.js +34 -0
- package/server/util/check.js +23 -0
- package/server/util/feishu.js +63 -0
package/app.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// config
|
|
2
|
+
const { parseServerConfig } = require("@shun-js/shun-config");
|
|
3
|
+
|
|
4
|
+
// init
|
|
5
|
+
(async () => {
|
|
6
|
+
// config
|
|
7
|
+
const config = await parseServerConfig(process.argv);
|
|
8
|
+
if (!config) {
|
|
9
|
+
console.log("read server config fail");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// options
|
|
14
|
+
const options = {};
|
|
15
|
+
|
|
16
|
+
// options cros
|
|
17
|
+
options.cros = true;
|
|
18
|
+
|
|
19
|
+
// options config
|
|
20
|
+
options.config = config;
|
|
21
|
+
|
|
22
|
+
// options redis
|
|
23
|
+
options.redis = require("qiao-redis");
|
|
24
|
+
options.redisOptions = config.redisOptions;
|
|
25
|
+
|
|
26
|
+
// options log
|
|
27
|
+
options.log = require("qiao-log");
|
|
28
|
+
options.logOptions = require("./server/log-options.js")();
|
|
29
|
+
|
|
30
|
+
// options rate limit
|
|
31
|
+
options.rateLimitLib = require("qiao-rate-limit");
|
|
32
|
+
options.rateLimitOptions = config.rateLimitOptions;
|
|
33
|
+
|
|
34
|
+
// options checks
|
|
35
|
+
options.checks = [require("./server/util/check.js").checkUserAuth];
|
|
36
|
+
|
|
37
|
+
// options modules
|
|
38
|
+
options.modules = [
|
|
39
|
+
require("qiao-z-nuser").initUserInfo,
|
|
40
|
+
require("qiao-z-nuser").initGithub,
|
|
41
|
+
require("qiao-z-nuser").initGoogle,
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
// go
|
|
45
|
+
const app = await require("qiao-z")(options);
|
|
46
|
+
app.listen(config.port);
|
|
47
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shun-js/vicvic-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "uikoo9 <uikoo9@qq.com>",
|
|
6
|
+
"homepage": "https://github.com/uikoo9/shun-js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/uikoo9/shun-js.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/uikoo9/shun-js/issues"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"server",
|
|
16
|
+
"app.js"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@shun-js/shun-config": "^0.3.1",
|
|
20
|
+
"@shun-js/shun-service": "^0.3.1",
|
|
21
|
+
"qiao-log": "^6.0.0",
|
|
22
|
+
"qiao-rate-limit": "^6.0.0",
|
|
23
|
+
"qiao-redis": "^6.0.0",
|
|
24
|
+
"qiao-z": "^6.0.0",
|
|
25
|
+
"qiao-z-nuser": "^6.0.2",
|
|
26
|
+
"qiao-z-service": "^6.0.1",
|
|
27
|
+
"viho-llm": "^1.1.0",
|
|
28
|
+
"ws": "^8.20.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"gitHead": "7ed1838656ab55ab95c4b580a92a9e4a3053d4ea"
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* log options
|
|
3
|
+
* @returns
|
|
4
|
+
*/
|
|
5
|
+
module.exports = () => {
|
|
6
|
+
// log options
|
|
7
|
+
const logLevel = "debug";
|
|
8
|
+
const logPattern = "yyyy-MM-dd-hh";
|
|
9
|
+
const logPath = require("path").resolve(__dirname, "../logs/qiao-z.log");
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
pm2: true,
|
|
13
|
+
pm2InstanceVar: "INSTANCE_ID",
|
|
14
|
+
appenders: {
|
|
15
|
+
stdout: {
|
|
16
|
+
type: "stdout",
|
|
17
|
+
},
|
|
18
|
+
datefile: {
|
|
19
|
+
type: "dateFile",
|
|
20
|
+
pattern: logPattern,
|
|
21
|
+
filename: logPath,
|
|
22
|
+
keepFileExt: true,
|
|
23
|
+
numBackups: 30,
|
|
24
|
+
compress: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
categories: {
|
|
28
|
+
default: {
|
|
29
|
+
level: logLevel,
|
|
30
|
+
appenders: ["stdout", "datefile"],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// qiao
|
|
2
|
+
const { userCheck } = require("qiao-z-service");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* checkUserAuth
|
|
6
|
+
* @param {*} req
|
|
7
|
+
* @param {*} res
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
exports.checkUserAuth = async function (req, res) {
|
|
11
|
+
const userCheckRes = await userCheck(global.QZ_CONFIG.user, {
|
|
12
|
+
userid: req.headers.userid,
|
|
13
|
+
usertoken: req.headers.usertoken,
|
|
14
|
+
paths: JSON.stringify(global.QZ_CONFIG.paths),
|
|
15
|
+
path: req.url.pathname,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// pass
|
|
19
|
+
if (userCheckRes && userCheckRes.type === "success") return true;
|
|
20
|
+
|
|
21
|
+
// r
|
|
22
|
+
res.json(userCheckRes);
|
|
23
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// services
|
|
2
|
+
const { feishuBot } = require("@shun-js/shun-service");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* feishuMsg
|
|
6
|
+
* @param {*} msg
|
|
7
|
+
*/
|
|
8
|
+
exports.feishuMsg = (msg) => {
|
|
9
|
+
if (global.QZ_CONFIG.env !== "production") return;
|
|
10
|
+
|
|
11
|
+
feishuBot({
|
|
12
|
+
url: global.QZ_CONFIG.feishu.url,
|
|
13
|
+
feishuUrl: global.QZ_CONFIG.feishu.feishuUrl,
|
|
14
|
+
feishuMsg: msg,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// is bot
|
|
19
|
+
function isBot(req) {
|
|
20
|
+
const ua = req.useragent;
|
|
21
|
+
const hasOSName = ua && ua.os && ua.os.name;
|
|
22
|
+
const isGoogleBot = ua && ua.browser && ua.browser.name === "Googlebot";
|
|
23
|
+
const isMetaBot =
|
|
24
|
+
ua && ua.browser && ua.browser.name === "meta-externalagent";
|
|
25
|
+
const isSafariBot =
|
|
26
|
+
ua &&
|
|
27
|
+
ua.engine &&
|
|
28
|
+
ua.engine.name === "WebKit" &&
|
|
29
|
+
ua.engine.version === "605.1.15";
|
|
30
|
+
return !hasOSName || isGoogleBot || isMetaBot || isSafariBot;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* errorFeishuMsg (for task/cron usage - no req)
|
|
35
|
+
* @param {*} msg
|
|
36
|
+
*/
|
|
37
|
+
exports.errorFeishuMsg = (msg) => {
|
|
38
|
+
exports.feishuMsg(`[通知] Service error: ${msg}, check logs.`);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* errorFeishuMsgWithReq (for request handler usage)
|
|
43
|
+
* @param {*} req
|
|
44
|
+
* @param {*} msg
|
|
45
|
+
*/
|
|
46
|
+
exports.errorFeishuMsgWithReq = (req, msg) => {
|
|
47
|
+
if (isBot(req)) return;
|
|
48
|
+
const uaJson = JSON.stringify(req.useragent || {});
|
|
49
|
+
exports.feishuMsg(`[通知] Service error: ${msg}, check logs. UA: ${uaJson}`);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* chatFeishuMsg
|
|
54
|
+
* @param {*} req
|
|
55
|
+
* @param {*} msg
|
|
56
|
+
*/
|
|
57
|
+
exports.chatFeishuMsg = (req, msg) => {
|
|
58
|
+
if (isBot(req)) return;
|
|
59
|
+
const uaJson = JSON.stringify(req.useragent || {});
|
|
60
|
+
const userid = req.headers.userid;
|
|
61
|
+
const finalMsg = `[通知] /remotion-agent\nuserid:${userid}\nua:\n${uaJson}\nmsg:\n${msg}`;
|
|
62
|
+
exports.feishuMsg(finalMsg);
|
|
63
|
+
};
|