@shun-js/webcc-server 0.6.7

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 qiaowenbin<uikoo9@qq.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/app.js ADDED
@@ -0,0 +1,29 @@
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 log
23
+ options.log = require('qiao-log');
24
+ options.logOptions = require('./server/log-options.js')();
25
+
26
+ // go
27
+ const app = await require('qiao-z')(options);
28
+ app.listen(config.port);
29
+ })();
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@shun-js/webcc-server",
3
+ "version": "0.6.7",
4
+ "description": "webcc.dev server",
5
+ "keywords": [
6
+ "web claude code"
7
+ ],
8
+ "license": "MIT",
9
+ "author": "uikoo9 <uikoo9@qq.com>",
10
+ "homepage": "https://github.com/uikoo9/shun-js",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/uikoo9/shun-js.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/uikoo9/shun-js/issues"
17
+ },
18
+ "files": [
19
+ "server",
20
+ "app.js"
21
+ ],
22
+ "scripts": {},
23
+ "dependencies": {
24
+ "@shun-js/shun-config": "^0.3.1",
25
+ "@shun-js/shun-service": "^0.3.1",
26
+ "qiao-file": "^5.0.6",
27
+ "qiao-log": "^5.1.9",
28
+ "qiao-z": "^5.8.9"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "registry": "https://registry.npmjs.org/"
33
+ },
34
+ "gitHead": "a43c95c66e0f7dc0a8cfed413baf2ccc5699c373"
35
+ }
@@ -0,0 +1,17 @@
1
+ // service
2
+ const service = require('../service/IndexService.js');
3
+
4
+ /**
5
+ * controller
6
+ */
7
+ module.exports = (app) => {
8
+ // index
9
+ app.get('/', (req, res) => {
10
+ service.index(req, res);
11
+ });
12
+
13
+ // github callback
14
+ app.get('/github/callback', (req, res) => {
15
+ service.githubCallback(req, res);
16
+ });
17
+ };
@@ -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,25 @@
1
+ // github
2
+ const { getGitHubAuthUrl } = require('../util/github.js');
3
+
4
+ /**
5
+ * index
6
+ * @param {*} req
7
+ * @param {*} res
8
+ */
9
+ exports.index = async (req, res) => {
10
+ const url = getGitHubAuthUrl('1');
11
+ console.log(url);
12
+ res.send('1');
13
+ };
14
+
15
+ /**
16
+ * githubCallback
17
+ * @param {*} req
18
+ * @param {*} res
19
+ */
20
+ exports.githubCallback = async (req, res) => {
21
+ console.log(req.params);
22
+ console.log(req.body);
23
+ console.log(req.query);
24
+ res.send('1');
25
+ };
@@ -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,77 @@
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 = ua && ua.browser && ua.browser.name === 'meta-externalagent';
24
+ const isSafariBot = ua && ua.engine && ua.engine.name === 'WebKit' && ua.engine.version === '605.1.15';
25
+ return !hasOSName || isGoogleBot || isMetaBot || isSafariBot;
26
+ }
27
+
28
+ /**
29
+ * errorFeishuMsg
30
+ * @param {*} req
31
+ * @param {*} msg
32
+ * @returns
33
+ */
34
+ exports.errorFeishuMsg = (req, msg) => {
35
+ // check
36
+ if (isBot(req)) return;
37
+
38
+ // msg
39
+ const uaJson = JSON.stringify(req.useragent || {});
40
+ exports.feishuMsg(`【通知】服务异常,${msg},请查看日志,ua:${uaJson}`);
41
+ };
42
+
43
+ /**
44
+ * chatFeishuMsg
45
+ * @param {*} req
46
+ * @returns
47
+ */
48
+ exports.chatFeishuMsg = (req) => {
49
+ // check
50
+ if (isBot(req)) return;
51
+
52
+ // msg
53
+ const uaJson = JSON.stringify(req.useragent || {});
54
+ const userid = req.headers.userid;
55
+ const prompt = decodeURIComponent(req.body.userPrompt);
56
+
57
+ const msg = `【通知】/chat被访问\nuserid:${userid}\nua:\n${uaJson}\nprompt:\n${prompt}`;
58
+ exports.feishuMsg(msg);
59
+ };
60
+
61
+ /**
62
+ * chatResFeishuMsg
63
+ * @param {*} req
64
+ * @returns
65
+ */
66
+ exports.chatResFeishuMsg = (req, chatRes) => {
67
+ // check
68
+ if (isBot(req)) return;
69
+
70
+ // msg
71
+ const uaJson = JSON.stringify(req.useragent || {});
72
+ const userid = req.headers.userid;
73
+ const prompt = decodeURIComponent(req.body.userPrompt);
74
+
75
+ const msg = `【通知】/chat生成成功\nuserid:${userid}\nua:\n${uaJson}\nprompt:\n${prompt}\nres:${chatRes}`;
76
+ exports.feishuMsg(msg);
77
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * getGitHubAuthUrl
3
+ * @param {*} state
4
+ * @returns
5
+ */
6
+ exports.getGitHubAuthUrl = (state) => {
7
+ const params = new URLSearchParams({
8
+ client_id: global.QZ_CONFIG.github.clientID,
9
+ redirect_uri: global.QZ_CONFIG.github.callbackUrl,
10
+ scope: global.QZ_CONFIG.github.scope,
11
+ state: state,
12
+ });
13
+
14
+ return `${global.QZ_CONFIG.github.authUrl}?${params.toString()}`;
15
+ };