refactor(devstar-api): not need user as member

This commit is contained in:
Levi Yan
2025-03-23 16:34:03 +08:00
parent 1d1eb092a9
commit 5813fe2c20
2 changed files with 9 additions and 12 deletions

View File

@@ -5,12 +5,9 @@ import * as utils from './utils';
export default class DevstarAPIHandler {
private user: User;
private devstarDomain: string;
constructor(user: User) {
this.user = user
constructor() {
// 获取domain
const devstarDomainFromUserConfig = utils.getDevstarDomain()
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) => {
// 获取机器名称
const machineName = os.hostname();
// 组成公钥名称
const timestamp = Date.now();
const keyTitle = `${this.user.getUsernameFromLocal()}-${machineName}-${timestamp}`
const keyTitle = `${user.getUsernameFromLocal()}-${machineName}-${timestamp}`
const postData = {
"key": this.user.getUserPublicKey(),
"key": user.getUserPublicKey(),
"title": keyTitle
}
@@ -40,7 +37,7 @@ export default class DevstarAPIHandler {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'token ' + this.user.getUserTokenFromLocal()
'Authorization': 'token ' + user.getUserTokenFromLocal()
},
body: JSON.stringify(postData)
})

View File

@@ -43,8 +43,8 @@ export class DevStarExtension {
await this.user.createUserSSHKey()
.then(async () => {
// 上传公钥
const devstarAPIHandler = new DevstarAPIHandler(this.user)
await devstarAPIHandler.uploadUserPublicKey()
const devstarAPIHandler = new DevstarAPIHandler()
await devstarAPIHandler.uploadUserPublicKey(this.user)
.then(async (res) => {
if (res === "ok") {
// 打开项目
@@ -73,8 +73,8 @@ export class DevStarExtension {
await this.user.createUserSSHKey()
.then(async () => {
// 上传公钥
const devstarAPIHandler = new DevstarAPIHandler(this.user)
await devstarAPIHandler.uploadUserPublicKey()
const devstarAPIHandler = new DevstarAPIHandler()
await devstarAPIHandler.uploadUserPublicKey(this.user)
.then(async (res) => {
if (res === "ok") {
// 打开项目