mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-15 04:14:46 +08:00
feat(app): 适配最新版本
- 修改软件内部分提示文本 - 添加 API KEY 掩码,防止直接输出 API KEY 内容
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
||||
} from '../types'
|
||||
import { Log } from './Log'
|
||||
import { app, BrowserWindow } from 'electron'
|
||||
import { passwordMaskingForObject } from './UtilsFunc'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
@@ -151,9 +152,7 @@ class AllConfig {
|
||||
}
|
||||
}
|
||||
this.controls.engineEnabled = engineEnabled
|
||||
let _controls = {...this.controls}
|
||||
_controls.API_KEY = _controls.API_KEY.replace(/./g, '*')
|
||||
Log.info('Set Controls:', _controls)
|
||||
Log.info('Set Controls:', passwordMaskingForObject(this.controls))
|
||||
}
|
||||
|
||||
public sendControls(window: BrowserWindow, info = true) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import { controlWindow } from '../ControlWindow'
|
||||
import { allConfig } from './AllConfig'
|
||||
import { i18n } from '../i18n'
|
||||
import { Log } from './Log'
|
||||
import { passwordMaskingForList } from './UtilsFunc'
|
||||
|
||||
export class CaptionEngine {
|
||||
appPath: string = ''
|
||||
@@ -114,12 +115,7 @@ export class CaptionEngine {
|
||||
}
|
||||
}
|
||||
Log.info('Engine Path:', this.appPath)
|
||||
if(this.command.length > 2 && this.command[this.command.length - 2] === '-k') {
|
||||
const _command = [...this.command]
|
||||
_command[_command.length -1] = _command[_command.length -1].replace(/./g, '*')
|
||||
Log.info('Engine Command:', _command)
|
||||
}
|
||||
else Log.info('Engine Command:', this.command)
|
||||
Log.info('Engine Command:', passwordMaskingForList(this.command))
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -182,7 +178,7 @@ export class CaptionEngine {
|
||||
const data_obj = JSON.parse(line)
|
||||
handleEngineData(data_obj)
|
||||
} catch (e) {
|
||||
controlWindow.sendErrorMessage(i18n('engine.output.parse.error') + e)
|
||||
// controlWindow.sendErrorMessage(i18n('engine.output.parse.error') + e)
|
||||
Log.error('Error parsing JSON:', e)
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/utils/UtilsFunc.ts
Normal file
24
src/main/utils/UtilsFunc.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
function passwordMasking(pwd: string) {
|
||||
return pwd.replace(/./g, '*')
|
||||
}
|
||||
|
||||
export function passwordMaskingForList(args: string[]) {
|
||||
const maskedArgs = [...args]
|
||||
for(let i = 1; i < maskedArgs.length; i++) {
|
||||
if(maskedArgs[i-1] === '-k' || maskedArgs[i-1] === '-okey' || maskedArgs[i-1] === '-gkey') {
|
||||
maskedArgs[i] = passwordMasking(maskedArgs[i])
|
||||
}
|
||||
}
|
||||
return maskedArgs
|
||||
}
|
||||
|
||||
export function passwordMaskingForObject(args: Record<string, any>) {
|
||||
const maskedArgs = {...args}
|
||||
for(const key in maskedArgs) {
|
||||
const lKey = key.toLowerCase()
|
||||
if(lKey.includes('api') && lKey.includes('key')) {
|
||||
maskedArgs[key] = passwordMasking(maskedArgs[key])
|
||||
}
|
||||
}
|
||||
return maskedArgs
|
||||
}
|
||||
Reference in New Issue
Block a user