V 2.2.11 优化MJ代理模式
This commit is contained in:
@@ -5,7 +5,7 @@ export class BookBackTaskList extends Realm.Object<BookBackTaskList> {
|
||||
id: string
|
||||
bookId: string
|
||||
bookTaskId: string
|
||||
name: string
|
||||
name: string // 任务名称,小说名+批次名+分镜名
|
||||
type: BookBackTaskType
|
||||
status: BookBackTaskStatus
|
||||
createTime: Date
|
||||
|
||||
@@ -112,6 +112,7 @@ export class BookTaskDetailModel extends Realm.Object<BookTaskDetailModel> {
|
||||
bookId: string
|
||||
bookTaskId: string
|
||||
videoPath: string | null // 视频地址
|
||||
audioPath: string | null // 音频地址
|
||||
word: string | null // 文案
|
||||
oldImage: string | null // 旧图片(用于SD的图生图)
|
||||
afterGpt: string | null // GPT生成的文案
|
||||
@@ -123,7 +124,7 @@ export class BookTaskDetailModel extends Realm.Object<BookTaskDetailModel> {
|
||||
gptPrompt: string | null // GPT提示词
|
||||
mjMessage: MJMessage | null // MJ消息
|
||||
outImagePath: string | null // 输出图片地址
|
||||
subImagePath: string[] | null // 字幕图片地址
|
||||
subImagePath: string[] | null // 子图片地址
|
||||
prompt: string | null // 提示
|
||||
adetailer: boolean // 是否开启修脸
|
||||
sdConifg: SDConfig | null // SD配置
|
||||
@@ -139,6 +140,7 @@ export class BookTaskDetailModel extends Realm.Object<BookTaskDetailModel> {
|
||||
bookId: { type: 'string', indexed: true },
|
||||
bookTaskId: { type: 'string', indexed: true },
|
||||
videoPath: 'string?',
|
||||
audioPath: 'string?',
|
||||
word: 'string?',
|
||||
oldImage: 'string?',
|
||||
afterGpt: 'string?',
|
||||
|
||||
@@ -39,9 +39,10 @@ export class RemoteMJModel extends Realm.Object<RemoteMJModel> {
|
||||
accountId: string | null
|
||||
channelId: string
|
||||
coreSize: number
|
||||
guildId: string
|
||||
mjBotChannelId: string
|
||||
nijiBotChannelId: string
|
||||
guildId: string
|
||||
enable: boolean // 是否启用
|
||||
mjBotChannelId: string | null
|
||||
nijiBotChannelId: string | null
|
||||
queueSize: number
|
||||
remark: string
|
||||
remixAutoSubmit: boolean
|
||||
@@ -59,8 +60,9 @@ export class RemoteMJModel extends Realm.Object<RemoteMJModel> {
|
||||
channelId: 'string',
|
||||
coreSize: 'int',
|
||||
guildId: 'string',
|
||||
mjBotChannelId: 'string',
|
||||
nijiBotChannelId: 'string',
|
||||
enable: 'bool',
|
||||
mjBotChannelId: 'string?',
|
||||
nijiBotChannelId: 'string?',
|
||||
queueSize: 'int',
|
||||
remark: 'string',
|
||||
remixAutoSubmit: 'bool',
|
||||
|
||||
@@ -26,14 +26,29 @@ export class BookBackTaskListService extends BaseRealmService {
|
||||
BookBackTaskListService.instance = new BookBackTaskListService()
|
||||
await super.getInstance()
|
||||
}
|
||||
await BookBackTaskListService.instance.open()
|
||||
return BookBackTaskListService.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定条件的后台任务队列
|
||||
* bookId 必填
|
||||
* @param query bookId,bookTaskId,name,type,status
|
||||
*/
|
||||
getBookBackTaskList(query) {
|
||||
try {
|
||||
// if()
|
||||
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增一个小说相关的后台任务队列
|
||||
* @param bookBackTask 要添加的小说数据
|
||||
*/
|
||||
async AddBookBackTaskList(bookBackTask) {
|
||||
AddBookBackTaskList(bookBackTask) {
|
||||
try {
|
||||
// 判断数据是不是存在
|
||||
if (
|
||||
|
||||
@@ -32,6 +32,13 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
|
||||
newBookTask[i].isAuto = false // 为新属性设置默认值
|
||||
}
|
||||
}
|
||||
if (oldRealm.schemaVersion < 3) {
|
||||
const oldBookTask = oldRealm.objects('BookTask')
|
||||
const newBookTask = newRealm.objects('BookTask')
|
||||
for (let i = 0; i < oldBookTask.length; i++) {
|
||||
newBookTask[i].audioPath = null // 为新属性设置默认值
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class BaseRealmService extends BaseService {
|
||||
@@ -72,7 +79,7 @@ export class BaseRealmService extends BaseService {
|
||||
BookTaskDetailModel
|
||||
],
|
||||
path: this.dbpath,
|
||||
schemaVersion: 2,
|
||||
schemaVersion: 3,
|
||||
migration: migration
|
||||
}
|
||||
this.realm = await Realm.open(config)
|
||||
|
||||
@@ -11,8 +11,8 @@ import { BookTaskService } from './bookTaskService'
|
||||
import { BaseRealmService } from './bookBasic.js'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
class BooKService extends BaseRealmService {
|
||||
static instance: BooKService | null = null
|
||||
export class BookService extends BaseRealmService {
|
||||
static instance: BookService | null = null
|
||||
realm: Realm
|
||||
|
||||
private constructor() {
|
||||
@@ -24,20 +24,59 @@ class BooKService extends BaseRealmService {
|
||||
* @returns
|
||||
*/
|
||||
public static async getInstance() {
|
||||
if (BooKService.instance === null) {
|
||||
BooKService.instance = new BooKService()
|
||||
if (BookService.instance === null) {
|
||||
BookService.instance = new BookService()
|
||||
await super.getInstance()
|
||||
}
|
||||
return BooKService.instance
|
||||
await BookService.instance.open()
|
||||
return BookService.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小说信息,没有找到返回null
|
||||
* @param bookId
|
||||
*/
|
||||
GetBookDataById(bookId) {
|
||||
try {
|
||||
if (isEmpty(bookId)) {
|
||||
throw new Error('获取小说信息失败,缺少小说ID')
|
||||
}
|
||||
let books = this.realm.objects<BookModel>('Book').filtered('id = $0', bookId)
|
||||
if (books.length <= 0) {
|
||||
return successMessage(null, '通过ID获取小说数据成功', 'ReverseBook_GetBookDataById')
|
||||
} else {
|
||||
// 对返回的数据进行处理
|
||||
let resBooks = Array.from(books).map((book) => {
|
||||
// 这里可以直接操作普通对象
|
||||
let bookObj = {
|
||||
...book,
|
||||
bookFolderPath: path.resolve(
|
||||
define.project_path,
|
||||
book.bookFolderPath.replace(/\\/g, '/')
|
||||
),
|
||||
oldVideoPath: book.oldVideoPath
|
||||
? path.resolve(define.project_path, book.oldVideoPath.replace(/\\/g, '/'))
|
||||
: '',
|
||||
imageFolder: book.imageFolder
|
||||
? path.resolve(define.project_path, book.imageFolder.replace(/\\/g, '/'))
|
||||
: ''
|
||||
}
|
||||
return bookObj
|
||||
})
|
||||
|
||||
return successMessage(resBooks[0], '通过ID获取小说数据成功', 'ReverseBook_GetBookDataById')
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小说信息,通过参数查询
|
||||
* @returns
|
||||
*/
|
||||
async GetBookData(bookQuery) {
|
||||
GetBookData(bookQuery) {
|
||||
try {
|
||||
await this.open()
|
||||
// 获取所有的小说数据,并进行时间降序排序
|
||||
let books = this.realm.objects<BookModel>('Book')
|
||||
let book_length = books.length
|
||||
@@ -106,7 +145,6 @@ class BooKService extends BaseRealmService {
|
||||
*/
|
||||
async AddOrModifyBook(book) {
|
||||
try {
|
||||
await this.open()
|
||||
if (book == null) {
|
||||
throw new Error('小说数据为空,无法修改')
|
||||
}
|
||||
@@ -141,6 +179,7 @@ class BooKService extends BaseRealmService {
|
||||
let bookFolderPath = path.resolve(define.project_path, book.id)
|
||||
let imageFolder = path.resolve(define.project_path, `${book.id}/tmp`)
|
||||
let oldVideoPath = path.resolve(define.project_path, `${book.id}/data/${book.id}.mp4`)
|
||||
let bookTaskImageFolder = path.resolve(imageFolder, 'output_00001')
|
||||
|
||||
// 将视频拷贝一个到项目文件下面
|
||||
if (book.oldVideoPath) {
|
||||
@@ -150,11 +189,11 @@ class BooKService extends BaseRealmService {
|
||||
// 创建对应的文件夹
|
||||
await CheckFolderExistsOrCreate(bookFolderPath)
|
||||
await CheckFolderExistsOrCreate(imageFolder)
|
||||
await CheckFolderExistsOrCreate(bookTaskImageFolder) // 创建默认的任务文件夹
|
||||
// 修改数据
|
||||
book.oldVideoPath = path.relative(define.project_path, oldVideoPath)
|
||||
this.realm.write(() => {
|
||||
this.realm.create('Book', book)
|
||||
let bookTaskImageFolder = path.resolve(imageFolder, 'output_00001')
|
||||
// 添加一个任务
|
||||
let bookTask = {
|
||||
id: uuidv4(),
|
||||
@@ -210,5 +249,3 @@ class BooKService extends BaseRealmService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default BooKService
|
||||
|
||||
@@ -6,6 +6,10 @@ import { BookTaskModel } from '../../model/Book/bookTask.js'
|
||||
import { BookTaskStatus } from '../../../enum/bookEnum.js'
|
||||
import { successMessage } from '../../../../main/generalTools.js'
|
||||
import { BaseRealmService } from './bookBasic'
|
||||
import { endsWith, isEmpty } from 'lodash'
|
||||
import { book } from '../../../../preload/book.js'
|
||||
import { DefaultObject } from 'realm/dist/public-types/schema.js'
|
||||
import { JoinPath } from '../../../Tools/file.js'
|
||||
const { v4: uuidv4 } = require('uuid')
|
||||
|
||||
let dbPath = path.resolve(define.db_path, 'book.realm')
|
||||
@@ -30,16 +34,202 @@ export class BookTaskDetailService extends BaseRealmService {
|
||||
BookTaskDetailService.instance = new BookTaskDetailService()
|
||||
await super.getInstance()
|
||||
}
|
||||
await BookTaskDetailService.instance.open()
|
||||
return BookTaskDetailService.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一条小说人物对应的详细数据
|
||||
* 更具条件查询执行的小说的分镜信息
|
||||
* @param condition 查询的条件,id,name,bookId,bookTaskId
|
||||
*/
|
||||
GetBookTaskData(condition) {
|
||||
try {
|
||||
if (condition == null) {
|
||||
throw new Error('查询小说分镜信息,查询条件不能为空')
|
||||
}
|
||||
let query = [] as string[]
|
||||
if (condition.id) {
|
||||
query.push(`id = ${condition.id}`)
|
||||
}
|
||||
if (condition.bookId) {
|
||||
query.push(`bookId = ${condition.bookId}`)
|
||||
}
|
||||
if (condition.bookTaskId) {
|
||||
query.push(`bookTaskId = ${condition.bookTaskId}`)
|
||||
}
|
||||
if (condition.name) {
|
||||
query.push(`name = ${condition.name}`)
|
||||
}
|
||||
const queryString = query.join(' && ')
|
||||
let tasksToDelete: Realm.Results<Realm.Object<DefaultObject, never> & DefaultObject>
|
||||
// 获取指定的数据
|
||||
if (queryString) {
|
||||
tasksToDelete = this.realm.objects('BookTaskDetail').filtered(queryString)
|
||||
} else {
|
||||
// 返回全部
|
||||
tasksToDelete = this.realm.objects('BookTaskDetail')
|
||||
}
|
||||
let resData = Array.from(tasksToDelete).map((item) => {
|
||||
let resObj = {
|
||||
...item,
|
||||
videoPath: JoinPath(define.project_path, item.videoPath),
|
||||
audioPath: JoinPath(define.project_path, item.audioPath),
|
||||
oldImage: JoinPath(define.project_path, item.oldImage),
|
||||
outImagePath: JoinPath(define.project_path, item.outImagePath),
|
||||
subImagePath: (item.subImagePath as string[])?.map((subImage) => {
|
||||
return JoinPath(define.project_path, subImage)
|
||||
})
|
||||
}
|
||||
return resObj
|
||||
})
|
||||
return successMessage(
|
||||
resData,
|
||||
'获取小说的分镜信息成功',
|
||||
'BookTaskDetailService_GetBookTaskData'
|
||||
)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID获取指定的小说任务分镜详细数据
|
||||
* @param bookTaskDetailId
|
||||
*/
|
||||
public GetBookTaskDetailDataById(bookTaskDetailId: string) {
|
||||
try {
|
||||
if (bookTaskDetailId == null) {
|
||||
throw new Error('获取小说任务详细信息失败,缺少ID')
|
||||
}
|
||||
|
||||
let bookTaskDetails = this.GetBookTaskData({ id: bookTaskDetailId })
|
||||
if (bookTaskDetails.data.length <= 0) {
|
||||
return successMessage(
|
||||
null,
|
||||
'未找到对应的小说任务详细信息',
|
||||
'BookTaskDetailService_GetBookTaskDetailDataById'
|
||||
)
|
||||
} else {
|
||||
return successMessage(
|
||||
bookTaskDetails.data[0],
|
||||
'获取小说任务详细信息成功',
|
||||
'BookTaskDetailService_GetBookTaskDetailDataById'
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一条小说任务对应的详细数据
|
||||
* @param BookTaskDetail
|
||||
*/
|
||||
public async AddBookTaskDetail(BookTaskDetail) {
|
||||
public AddBookTaskDetail(bookTaskDetail) {
|
||||
try {
|
||||
// 判断是不是又小说的ID
|
||||
// 判断是不是又小说ID
|
||||
if (isEmpty(bookTaskDetail.bookId) || isEmpty(bookTaskDetail.bookTaskId)) {
|
||||
throw new Error(
|
||||
'新增小说任务详细信息到数据库失败,数据不完整,缺少小说ID或者小说批次任务ID'
|
||||
)
|
||||
}
|
||||
|
||||
// 开始初始化数据(获取指定的bookId和bookTaskId)中最大的no
|
||||
let bookTaskDetails = this.realm
|
||||
.objects<BookTaskModel>('BookTaskDetail')
|
||||
.filtered(
|
||||
'bookId = $0 AND bookTaskId = $1',
|
||||
bookTaskDetail.bookId,
|
||||
bookTaskDetail.bookTaskId
|
||||
)
|
||||
|
||||
let maxNo = bookTaskDetails.max('no')
|
||||
bookTaskDetail.no = maxNo ? Number(maxNo) + 1 : 1
|
||||
let name = bookTaskDetail.no.tosString().padStart(5, '0')
|
||||
|
||||
bookTaskDetail.name = name
|
||||
bookTaskDetail.id = uuidv4()
|
||||
bookTaskDetail.createTime = new Date()
|
||||
bookTaskDetail.updateTime = new Date()
|
||||
// 开始添加
|
||||
this.transaction(() => {
|
||||
this.realm.create('BookTaskDetail', bookTaskDetail)
|
||||
})
|
||||
//创建成功,返回
|
||||
return successMessage(
|
||||
bookTaskDetail,
|
||||
'新增小说任务详细信息成功',
|
||||
'BookTaskDetailService_AddBookTaskDetail'
|
||||
)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定ID的指定数据
|
||||
* @param bookTaskDetailId
|
||||
* @param updateData
|
||||
*/
|
||||
UpdateBookTaskDetail(bookTaskDetailId: string, updateData) {
|
||||
try {
|
||||
this.transaction(() => {
|
||||
let bookTaskDetail = this.realm.objectForPrimaryKey('BookTaskDetail', bookTaskDetailId)
|
||||
if (bookTaskDetail == null) {
|
||||
throw new Error('未找到对应的小说任务详细信息')
|
||||
}
|
||||
// 开始修改
|
||||
for (let key in updateData) {
|
||||
bookTaskDetail[key] = updateData[key]
|
||||
}
|
||||
bookTaskDetail.updateTime = new Date()
|
||||
})
|
||||
return successMessage(
|
||||
null,
|
||||
'修改小说任务详细信息成功',
|
||||
'BookTaskDetailService_UpdateBookTaskDetail'
|
||||
)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除满足条件的对象吗,必传小说ID和小说任务ID
|
||||
* @param condition bookId,bookTaskId,name,id
|
||||
*/
|
||||
DeleteBookTaskDetail(condition) {
|
||||
try {
|
||||
if (isEmpty(condition.id) && isEmpty(condition.bookTaskId) && isEmpty(condition.bookId)) {
|
||||
throw new Error('删除小说分镜信息失败,没有必要参数')
|
||||
}
|
||||
let query = [] as string[]
|
||||
if (condition.id) {
|
||||
query.push(`id = ${condition.id}`)
|
||||
}
|
||||
if (condition.bookId) {
|
||||
query.push(`bookId = ${condition.bookId}`)
|
||||
}
|
||||
if (condition.bookTaskId) {
|
||||
query.push(`bookTaskId = ${condition.bookTaskId}`)
|
||||
}
|
||||
if (condition.name) {
|
||||
query.push(`name = ${condition.name}`)
|
||||
}
|
||||
|
||||
if (query.length <= 0) {
|
||||
throw new Error('删除小说分镜任务失败,没有查询条件')
|
||||
}
|
||||
const queryString = query.join(' && ')
|
||||
let tasksToDelete = this.realm.objects('BookTaskDetail').filtered(queryString)
|
||||
this.transaction(() => {
|
||||
this.realm.delete(tasksToDelete)
|
||||
})
|
||||
return successMessage(
|
||||
null,
|
||||
'删除指定的分镜任务成功',
|
||||
'BookTaskDetailService_DeleteBookTaskDetail'
|
||||
)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ export class BookTaskService extends BaseRealmService {
|
||||
BookTaskService.instance = new BookTaskService()
|
||||
await super.getInstance()
|
||||
}
|
||||
await BookTaskService.instance.open()
|
||||
return BookTaskService.instance
|
||||
}
|
||||
|
||||
@@ -36,9 +37,8 @@ export class BookTaskService extends BaseRealmService {
|
||||
* 查询满足条件的小说子任务信息
|
||||
* @param bookTaskCondition 查询条件 id,bookId,name,no,page, pageSize
|
||||
*/
|
||||
async GetBookTaskData(bookTaskCondition) {
|
||||
GetBookTaskData(bookTaskCondition) {
|
||||
try {
|
||||
await this.open()
|
||||
// 获取所有的小说数据,并进行时间降序排序
|
||||
let bookTasks = this.realm.objects<BookTaskModel>('BookTask')
|
||||
|
||||
@@ -98,10 +98,64 @@ export class BookTaskService extends BaseRealmService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过ID获取小说批次任务的数据
|
||||
* @param bookTaskId
|
||||
*/
|
||||
GetBookTaskDataById(bookTaskId: string) {
|
||||
try {
|
||||
if (bookTaskId == null) {
|
||||
throw new Error('小说任务ID不能为空')
|
||||
}
|
||||
|
||||
let bookTasks = this.GetBookTaskData({ id: bookTaskId })
|
||||
if (bookTasks.data.bookTasks.length <= 0) {
|
||||
return successMessage(null, '未找到对应的小说任务', 'BookTaskService_GetBookTaskDataById')
|
||||
} else {
|
||||
return successMessage(
|
||||
bookTasks.data.bookTasks[0],
|
||||
'查询小说任务成功',
|
||||
'BookTaskService_GetBookTaskDataById'
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改小说批次任务的状态
|
||||
* @param bookTaskId 小说批次任务Id
|
||||
* @param status 目标状态
|
||||
*/
|
||||
UpdateBookTaskStatus(bookTaskId: string, status: BookTaskStatus, errorMsg: string | null = null) {
|
||||
try {
|
||||
this.transaction(() => {
|
||||
// 修改对应小说批次任务的状态
|
||||
let bookTask = this.realm.objectForPrimaryKey('BookTask', bookTaskId)
|
||||
if (bookTask == null) {
|
||||
throw new Error('未找到对应的小说任务')
|
||||
}
|
||||
bookTask.status = status
|
||||
bookTask.updateTime = new Date()
|
||||
if (errorMsg != null) {
|
||||
bookTask.errorMsg = errorMsg
|
||||
}
|
||||
})
|
||||
|
||||
return successMessage(
|
||||
null,
|
||||
`修改小说任务状态成功,修改后的状态为${status}`,
|
||||
'BookTaskService_UpdateBookTaskStatus'
|
||||
)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// 添加一条数据
|
||||
async AddOrModifyBookTask(bookTask) {
|
||||
AddOrModifyBookTask(bookTask) {
|
||||
try {
|
||||
await this.open()
|
||||
if (bookTask == null) {
|
||||
throw new Error('添加的小说任务不能为空')
|
||||
}
|
||||
|
||||
@@ -249,7 +249,6 @@ export class MJSettingService extends BaseSoftWareService {
|
||||
if (remoteMjQuery?.id) {
|
||||
remoteMjSettings = this.realm.objects('RemoteMJ').filtered('id = $0', remoteMjQuery.id)
|
||||
}
|
||||
|
||||
let resRemoteMj = Array.from(remoteMjSettings).map((remoteMj) => {
|
||||
return {
|
||||
...remoteMj
|
||||
@@ -298,6 +297,7 @@ export class MJSettingService extends BaseSoftWareService {
|
||||
remoteMjSetting.createTime = new Date()
|
||||
remoteMjSetting.updateTime = new Date()
|
||||
remoteMjSetting.version = version
|
||||
remoteMjSetting.enable = true
|
||||
remoteMjSetting.remark = global.machineId
|
||||
|
||||
// 判断当前this.relam 是不是已经处于一个事务中
|
||||
@@ -374,6 +374,28 @@ export class MJSettingService extends BaseSoftWareService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定ID的数据
|
||||
* @param id
|
||||
*/
|
||||
DeleteRemoteMJSetting(id: string) {
|
||||
try {
|
||||
if (isEmpty(id)) {
|
||||
throw new Error('删除代理模式配置,ID不能为空')
|
||||
}
|
||||
let remoteMjSettingRes = this.realm.objects('RemoteMJ').filtered('id = $0', id)
|
||||
if (remoteMjSettingRes.length <= 0) {
|
||||
throw new Error('没有找到对应的代理模式配置信息')
|
||||
}
|
||||
this.transaction(() => {
|
||||
this.realm.delete(remoteMjSettingRes)
|
||||
})
|
||||
return successMessage(null, '删除代理API配置成功', 'MJSettingService_DeleteRemoteMjSetting')
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region MJ设置的基础设置
|
||||
@@ -540,22 +562,6 @@ export class MJSettingService extends BaseSoftWareService {
|
||||
}
|
||||
// 组合添加数据
|
||||
this.realm.write(() => {
|
||||
// 先添加RemoteMJ的数据
|
||||
let remoteSetting = mjSetting.remoteSetting ? mjSetting.remoteSetting : null
|
||||
if (remoteSetting != null) {
|
||||
let remoteSettingRes: { code: number; data: any; message: any }
|
||||
if (isEmpty(remoteSetting.id)) {
|
||||
// 新增
|
||||
remoteSettingRes = this.AddRemoteMjSetting(remoteSetting)
|
||||
} else {
|
||||
// 修改
|
||||
remoteSettingRes = this.UpdateRemoteMjSetting(remoteSetting)
|
||||
}
|
||||
if (remoteSettingRes && remoteSettingRes.code == 1) {
|
||||
mjSetting.remoteSetting = remoteSettingRes.data
|
||||
}
|
||||
}
|
||||
|
||||
// 判断API设置的数据是不是存在
|
||||
let apiSetting = mjSetting.apiSetting ? mjSetting.apiSetting : null
|
||||
if (apiSetting != null) {
|
||||
|
||||
@@ -60,7 +60,7 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
|
||||
}
|
||||
if (oldRealm.schemaVersion < 9) {
|
||||
newRealm.write(() => {
|
||||
const newSoftwares = newRealm.objects('MjSetting')
|
||||
const newSoftwares = newRealm.objects('RemoteMJ')
|
||||
for (let software of newSoftwares) {
|
||||
software.accountId = null
|
||||
}
|
||||
@@ -74,6 +74,31 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
if (oldRealm.schemaVersion < 11) {
|
||||
newRealm.write(() => {
|
||||
const newSoftwares = newRealm.objects('MjSetting')
|
||||
for (let software of newSoftwares) {
|
||||
software.enable = true
|
||||
}
|
||||
})
|
||||
}
|
||||
if (oldRealm.schemaVersion < 12) {
|
||||
newRealm.write(() => {
|
||||
const newSoftwares = newRealm.objects('RemoteMJ')
|
||||
for (let software of newSoftwares) {
|
||||
software.nijiBotChannelId = null
|
||||
software.mjBotChannelId = null
|
||||
}
|
||||
})
|
||||
}
|
||||
if (oldRealm.schemaVersion < 13) {
|
||||
newRealm.write(() => {
|
||||
const newSoftwares = newRealm.objects('RemoteMJ')
|
||||
for (let software of newSoftwares) {
|
||||
software.enable = true // 默认都是启用的
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class BaseSoftWareService extends BaseService {
|
||||
@@ -112,7 +137,7 @@ export class BaseSoftWareService extends BaseService {
|
||||
MjSettingModel
|
||||
],
|
||||
path: dbPath,
|
||||
schemaVersion: 10, // 当前版本号
|
||||
schemaVersion: 13, // 当前版本号
|
||||
migration: migration
|
||||
}
|
||||
// 判断当前全局是不是又当前这个
|
||||
|
||||
Reference in New Issue
Block a user