style: tab -> 2 spaces in all typescript files
This commit is contained in:
34
src/home.ts
34
src/home.ts
@@ -7,15 +7,15 @@ import * as utils from './utils'
|
||||
export default class DSHome {
|
||||
private context: vscode.ExtensionContext;
|
||||
private remoteContainer: RemoteContainer;
|
||||
private user:User;
|
||||
private devstarHomePageUrl:string;
|
||||
private user: User;
|
||||
private devstarHomePageUrl: string;
|
||||
|
||||
constructor(context: vscode.ExtensionContext) {
|
||||
this.context = context;
|
||||
this.user = new User(context);
|
||||
this.remoteContainer = new RemoteContainer(this.user);
|
||||
|
||||
const devstarHomePageUrl:string|undefined = vscode.workspace.getConfiguration('devstar').get('devstarHomePage')
|
||||
const devstarHomePageUrl: string | undefined = vscode.workspace.getConfiguration('devstar').get('devstarHomePage')
|
||||
if (undefined == devstarHomePageUrl || "" == devstarHomePageUrl) {
|
||||
this.devstarHomePageUrl = "https://devstar.cn/devstar-home"
|
||||
// this.devstarHomePageUrl = "http://localhost:3000/devstar-home"
|
||||
@@ -44,19 +44,19 @@ export default class DSHome {
|
||||
case 'getUserToken':
|
||||
const userToken = this.user.getUserTokenFromLocal()
|
||||
if (userToken === undefined) {
|
||||
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: ''}})
|
||||
panel.webview.postMessage({ command: 'getUserToken', data: { userToken: '' } })
|
||||
break;
|
||||
} else {
|
||||
panel.webview.postMessage({ command: 'getUserToken', data: {userToken: userToken}})
|
||||
panel.webview.postMessage({ command: 'getUserToken', data: { userToken: userToken } })
|
||||
break;
|
||||
}
|
||||
case 'getUsername':
|
||||
const username = this.user.getUsernameFromLocal()
|
||||
if (username === undefined) {
|
||||
panel.webview.postMessage({command: 'getUsername', data: {username: ''}})
|
||||
panel.webview.postMessage({ command: 'getUsername', data: { username: '' } })
|
||||
break;
|
||||
} else {
|
||||
panel.webview.postMessage({command: 'getUsername', data: {username: username}})
|
||||
panel.webview.postMessage({ command: 'getUsername', data: { username: username } })
|
||||
break;
|
||||
}
|
||||
case 'firstOpenRemoteFolder':
|
||||
@@ -77,43 +77,43 @@ export default class DSHome {
|
||||
case 'setUserToken':
|
||||
this.user.setUserTokenToLocal(data.userToken)
|
||||
if (data.userToken === this.user.getUserTokenFromLocal()) {
|
||||
panel.webview.postMessage({ command: 'setUserToken', data: {ok: true}})
|
||||
panel.webview.postMessage({ command: 'setUserToken', data: { ok: true } })
|
||||
break;
|
||||
} else {
|
||||
panel.webview.postMessage({ command: 'setUserToken', data: {ok: false}})
|
||||
panel.webview.postMessage({ command: 'setUserToken', data: { ok: false } })
|
||||
break;
|
||||
}
|
||||
case 'setUsername':
|
||||
this.user.setUsernameToLocal(data.username);
|
||||
if (data.username === this.user.getUsernameFromLocal()) {
|
||||
panel.webview.postMessage({command: 'setUsername', data: {ok: true}});
|
||||
panel.webview.postMessage({ command: 'setUsername', data: { ok: true } });
|
||||
break;
|
||||
} else {
|
||||
panel.webview.postMessage({command: 'setUsername', data: {ok: false}});
|
||||
panel.webview.postMessage({ command: 'setUsername', data: { ok: false } });
|
||||
break;
|
||||
}
|
||||
case 'getUserPublicKey':
|
||||
var userPublicKey = '';
|
||||
if (this.user.existUserPrivateKey()) {
|
||||
userPublicKey = this.user.getUserPublicKey();
|
||||
panel.webview.postMessage({command: 'getUserPublicKey', data: {userPublicKey: userPublicKey}})
|
||||
panel.webview.postMessage({ command: 'getUserPublicKey', data: { userPublicKey: userPublicKey } })
|
||||
break;
|
||||
} else {
|
||||
panel.webview.postMessage({command: 'getUserPublicKey', data: {userPublicKey: userPublicKey}})
|
||||
panel.webview.postMessage({ command: 'getUserPublicKey', data: { userPublicKey: userPublicKey } })
|
||||
break;
|
||||
}
|
||||
case 'createUserPublicKey':
|
||||
await this.user.createUserSSHKey();
|
||||
if (this.user.existUserPublicKey()) {
|
||||
panel.webview.postMessage({command: 'createUserPublicKey', data: {ok: true}})
|
||||
panel.webview.postMessage({ command: 'createUserPublicKey', data: { ok: true } })
|
||||
break;
|
||||
} else {
|
||||
panel.webview.postMessage({command: 'createUserPublicKey', data: {ok: false}})
|
||||
panel.webview.postMessage({ command: 'createUserPublicKey', data: { ok: false } })
|
||||
break;
|
||||
}
|
||||
case 'getMachineName':
|
||||
const machineName = os.hostname();
|
||||
panel.webview.postMessage({command: 'getMachineName', data: {machineName: machineName}})
|
||||
panel.webview.postMessage({ command: 'getMachineName', data: { machineName: machineName } })
|
||||
case 'getDefaultPublicKey':
|
||||
var defaultPublicKey;
|
||||
if (utils.existDefaultPublicKey()) {
|
||||
@@ -123,7 +123,7 @@ export default class DSHome {
|
||||
utils.createSSHKey();
|
||||
defaultPublicKey = utils.getDefaultPublicKey();
|
||||
}
|
||||
panel.webview.postMessage({ command: 'getDefaultPublicKey', data: {defaultPublicKey: defaultPublicKey}})
|
||||
panel.webview.postMessage({ command: 'getDefaultPublicKey', data: { defaultPublicKey: defaultPublicKey } })
|
||||
}
|
||||
},
|
||||
undefined,
|
||||
|
@@ -9,9 +9,9 @@ import * as utils from './utils';
|
||||
import User from './user';
|
||||
|
||||
export default class RemoteContainer {
|
||||
private user:User;
|
||||
private user: User;
|
||||
|
||||
constructor(user:User) {
|
||||
constructor(user: User) {
|
||||
this.user = user
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ export default class RemoteContainer {
|
||||
}
|
||||
|
||||
|
||||
openRemoteFolder(host: string, username:string ,port:number, path: string): void {
|
||||
openRemoteFolder(host: string, username: string, port: number, path: string): void {
|
||||
var host = `${host}-${port}`
|
||||
const command = `code --remote ssh-remote+${username}@${host} ${path} --reuse-window`
|
||||
let terminal = vscode.window.activeTerminal || vscode.window.createTerminal(`Ext Terminal`);
|
||||
|
32
src/user.ts
32
src/user.ts
@@ -9,11 +9,11 @@ const {
|
||||
const sshpk = require('sshpk');
|
||||
|
||||
export default class User {
|
||||
private context:vscode.ExtensionContext;
|
||||
private username:string|undefined;
|
||||
private userToken:string|undefined;
|
||||
private usernameKey:string = 'devstarUsername'
|
||||
private userTokenKey:string = 'devstarUserToken'
|
||||
private context: vscode.ExtensionContext;
|
||||
private username: string | undefined;
|
||||
private userToken: string | undefined;
|
||||
private usernameKey: string = 'devstarUsername'
|
||||
private userTokenKey: string = 'devstarUserToken'
|
||||
|
||||
constructor(context: vscode.ExtensionContext) {
|
||||
this.context = context;
|
||||
@@ -24,10 +24,10 @@ export default class User {
|
||||
private isLogged() {
|
||||
var existUsername = false;
|
||||
var existUserToken = false;
|
||||
if(this.username != undefined && this.username != '') {
|
||||
if (this.username != undefined && this.username != '') {
|
||||
existUsername = true;
|
||||
}
|
||||
if(this.userToken != undefined && this.userToken != '') {
|
||||
if (this.userToken != undefined && this.userToken != '') {
|
||||
existUserToken = true;
|
||||
}
|
||||
|
||||
@@ -38,25 +38,25 @@ export default class User {
|
||||
}
|
||||
}
|
||||
|
||||
public getUsernameFromLocal(): string|undefined {
|
||||
public getUsernameFromLocal(): string | undefined {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public getUserTokenFromLocal(): string|undefined{
|
||||
public getUserTokenFromLocal(): string | undefined {
|
||||
return this.userToken;
|
||||
}
|
||||
|
||||
public setUsernameToLocal(username:string) {
|
||||
public setUsernameToLocal(username: string) {
|
||||
this.context.globalState.update(this.usernameKey, username);
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public setUserTokenToLocal(userToken:string) {
|
||||
public setUserTokenToLocal(userToken: string) {
|
||||
this.context.globalState.update(this.userTokenKey, userToken)
|
||||
this.userToken = userToken
|
||||
}
|
||||
|
||||
public getUserPrivateKeyPath() : string{
|
||||
public getUserPrivateKeyPath(): string {
|
||||
if (!this.isLogged) {
|
||||
return '';
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export default class User {
|
||||
return path.join(os.homedir(), '.ssh', `id_rsa_${this.username}`)
|
||||
}
|
||||
|
||||
public getUserPublicKeyPath() :string{
|
||||
public getUserPublicKeyPath(): string {
|
||||
if (!this.isLogged) {
|
||||
return '';
|
||||
}
|
||||
@@ -72,12 +72,12 @@ export default class User {
|
||||
return path.join(os.homedir(), '.ssh', `id_rsa_${this.username}.pub`)
|
||||
}
|
||||
|
||||
public existUserPublicKey() :boolean{
|
||||
public existUserPublicKey(): boolean {
|
||||
const userPublicKeyPath = this.getUserPublicKeyPath();
|
||||
return fs.existsSync(userPublicKeyPath)
|
||||
}
|
||||
|
||||
public existUserPrivateKey() :boolean{
|
||||
public existUserPrivateKey(): boolean {
|
||||
const userPrivateKeyPath = this.getUserPrivateKeyPath();
|
||||
return fs.existsSync(userPrivateKeyPath)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ export default class User {
|
||||
await fs.writeFileSync(this.getUserPrivateKeyPath(), privateKeyStr);
|
||||
// limit the permission of private key to prevent that the private key not works
|
||||
await fs.chmodSync(this.getUserPrivateKeyPath(), 0o600)
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
console.error("Failed to write public/private key into the default ssh public/key file: ", error);
|
||||
}
|
||||
}
|
||||
|
14
src/utils.ts
14
src/utils.ts
@@ -34,8 +34,8 @@ export function fetch(url: string): Promise<string> {
|
||||
});
|
||||
}
|
||||
|
||||
export const Sleep = (ms:number)=> {
|
||||
return new Promise(resolve=>setTimeout(resolve, ms))
|
||||
export const Sleep = (ms: number) => {
|
||||
return new Promise(resolve => setTimeout(resolve, ms))
|
||||
}
|
||||
|
||||
export function getVsCodeCommitId(): Promise<string> {
|
||||
@@ -60,20 +60,20 @@ export function getVsCodeCommitId(): Promise<string> {
|
||||
})
|
||||
}
|
||||
|
||||
export function getDefaultPrivateKeyPath() : string{
|
||||
export function getDefaultPrivateKeyPath(): string {
|
||||
return path.join(os.homedir(), '.ssh', 'id_rsa')
|
||||
}
|
||||
|
||||
export function getDefaultPublicKeyPath() :string{
|
||||
export function getDefaultPublicKeyPath(): string {
|
||||
return path.join(os.homedir(), '.ssh', 'id_rsa.pub')
|
||||
}
|
||||
|
||||
export function existDefaultPublicKey() :boolean{
|
||||
export function existDefaultPublicKey(): boolean {
|
||||
const defaultPublicKeyPath = getDefaultPublicKeyPath();
|
||||
return fs.existsSync(defaultPublicKeyPath)
|
||||
}
|
||||
|
||||
export function existDefaultPrivateKey() :boolean{
|
||||
export function existDefaultPrivateKey(): boolean {
|
||||
const defaultPrivateKeyPath = getDefaultPrivateKeyPath();
|
||||
return fs.existsSync(defaultPrivateKeyPath)
|
||||
}
|
||||
@@ -117,7 +117,7 @@ export function createSSHKey() {
|
||||
try {
|
||||
fs.writeFileSync(getDefaultPublicKeyPath(), publicKey);
|
||||
fs.writeFileSync(getDefaultPrivateKeyPath(), privateKey);
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
console.error("Failed to write public/private key into the default ssh public/key file: ", error);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user