@shun-js/webcc-server 0.6.9 → 0.7.1

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 CHANGED
@@ -23,6 +23,9 @@ const { parseServerConfig } = require('@shun-js/shun-config');
23
23
  options.log = require('qiao-log');
24
24
  options.logOptions = require('./server/log-options.js')();
25
25
 
26
+ // options modules
27
+ options.modules = [require('qiao-z-nuser').initGithub];
28
+
26
29
  // go
27
30
  const app = await require('qiao-z')(options);
28
31
  app.listen(config.port);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/webcc-server",
3
- "version": "0.6.9",
3
+ "version": "0.7.1",
4
4
  "description": "webcc.dev server",
5
5
  "keywords": [
6
6
  "web claude code"
@@ -26,11 +26,12 @@
26
26
  "qiao-ajax": "^5.2.4",
27
27
  "qiao-encode": "^5.0.6",
28
28
  "qiao-log": "^5.1.9",
29
- "qiao-z": "^5.8.9"
29
+ "qiao-z": "^5.8.9",
30
+ "qiao-z-nuser": "^5.9.1"
30
31
  },
31
32
  "publishConfig": {
32
33
  "access": "public",
33
34
  "registry": "https://registry.npmjs.org/"
34
35
  },
35
- "gitHead": "2e16481e703d73845eac724b043e641a56346041"
36
+ "gitHead": "b797c5d6b2b8a8dd4175fa32eb59c396eeb80333"
36
37
  }
@@ -10,10 +10,10 @@ module.exports = (app) => {
10
10
  service.index(req, res);
11
11
  });
12
12
 
13
- // github auth
14
- app.get('/github/auth', (req, res) => {
15
- service.githubAuth(req, res);
16
- });
13
+ // // github auth
14
+ // app.get('/github/auth', (req, res) => {
15
+ // service.githubAuth(req, res);
16
+ // });
17
17
 
18
18
  // github callback
19
19
  app.get('/github/callback', (req, res) => {
@@ -1,5 +1,8 @@
1
1
  // github
2
- const { getGitHubAuthUrl, getGithubUserinfo } = require('../util/github.js');
2
+ const {
3
+ // getGitHubAuthUrl,
4
+ getGithubUserinfo,
5
+ } = require('../util/github.js');
3
6
 
4
7
  /**
5
8
  * index
@@ -10,21 +13,21 @@ exports.index = async (req, res) => {
10
13
  res.send('1');
11
14
  };
12
15
 
13
- /**
14
- * githubAuth
15
- * @param {*} req
16
- * @param {*} res
17
- */
18
- exports.githubAuth = async (req, res) => {
19
- // auth
20
- const authObj = getGitHubAuthUrl();
16
+ // /**
17
+ // * githubAuth
18
+ // * @param {*} req
19
+ // * @param {*} res
20
+ // */
21
+ // exports.githubAuth = async (req, res) => {
22
+ // // auth
23
+ // const authObj = getGitHubAuthUrl();
21
24
 
22
- // set cookie
23
- res.setCookie('state', authObj.state);
25
+ // // set cookie
26
+ // res.setCookie('state', authObj.state);
24
27
 
25
- // redirect
26
- res.redirect(authObj.finalUrl);
27
- };
28
+ // // redirect
29
+ // res.redirect(authObj.finalUrl);
30
+ // };
28
31
 
29
32
  /**
30
33
  * githubCallback
@@ -69,6 +72,11 @@ exports.githubCallback = async (req, res) => {
69
72
  }
70
73
 
71
74
  // userinfo
72
- await getGithubUserinfo(queryCode);
75
+ const githubUserinfo = await getGithubUserinfo(req, queryCode);
76
+ if (!githubUserinfo) {
77
+ req.logger.error(methodName, 'githubUserinfo is null');
78
+ res.redirect(fallbackUrl);
79
+ return;
80
+ }
73
81
  res.send('1');
74
82
  };
@@ -24,9 +24,12 @@ exports.getGitHubAuthUrl = () => {
24
24
 
25
25
  /**
26
26
  * getGithubUserinfo
27
+ * @param {*} req
27
28
  * @param {*} code
28
29
  */
29
- exports.getGithubUserinfo = async (code) => {
30
+ exports.getGithubUserinfo = async (req, code) => {
31
+ const methodName = 'getGithubUserinfo';
32
+
30
33
  try {
31
34
  // get token
32
35
  const tokenUrl = global.QZ_CONFIG.github.tokenUrl;
@@ -41,10 +44,104 @@ exports.getGithubUserinfo = async (code) => {
41
44
  Accept: 'application/json',
42
45
  },
43
46
  };
44
- console.log(tokenConfig);
45
47
  const tokenResponse = await get(tokenUrl, tokenConfig);
46
- console.log(tokenResponse);
48
+
49
+ // check
50
+ if (!tokenResponse) {
51
+ req.logger.error(methodName, 'tokenResponse is null');
52
+ return;
53
+ }
54
+ if (tokenResponse.status !== 200) {
55
+ req.logger.error(methodName, 'tokenResponse.status !== 200', tokenResponse.status);
56
+ return;
57
+ }
58
+ if (!tokenResponse.data) {
59
+ req.logger.error(methodName, 'tokenResponse.data is null');
60
+ return;
61
+ }
62
+ if (!tokenResponse.data.access_token || !tokenResponse.data.token_type) {
63
+ req.logger.error(methodName, 'tokenResponse.data.access_token is null or tokenResponse.data.token_type is null');
64
+ return;
65
+ }
66
+
67
+ // get user
68
+ req.logger.info(methodName, 'get token success');
69
+ const userUrl = global.QZ_CONFIG.github.userUrl;
70
+ const userConfig = {
71
+ headers: {
72
+ Authorization: `${tokenResponse.data.token_type} ${tokenResponse.data.access_token}`,
73
+ Accept: 'application/json',
74
+ },
75
+ };
76
+ const userResponse = await get(userUrl, userConfig);
77
+
78
+ // check
79
+ if (!userResponse) {
80
+ req.logger.error(methodName, 'userResponse is null');
81
+ return;
82
+ }
83
+ if (userResponse.status !== 200) {
84
+ req.logger.error(methodName, 'userResponse.status !== 200', userResponse.status);
85
+ return;
86
+ }
87
+ if (!userResponse.data) {
88
+ req.logger.error(methodName, 'userResponse.data is null');
89
+ return;
90
+ }
91
+ req.logger.info(methodName, 'get user success');
92
+
93
+ // r
94
+ return userResponse.data;
47
95
  } catch (error) {
48
- console.log(error);
96
+ req.logger.error(methodName, 'error', error);
49
97
  }
50
98
  };
99
+
100
+ // {
101
+ // login: 'uikoo9',
102
+ // id: 10345351,
103
+ // node_id: 'MDQ6VXNlcjEwMzQ1MzUx',
104
+ // avatar_url: 'https://avatars.githubusercontent.com/u/10345351?v=4',
105
+ // gravatar_id: '',
106
+ // url: 'https://api.github.com/users/uikoo9',
107
+ // html_url: 'https://github.com/uikoo9',
108
+ // followers_url: 'https://api.github.com/users/uikoo9/followers',
109
+ // following_url: 'https://api.github.com/users/uikoo9/following{/other_user}',
110
+ // gists_url: 'https://api.github.com/users/uikoo9/gists{/gist_id}',
111
+ // starred_url: 'https://api.github.com/users/uikoo9/starred{/owner}{/repo}',
112
+ // subscriptions_url: 'https://api.github.com/users/uikoo9/subscriptions',
113
+ // organizations_url: 'https://api.github.com/users/uikoo9/orgs',
114
+ // repos_url: 'https://api.github.com/users/uikoo9/repos',
115
+ // events_url: 'https://api.github.com/users/uikoo9/events{/privacy}',
116
+ // received_events_url: 'https://api.github.com/users/uikoo9/received_events',
117
+ // type: 'User',
118
+ // user_view_type: 'private',
119
+ // site_admin: false,
120
+ // name: null,
121
+ // company: null,
122
+ // blog: '',
123
+ // location: null,
124
+ // email: 'uikoo9@qq.com',
125
+ // hireable: null,
126
+ // bio: null,
127
+ // twitter_username: null,
128
+ // notification_email: 'uikoo9@qq.com',
129
+ // public_repos: 27,
130
+ // public_gists: 0,
131
+ // followers: 91,
132
+ // following: 4,
133
+ // created_at: '2014-12-30T03:11:05Z',
134
+ // updated_at: '2026-01-29T09:08:41Z',
135
+ // private_gists: 0,
136
+ // total_private_repos: 33,
137
+ // owned_private_repos: 33,
138
+ // disk_usage: 1026748,
139
+ // collaborators: 4,
140
+ // two_factor_authentication: true,
141
+ // plan: {
142
+ // name: 'free',
143
+ // space: 976562499,
144
+ // collaborators: 0,
145
+ // private_repos: 10000
146
+ // }
147
+ // }