refactor(devstar-api): not need user as member
This commit is contained in:
		@@ -5,12 +5,9 @@ import * as utils from './utils';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export default class DevstarAPIHandler {
 | 
					export default class DevstarAPIHandler {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private user: User;
 | 
					 | 
				
			||||||
  private devstarDomain: string;
 | 
					  private devstarDomain: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  constructor(user: User) {
 | 
					  constructor() {
 | 
				
			||||||
    this.user = user
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // 获取domain
 | 
					    // 获取domain
 | 
				
			||||||
    const devstarDomainFromUserConfig = utils.getDevstarDomain()
 | 
					    const devstarDomainFromUserConfig = utils.getDevstarDomain()
 | 
				
			||||||
    if (undefined == devstarDomainFromUserConfig || "" == devstarDomainFromUserConfig) {
 | 
					    if (undefined == devstarDomainFromUserConfig || "" == devstarDomainFromUserConfig) {
 | 
				
			||||||
@@ -21,15 +18,15 @@ export default class DevstarAPIHandler {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 上传公钥
 | 
					  // 上传公钥
 | 
				
			||||||
  public async uploadUserPublicKey(): Promise<string> {
 | 
					  public async uploadUserPublicKey(user: User): Promise<string> {
 | 
				
			||||||
    return new Promise(async (resolve) => {
 | 
					    return new Promise(async (resolve) => {
 | 
				
			||||||
      // 获取机器名称
 | 
					      // 获取机器名称
 | 
				
			||||||
      const machineName = os.hostname();
 | 
					      const machineName = os.hostname();
 | 
				
			||||||
      // 组成公钥名称
 | 
					      // 组成公钥名称
 | 
				
			||||||
      const timestamp = Date.now();
 | 
					      const timestamp = Date.now();
 | 
				
			||||||
      const keyTitle = `${this.user.getUsernameFromLocal()}-${machineName}-${timestamp}`
 | 
					      const keyTitle = `${user.getUsernameFromLocal()}-${machineName}-${timestamp}`
 | 
				
			||||||
      const postData = {
 | 
					      const postData = {
 | 
				
			||||||
        "key": this.user.getUserPublicKey(),
 | 
					        "key": user.getUserPublicKey(),
 | 
				
			||||||
        "title": keyTitle
 | 
					        "title": keyTitle
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,7 +37,7 @@ export default class DevstarAPIHandler {
 | 
				
			|||||||
        method: 'POST',
 | 
					        method: 'POST',
 | 
				
			||||||
        headers: {
 | 
					        headers: {
 | 
				
			||||||
          'Content-Type': 'application/json',
 | 
					          'Content-Type': 'application/json',
 | 
				
			||||||
          'Authorization': 'token ' + this.user.getUserTokenFromLocal()
 | 
					          'Authorization': 'token ' + user.getUserTokenFromLocal()
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        body: JSON.stringify(postData)
 | 
					        body: JSON.stringify(postData)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,8 +43,8 @@ export class DevStarExtension {
 | 
				
			|||||||
                  await this.user.createUserSSHKey()
 | 
					                  await this.user.createUserSSHKey()
 | 
				
			||||||
                    .then(async () => {
 | 
					                    .then(async () => {
 | 
				
			||||||
                      // 上传公钥
 | 
					                      // 上传公钥
 | 
				
			||||||
                      const devstarAPIHandler = new DevstarAPIHandler(this.user)
 | 
					                      const devstarAPIHandler = new DevstarAPIHandler()
 | 
				
			||||||
                      await devstarAPIHandler.uploadUserPublicKey()
 | 
					                      await devstarAPIHandler.uploadUserPublicKey(this.user)
 | 
				
			||||||
                      .then(async (res) => {
 | 
					                      .then(async (res) => {
 | 
				
			||||||
                        if (res === "ok") {
 | 
					                        if (res === "ok") {
 | 
				
			||||||
                          // 打开项目
 | 
					                          // 打开项目
 | 
				
			||||||
@@ -73,8 +73,8 @@ export class DevStarExtension {
 | 
				
			|||||||
                    await this.user.createUserSSHKey()
 | 
					                    await this.user.createUserSSHKey()
 | 
				
			||||||
                      .then(async () => {
 | 
					                      .then(async () => {
 | 
				
			||||||
                        // 上传公钥
 | 
					                        // 上传公钥
 | 
				
			||||||
                        const devstarAPIHandler = new DevstarAPIHandler(this.user)
 | 
					                        const devstarAPIHandler = new DevstarAPIHandler()
 | 
				
			||||||
                        await devstarAPIHandler.uploadUserPublicKey()
 | 
					                        await devstarAPIHandler.uploadUserPublicKey(this.user)
 | 
				
			||||||
                        .then(async (res) => {
 | 
					                        .then(async (res) => {
 | 
				
			||||||
                          if (res === "ok") {
 | 
					                          if (res === "ok") {
 | 
				
			||||||
                            // 打开项目
 | 
					                            // 打开项目
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user