2024-07-13 15:44:13 +08:00
|
|
|
|
import fs from 'fs'
|
2024-06-24 13:11:19 +08:00
|
|
|
|
import { version } from '../../../package.json'
|
2024-07-13 15:44:13 +08:00
|
|
|
|
import { define } from '../../define/define'
|
|
|
|
|
|
const fspromises = fs.promises
|
|
|
|
|
|
import { MJSettingService } from '../../define/db/service/SoftWare/mjSettingService'
|
|
|
|
|
|
import _, { isEmpty } from 'lodash'
|
|
|
|
|
|
import { SoftwareService } from '../../define/db/service/SoftWare/softwareService'
|
|
|
|
|
|
import { CheckFileOrDirExist } from '../../define/Tools/file'
|
|
|
|
|
|
import path from 'path'
|
2024-06-24 13:11:19 +08:00
|
|
|
|
|
2024-07-13 15:44:13 +08:00
|
|
|
|
//#region 通用同步
|
2024-06-24 13:11:19 +08:00
|
|
|
|
|
2024-07-13 15:44:13 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 通用的自动初始化配置,所有的配置都在这里面进行初始化
|
|
|
|
|
|
*/
|
|
|
|
|
|
async function GlobalAutoSync() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let _softwareService = await SoftwareService.getInstance()
|
|
|
|
|
|
let softData = _softwareService.GetSoftwareData(null)
|
|
|
|
|
|
let initConifgPath
|
|
|
|
|
|
let isExist = await CheckFileOrDirExist(define.config_path)
|
|
|
|
|
|
if (isExist) {
|
|
|
|
|
|
initConifgPath = define.config_path
|
|
|
|
|
|
} else {
|
|
|
|
|
|
initConifgPath = path.join(define.init_config_path, 'global_setting.json')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是不是有数据,没有的话初始化整个设置数据,有的话判断是不是有全局设置,没有在设置
|
|
|
|
|
|
if (softData.data.length <= 0) {
|
|
|
|
|
|
// 初始化全局设置
|
|
|
|
|
|
let initGlobalConfig = await fspromises.readFile(initConifgPath, 'utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
let addSfotwareRes = _softwareService.AddSfotware({
|
|
|
|
|
|
theme: 'light',
|
|
|
|
|
|
reverse_display_show: false,
|
|
|
|
|
|
reverse_show_book_striped: false,
|
2024-08-04 15:00:00 +08:00
|
|
|
|
reverse_data_table_size: 'small',
|
2024-07-13 15:44:13 +08:00
|
|
|
|
globalSetting: initGlobalConfig
|
|
|
|
|
|
})
|
|
|
|
|
|
if (addSfotwareRes.code == 1) {
|
|
|
|
|
|
global.logger.info('AutoSunc_GlobalAutoSync', '初始化全局设置成功')
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 有,只需要检查全局设置是不是存在,不存在的话初始化
|
|
|
|
|
|
let softWareData = softData.data[0]
|
|
|
|
|
|
if (softWareData.globalSetting == null || softWareData.globalSetting == '') {
|
|
|
|
|
|
let initGlobalConfig = await fspromises.readFile(initConifgPath, 'utf-8')
|
|
|
|
|
|
softWareData.globalSetting = initGlobalConfig
|
2024-09-12 14:13:09 +08:00
|
|
|
|
_softwareService.UpdateSoftware(softWareData)
|
|
|
|
|
|
global.logger.info('AutoSunc_GlobalAutoSync', '初始化全局设置成功')
|
2024-07-13 15:44:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
// 同步数据不报错,只添加日志
|
|
|
|
|
|
global.logger.error(
|
|
|
|
|
|
'AutoSunc_GlobalAutoSync',
|
|
|
|
|
|
'初始化全局设置失败,失败信息如下' + '\n' + error.toString()
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
//#region 2.2.10 版本 自动同步数据
|
2024-06-24 13:11:19 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 自动同步MJ配置数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2025-04-02 19:52:57 +08:00
|
|
|
|
async function AutoSyncMJConfig2210() {}
|
2024-06-24 13:11:19 +08:00
|
|
|
|
//#endregion
|
2024-07-13 15:44:13 +08:00
|
|
|
|
|
|
|
|
|
|
export async function AutoSync() {
|
|
|
|
|
|
// 2.2.10 版本 自动同步数据
|
2025-04-02 19:52:57 +08:00
|
|
|
|
// await AutoSyncMJConfig2210()
|
2024-07-13 15:44:13 +08:00
|
|
|
|
// 通用同步
|
|
|
|
|
|
await GlobalAutoSync()
|
|
|
|
|
|
}
|