File tree Expand file tree Collapse file tree 4 files changed +99
-6
lines changed Expand file tree Collapse file tree 4 files changed +99
-6
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " coding-hbuilderx " ,
3
- "description" : " your extension description " ,
4
- "displayName" : " your extension display name " ,
5
- "version" : " 0 .0.0" ,
6
- "publisher" : " your name " ,
2
+ "name" : " codingplugin " ,
3
+ "description" : " " ,
4
+ "displayName" : " CODING 代码仓库插件 " ,
5
+ "version" : " 1 .0.0" ,
6
+ "publisher" : " coding " ,
7
7
"engines" : {
8
8
"HBuilderX" : " ^2.7.0"
9
9
},
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ import MRTreeDataProvider from './trees/mr';
5
5
import toast from './utils/toast' ;
6
6
import { getMRUrl } from './utils/repo' ;
7
7
import ACTIONS , { dispatch } from './utils/actions' ;
8
- import { IDepot , IMRItem } from './typings/common' ;
8
+ import { IDepot , IMRItem , IOAuthResponse } from './typings/common' ;
9
+ import * as DCloudService from './services/dcloud' ;
9
10
10
11
const { registerCommand } = hx . commands ;
11
12
@@ -60,6 +61,29 @@ export function createTreeViews(context: IContext) {
60
61
treeDataProvider : new DepotTreeDataProvider ( context ) ,
61
62
} ) ,
62
63
) ;
64
+
65
+ hx . authorize
66
+ . login ( {
67
+ scopes : [ 'basic' , 'email' , 'phone' ] ,
68
+ appId : DCloudService . appId ,
69
+ } )
70
+ . then ( async ( param : IOAuthResponse ) => {
71
+ const { code, error } = param ;
72
+ if ( error ) {
73
+ console . log ( error ) ;
74
+ return ;
75
+ }
76
+ console . info ( code ) ;
77
+
78
+ try {
79
+ const token = await DCloudService . applyForToken ( code ) ;
80
+ const resp = await DCloudService . fetchUser ( token . data . access_token ) ;
81
+ console . info ( resp ) ;
82
+ toast . info ( `logged in as DCloud user: ${ resp . data . nickname } ${ resp . data . email } ` ) ;
83
+ } catch ( err ) {
84
+ console . error ( err ) ;
85
+ }
86
+ } ) ;
63
87
}
64
88
65
89
export function workspaceInit ( ) {
Original file line number Diff line number Diff line change
1
+ import axios from '../utils/axios' ;
2
+ import { ITokenResponse , IDCloudUser } from '../typings/common' ;
3
+
4
+ const appSecret = `eLEDnBuT258P1OmRx1OVFSCj4SZXom` ;
5
+ export const appId = `gZTr3CuevT` ;
6
+
7
+ export const applyForToken = async ( code : string ) => {
8
+ try {
9
+ const resp : ITokenResponse = await axios . get ( `https://ide.dcloud.net.cn/dcloudOauthv2/accessToken` , {
10
+ params : {
11
+ code,
12
+ appid : appId ,
13
+ app_secret : appSecret ,
14
+ } ,
15
+ } ) ;
16
+
17
+ if ( resp . ret ) {
18
+ return Promise . reject ( resp ) ;
19
+ }
20
+ return resp ;
21
+ } catch ( e ) {
22
+ return Promise . reject ( e ) ;
23
+ }
24
+ } ;
25
+
26
+ export const fetchUser = async ( accessToken : string ) => {
27
+ try {
28
+ const resp : IDCloudUser = await axios . get ( `https://ide.dcloud.net.cn/dcloudOauthv2/userInfo` , {
29
+ params : {
30
+ access_token : accessToken ,
31
+ } ,
32
+ } ) ;
33
+
34
+ if ( resp . ret ) {
35
+ return Promise . reject ( resp ) ;
36
+ }
37
+ return resp ;
38
+ } catch ( e ) {
39
+ return Promise . reject ( e ) ;
40
+ }
41
+ } ;
Original file line number Diff line number Diff line change @@ -56,3 +56,31 @@ export interface IDepot {
56
56
svnEnabled : boolean ;
57
57
vcsType : 'git' | 'svn' ;
58
58
}
59
+
60
+ export interface IOAuthResponse {
61
+ code : string ;
62
+ error : number ;
63
+ }
64
+
65
+ export interface ITokenResponse {
66
+ ret : number ;
67
+ desc : string ;
68
+ data : {
69
+ access_token : string ;
70
+ access_token_ttl : string ;
71
+ refresh_token : string ;
72
+ refresh_token_ttl : string ;
73
+ } ;
74
+ }
75
+
76
+ export interface IDCloudUser {
77
+ ret : number ;
78
+ desc : string ;
79
+ data : {
80
+ nickname : string ;
81
+ avatar : string ;
82
+ uid : string ;
83
+ email : string ;
84
+ phone : string ;
85
+ } ;
86
+ }
You can’t perform that action at this time.
0 commit comments