Browse Source

Fix liniting errors

pull/270/head
butlerx 4 years ago
parent
commit
267ee6d338
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 14
      src/server/login.ts
  2. 21
      src/shared/config.ts
  3. 2
      src/shared/interfaces.ts

14
src/server/login.ts

@ -1,9 +1,13 @@
import pty from 'node-pty'; import pty from 'node-pty';
import { dirname, resolve } from 'path'; import { dirname, resolve as resolvePath } from 'path';
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { xterm } from './shared/xterm.js'; import { xterm } from './shared/xterm.js';
const __dirname = resolve(dirname(fileURLToPath(import.meta.url)), '..'); const executable = resolvePath(
dirname(fileURLToPath(import.meta.url)),
'..',
'buffer.js',
);
export function login(socket: SocketIO.Socket): Promise<string> { export function login(socket: SocketIO.Socket): Promise<string> {
// Check request-header for username // Check request-header for username
@ -16,11 +20,7 @@ export function login(socket: SocketIO.Socket): Promise<string> {
// Request carries no username information // Request carries no username information
// Create terminal and ask user for username // Create terminal and ask user for username
const term = pty.spawn( const term = pty.spawn('/usr/bin/env', ['node', executable], xterm);
'/usr/bin/env',
['node', `${__dirname}/buffer.js`],
xterm,
);
let buf = ''; let buf = '';
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
term.on('exit', () => { term.on('exit', () => {

21
src/shared/config.ts

@ -3,7 +3,7 @@ import path from 'path';
import JSON5 from 'json5'; import JSON5 from 'json5';
import isUndefined from 'lodash/isUndefined.js'; import isUndefined from 'lodash/isUndefined.js';
import type { Config, SSH, Server } from './interfaces'; import type { Config, SSH, Server, SSL } from './interfaces';
import { import {
sshDefault, sshDefault,
serverDefault, serverDefault,
@ -11,13 +11,14 @@ import {
defaultCommand, defaultCommand,
} from './defaults.js'; } from './defaults.js';
type confValue = boolean | string | number | undefined | SSH | Server | SSL;
/** /**
* Cast given value to boolean * Cast given value to boolean
* *
* @param value - variable to cast * @param value - variable to cast
* @returns variable cast to boolean * @returns variable cast to boolean
*/ */
function ensureBoolean(value: any): boolean { function ensureBoolean(value: confValue): boolean {
switch (value) { switch (value) {
case true: case true:
case 'true': case 'true':
@ -73,15 +74,15 @@ export async function loadConfigFile(filepath?: string): Promise<Config> {
* *
*/ */
const objectAssign = ( const objectAssign = (
target: Record<string, any>, target: SSH | Server,
source: Record<string, any>, source: Record<string, confValue>,
): Record<string, any> => ): SSH | Server =>
Object.fromEntries( Object.fromEntries(
Object.entries(source).map(([key, value]) => [ Object.entries(source).map(([key, value]) => [
key, key,
isUndefined(source[key]) ? target[key] : value, isUndefined(source[key]) ? target[key] : value,
]), ]),
); ) as SSH | Server;
/** /**
* Merge cli arguemens with config object * Merge cli arguemens with config object
@ -92,14 +93,14 @@ const objectAssign = (
* *
*/ */
export function mergeCliConf( export function mergeCliConf(
opts: Record<string, any>, opts: Record<string, confValue>,
config: Config, config: Config,
): Config { ): Config {
const ssl = { const ssl = {
key: opts['ssl-key'], key: opts['ssl-key'],
cert: opts['ssl-cert'], cert: opts['ssl-cert'],
...config.ssl, ...config.ssl,
}; } as SSL;
return { return {
ssh: objectAssign(config.ssh, { ssh: objectAssign(config.ssh, {
user: opts['ssh-user'], user: opts['ssh-user'],
@ -117,10 +118,10 @@ export function mergeCliConf(
title: opts.title, title: opts.title,
bypassHelmet: opts['bypass-helmet'], bypassHelmet: opts['bypass-helmet'],
}) as Server, }) as Server,
command: isUndefined(opts.command) ? config.command : opts.command, command: isUndefined(opts.command) ? config.command : `${opts.command}`,
forceSSH: isUndefined(opts['force-ssh']) forceSSH: isUndefined(opts['force-ssh'])
? config.forceSSH ? config.forceSSH
: opts['force-ssh'], : ensureBoolean(opts['force-ssh']),
ssl: isUndefined(ssl.key) || isUndefined(ssl.cert) ? undefined : ssl, ssl: isUndefined(ssl.key) || isUndefined(ssl.cert) ? undefined : ssl,
}; };
} }

2
src/shared/interfaces.ts

@ -1,4 +1,5 @@
export interface SSH { export interface SSH {
[s: string]: string | number | boolean | undefined;
user: string; user: string;
host: string; host: string;
auth: string; auth: string;
@ -19,6 +20,7 @@ export interface SSLBuffer {
} }
export interface Server { export interface Server {
[s: string]: string | number | boolean;
port: number; port: number;
host: string; host: string;
title: string; title: string;

Loading…
Cancel
Save