butlerx
4 years ago
7 changed files with 54 additions and 54 deletions
@ -0,0 +1,23 @@ |
|||||
|
import JSON5 from 'json5'; |
||||
|
|
||||
|
import type { Term } from '../../shared/type'; |
||||
|
import { editor } from '../../../shared/elements'; |
||||
|
|
||||
|
export const onInput = (term: Term) => (): void => { |
||||
|
try { |
||||
|
const updated = JSON5.parse(editor.value); |
||||
|
const updatedConf = JSON.stringify(updated, null, 2); |
||||
|
if (localStorage.options === updatedConf) return; |
||||
|
Object.keys(updated).forEach(key => { |
||||
|
const value = updated[key]; |
||||
|
term.setOption(key, value); |
||||
|
}); |
||||
|
term.resizeTerm(); |
||||
|
editor.value = updatedConf; |
||||
|
editor.classList.remove('error'); |
||||
|
localStorage.options = updatedConf; |
||||
|
} catch { |
||||
|
// skip
|
||||
|
editor.classList.add('error'); |
||||
|
} |
||||
|
}; |
@ -1,14 +1,14 @@ |
|||||
import fs from 'fs-extra'; |
import fs from 'fs-extra'; |
||||
import path from 'path'; |
|
||||
import isUndefined from 'lodash/isUndefined.js'; |
import isUndefined from 'lodash/isUndefined.js'; |
||||
|
import { resolve } from 'path'; |
||||
import type { SSL, SSLBuffer } from '../../shared/interfaces'; |
import type { SSL, SSLBuffer } from '../../shared/interfaces'; |
||||
|
|
||||
export async function loadSSL(ssl?: SSL): Promise<SSLBuffer> { |
export async function loadSSL(ssl?: SSL): Promise<SSLBuffer> { |
||||
if (isUndefined(ssl) || isUndefined(ssl.key) || isUndefined(ssl.cert)) |
if (isUndefined(ssl) || isUndefined(ssl.key) || isUndefined(ssl.cert)) |
||||
return {}; |
return {}; |
||||
const [key, cert]: Buffer[] = await Promise.all([ |
const [key, cert]: Buffer[] = await Promise.all([ |
||||
fs.readFile(path.resolve(ssl.key)), |
fs.readFile(resolve(ssl.key)), |
||||
fs.readFile(path.resolve(ssl.cert)), |
fs.readFile(resolve(ssl.cert)), |
||||
]); |
]); |
||||
return { key, cert }; |
return { key, cert }; |
||||
} |
} |
||||
|
Loading…
Reference in new issue