@@ -12,7 +12,7 @@ import {
1212} from './typings/respResult' ;
1313import { PromiseAdapter , promiseFromEvent , parseQuery , parseCloneUrl } from './common/utils' ;
1414import { GitService } from './common/gitService' ;
15- import { RepoInfo , SessionData , TokenType } from './typings/commonTypes' ;
15+ import { RepoInfo , ISessionData , TokenType } from './typings/commonTypes' ;
1616import { keychain } from './common/keychain' ;
1717import Logger from './common/logger' ;
1818
@@ -45,7 +45,7 @@ export class CodingServer {
4545
4646 private _loggedIn : boolean = false ;
4747 private _context : vscode . ExtensionContext ;
48- private _session : SessionData | null = null ;
48+ private _session : ISessionData | null = null ;
4949
5050 constructor ( context : vscode . ExtensionContext ) {
5151 this . _context = context ;
@@ -59,7 +59,7 @@ export class CodingServer {
5959 }
6060 }
6161
62- private async _readSessions ( ) : Promise < SessionData | null > {
62+ private async _readSessions ( ) : Promise < ISessionData | null > {
6363 const [ accessToken , refreshToken ] = await Promise . all ( [
6464 keychain . getToken ( TokenType . AccessToken ) ,
6565 keychain . getToken ( TokenType . RefreshToken ) ,
@@ -81,7 +81,7 @@ export class CodingServer {
8181 return null ;
8282 }
8383
84- public async getSessionData ( accessToken : TokenType . AccessToken , refreshToken : TokenType . RefreshToken ) : Promise < SessionData > {
84+ public async getSessionData ( accessToken : TokenType . AccessToken , refreshToken : TokenType . RefreshToken ) : Promise < ISessionData > {
8585 try {
8686 const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as RepoInfo ;
8787 if ( ! repoInfo ?. team ) {
@@ -90,7 +90,7 @@ export class CodingServer {
9090
9191 const result = await this . getUserInfo ( repoInfo . team || `` , accessToken ) ;
9292 const { data : userInfo } = result ;
93- const ret : SessionData = {
93+ const ret : ISessionData = {
9494 id : nanoid ( ) ,
9595 user : userInfo ,
9696 accessToken,
@@ -131,7 +131,7 @@ export class CodingServer {
131131 } ) ;
132132 }
133133
134- public async login ( team : string , scopes : string = SCOPES ) : Promise < SessionData | null > {
134+ public async login ( team : string , scopes : string = SCOPES ) : Promise < ISessionData | null > {
135135 const { access_token : accessToken , refresh_token : refreshToken } = await this . startOAuth ( team , scopes ) ;
136136 if ( accessToken && refreshToken ) {
137137 try {
@@ -305,6 +305,25 @@ export class CodingServer {
305305 }
306306 }
307307
308+ public async getRemoteFileContent ( path : string ) {
309+ try {
310+ const repoInfo = this . _context . workspaceState . get ( `repoInfo` ) as RepoInfo ;
311+ if ( ! repoInfo ?. team ) {
312+ throw new Error ( `team not exist` ) ;
313+ }
314+
315+ const { body } = await got . get ( `https://${ repoInfo . team } .coding.net/p/${ repoInfo . project } /d/${ repoInfo . repo } /git/raw/${ path } ` , {
316+ searchParams : {
317+ access_token : this . _session ?. accessToken ,
318+ } ,
319+ } ) ;
320+
321+ return body ;
322+ } catch ( err ) {
323+ return `` ;
324+ }
325+ }
326+
308327 get loggedIn ( ) {
309328 return this . _loggedIn ;
310329 }
0 commit comments