Laitool v3.0.1-preview.1

This commit is contained in:
2024-08-03 12:46:12 +08:00
parent c8a46d59fb
commit 7312053a20
196 changed files with 19822 additions and 8733 deletions
@@ -13,6 +13,8 @@ export class BookBackTaskList extends Realm.Object<BookBackTaskList> {
executeType: TaskExecuteType // 任务执行类型,手动还是自动
createTime: Date
updateTime: Date
startTime: number
endTime: number
static schema: ObjectSchema = {
name: 'BookBackTaskList',
@@ -27,7 +29,9 @@ export class BookBackTaskList extends Realm.Object<BookBackTaskList> {
errorMessage: 'string?',
executeType: { type: 'string', default: TaskExecuteType.AUTO },
createTime: 'date',
updateTime: 'date'
updateTime: 'date',
startTime: 'int',
endTime: 'int'
},
primaryKey: 'id'
}
+21 -2
View File
@@ -1,4 +1,5 @@
import Realm, { ObjectSchema } from 'realm'
// @ts-ignore
import Realm from 'realm'
import { BookType } from '../../../enum/bookEnum'
export class BookModel extends Realm.Object<BookModel> {
@@ -11,12 +12,21 @@ export class BookModel extends Realm.Object<BookModel> {
oldVideoPath: string | null
srtPath: string | null
audioPath: string | null
draftSrtStyle: string | null // 草稿字幕样式
backgroundMusic: string | null // 背景音乐ID
friendlyReminder: string | null // 友情提示
updateTime: Date
createTime: Date
version: string
imageStyle: string[] | null // 软件内置的样式
autoAnalyzeCharacter: string | null // 自动分析角色设置
customizeImageStyle: string[] | null // 自定义的样式
videoConfig: string | null // 合成视频设置
prefixPrompt: string | null // 前缀
suffixPrompt: string | null // 后缀
subtitlePosition: string | null
static schema: ObjectSchema = {
static schema: Realm.ObjectSchema = {
name: 'Book',
properties: {
id: 'string',
@@ -27,10 +37,19 @@ export class BookModel extends Realm.Object<BookModel> {
oldVideoPath: 'string?',
srtPath: 'string?',
audioPath: 'string?',
draftSrtStyle : 'string?',
backgroundMusic: 'string?',
friendlyReminder: 'string?',
imageFolder: 'string?',
updateTime: 'date',
createTime: 'date',
version: 'string',
imageStyle: 'string?[]',
autoAnalyzeCharacter: 'string?',
customizeImageStyle: 'string?[]',
videoConfig: "string?",
prefixPrompt: "string?",
suffixPrompt: "string?",
subtitlePosition: 'string?'
},
// 主键为_id
+60 -6
View File
@@ -1,5 +1,40 @@
import Realm, { ObjectSchema } from 'realm'
import { BookTaskStatus, BookType } from '../../../enum/bookEnum'
import { BookImageCategory, BookTaskStatus, BookType } from '../../../enum/bookEnum'
export class ImageDefineModel extends Realm.Object<ImageDefineModel> {
label: string
key: string
value: string
children: string
type: string
prompt: string
image_url: string
cref_cw: number
lora: string
chinese_prompt: string
lora_weight: number
show_image: string
isShow: true
static schema: ObjectSchema = {
name: 'ImageDefine',
properties: {
label: 'string',
key: 'string',
value: 'string',
children: 'string',
type: 'string',
prompt: 'string',
image_url: 'string',
cref_cw: 'int',
lora: 'string',
chinese_prompt: 'string',
lora_weight: 'int',
show_image: 'string',
isShow: 'bool'
},
primaryKey: 'key'
}
}
export class BookTaskModel extends Realm.Object<BookTaskModel> {
id: string
@@ -9,14 +44,24 @@ export class BookTaskModel extends Realm.Object<BookTaskModel> {
generateVideoPath: string | null
srtPath: string | null
audioPath: string | null
draftSrtStyle: string | null // 草稿字幕样式
backgroundMusic: string | null // 背景音乐ID
friendlyReminder: string | null // 友情提示
imageFolder: string | null
styleList: Realm.List<string> | null
prefix: string | null
imageStyle: string[] | null // 软件内置的样式
autoAnalyzeCharacter: string | null // 自动分析角色设置
customizeImageStyle: string[] | null // 自定义的样式
videoConfig: string | null // 合成视频设置
prefixPrompt: string | null // 前缀
suffixPrompt: string | null // 后缀
styleList: string[] | null
status: BookTaskStatus
errorMsg: string | null
isAuto: boolean // 是否自动
updateTime: Date
createTime: Date
imageCategory: BookImageCategory // 图片出图方式
subImageFolder: string[] | null // 出图的子文件夹
static schema: ObjectSchema = {
name: 'BookTask',
@@ -28,14 +73,23 @@ export class BookTaskModel extends Realm.Object<BookTaskModel> {
generateVideoPath: 'string?',
srtPath: 'string?',
audioPath: 'string?',
draftSrtStyle: 'string?',
backgroundMusic: 'string?',
friendlyReminder: 'string?',
imageFolder: 'string?',
styleList: 'string[]',
prefix: 'string?',
subImageFolder: "string?[]",
imageStyle: 'string?[]',
autoAnalyzeCharacter: 'string?',
customizeImageStyle: 'string?[]',
videoConfig: "string?",
prefixPrompt: "string?",
suffixPrompt: "string?",
status: 'string',
errorMsg: 'string?',
isAuto: 'bool',
updateTime: 'date',
createTime: 'date'
createTime: 'date',
imageCategory: 'string',
},
// 主键为_id
primaryKey: 'id'
+30 -4
View File
@@ -5,8 +5,8 @@ import {
BookTaskStatus,
BookType,
MJAction,
MJCategroy
} from '../../../enum/bookEnum'
import { MJImageType } from '../../../enum/mjEnum'
export class Subtitle extends Realm.Object<Subtitle> {
startTime: number
@@ -29,7 +29,7 @@ export class MJMessage extends Realm.Object<MJMessage> {
id: string
mjApiUrl: string | null
progress: number
category: MJCategroy
category: MJImageType
imageClick: string | null // 图片点击(显示的小的)
imageShow: string | null // 图片实际的地址
messageId: string // 消息ID(可以是MJ中的,也可以是API中的)
@@ -105,6 +105,26 @@ export class SDConfig extends Realm.Object<SDConfig> {
}
}
// 放反推的提示词的对象
export class ReversePrompt extends Realm.Object<ReversePrompt> {
id: string
bookTaskDetailId: string
prompt: string
promptCN: string
isSelect: boolean
static schema: ObjectSchema = {
name: 'ReversePrompt',
properties: {
id: 'string',
bookTaskDetailId: "string",
prompt: 'string',
promptCN: 'string',
isSelect: 'bool'
},
primaryKey: 'id'
}
}
export class BookTaskDetailModel extends Realm.Object<BookTaskDetailModel> {
id: string
no: number
@@ -119,16 +139,19 @@ export class BookTaskDetailModel extends Realm.Object<BookTaskDetailModel> {
startTime: number | null // 开始时间
endTime: number | null // 结束时间
timeLimit: string | null // 事件实现(0 -- 3000
subValue: Realm.List<Subtitle> | null // 包含的字幕数据
subValue: string | null // 包含的字幕数据
characterTags: string[] | null // 角色标签
gptPrompt: string | null // GPT提示词
mjMessage: MJMessage | null // MJ消息
outImagePath: string | null // 输出图片地址
subImagePath: string[] | null // 子图片地址
imageLock: boolean // 图片锁
prompt: string | null // 提示
adetailer: boolean // 是否开启修脸
sdConifg: SDConfig | null // SD配置
reversePrompt: ReversePrompt[] | null // 反推的提示词(数组)
subtitlePosition: string | null // 字幕位置
status: BookTaskStatus
createTime: Date
updateTime: Date
@@ -148,16 +171,19 @@ export class BookTaskDetailModel extends Realm.Object<BookTaskDetailModel> {
startTime: 'int?',
endTime: 'int?',
timeLimit: 'string?',
subValue: { type: 'list', objectType: 'Subtitle' },
subValue: 'string?',
reversePrompt: { type: 'list', objectType: 'ReversePrompt' },
characterTags: { type: 'list', objectType: 'string' },
gptPrompt: 'string?',
mjMessage: 'MJMessage?',
outImagePath: 'string?',
subImagePath: 'string[]',
imageLock: 'bool',
prompt: 'string?',
adetailer: 'bool',
sdConifg: 'SDConfig?',
subtitlePosition: 'string?',
status: "string",
createTime: 'date',
updateTime: 'date'
},
+5 -1
View File
@@ -11,6 +11,8 @@ export class SoftwareModel extends Realm.Object<SoftwareModel> {
ttsSetting: string | null // TTS设置的json字符串
writeSetting: string | null // 文案的相关配置的json字符串
aiSetting: string | null // AI相关的配置的json字符串
watermarkSetting: string | null // 水印相关的配置的json字符串
translationSetting: string | null // 翻译相关的配置的json字符串
static schema: ObjectSchema = {
name: 'Software',
@@ -23,7 +25,9 @@ export class SoftwareModel extends Realm.Object<SoftwareModel> {
globalSetting: 'string',
ttsSetting: 'string?', // 可空
writeSetting: 'string?',
aiSetting: 'string?'
aiSetting: 'string?',
watermarkSetting: 'string?',
translationSetting: 'string?'
},
// 主键为_id
primaryKey: 'id'
@@ -1,21 +1,16 @@
import Realm from 'realm'
import path from 'path'
import { BaseService } from '../baseService.js'
import { define } from '../../../define.js'
import { BookTaskModel } from '../../model/Book/bookTask.js'
import {
BookBackTaskStatus,
BookBackTaskType,
BookTaskStatus,
TaskExecuteType
} from '../../../enum/bookEnum.js'
import { errorMessage, successMessage } from '../../../../main/generalTools.js'
import { errorMessage, successMessage } from '../../../../main/Public/generalTools'
import { BaseRealmService } from './bookBasic'
import { isEmpty } from 'lodash'
import { DefaultObject } from 'realm/dist/public-types/schema.js'
import { BookModel } from '../../model/Book/book.js'
import { OtherData } from '../../../enum/softwareEnum.js'
import { BookBackTaskList } from '../../model/Book/BookBackTaskListModel.js'
import { Book } from '../../../../model/book.js'
import { GeneralResponse } from '../../../../model/generalResponse.js'
const { v4: uuidv4 } = require('uuid')
export class BookBackTaskListService extends BaseRealmService {
@@ -44,7 +39,7 @@ export class BookBackTaskListService extends BaseRealmService {
* bookId 和 status 必填一个
* @param query bookIdbookTaskIdnametypestatus
*/
GetBookBackTaskList(query) {
GetBookBackTaskList(query: Book.QueryBookBackTaskCondition) {
try {
if (query == null) {
throw new Error('查询后台队列任务失败,没有查询条件')
@@ -53,33 +48,36 @@ export class BookBackTaskListService extends BaseRealmService {
throw new Error('查询后台队列任务失败,没有查询条件')
}
// 构建查询条件
// 下面时可空的条件
let queryString = ''
if (query.bookId) {
queryString = `bookId = ${query.bookId}`
}
if (query.bookTaskId) {
queryString += ` && bookTaskId = ${query.bookTaskId}`
}
if (query.name) {
queryString += ` && name = ${query.name}`
}
if (query.type) {
queryString += ` && type = ${query.type}`
}
if (query.status) {
queryString += ` && status = ${query.status}`
}
if (query.executeType) {
queryString += ` && executeType = ${query.executeType}`
}
// 获取数据
let tasks = this.realm
.objects('BookBackTaskList')
.filtered(queryString)
.sorted('createTime', true)
// 构建查询条件
if (query.id) {
tasks.filtered('id = $0', query.id)
}
if (query.bookId) {
tasks.filtered('bookId = $0', query.bookId)
}
if (query.bookTaskId) {
tasks.filtered('bookTaskId = $0', query.bookTaskId)
}
if (query.name) {
tasks.filtered('name = $0', query.name)
}
if (query.type) {
tasks.filtered('type = $0', query.type)
}
if (query.status) {
tasks.filtered('status = $0', query.status)
}
if (query.executeType) {
tasks.filtered('executeType = $0', query.executeType)
}
let res
if (query.count) {
res = tasks.slice(0, query.count)
@@ -107,12 +105,12 @@ export class BookBackTaskListService extends BaseRealmService {
let tasks = this.realm
.objects<BookBackTaskList>('BookBackTaskList')
.filtered(
'status == $0 && executeType == $1',
'(status == $0 || status == $1) && executeType == $2',
BookBackTaskStatus.WAIT,
BookBackTaskStatus.RECONNECT,
executeType ? executeType : TaskExecuteType.AUTO
)
.sorted('createTime', false)
if (count != null) {
tasks = tasks.slice(0, count) as unknown as Realm.Results<BookBackTaskList>
}
@@ -169,9 +167,8 @@ export class BookBackTaskListService extends BaseRealmService {
}
// 开始往数据库中写数据
let name = `${book.name}-${bookTask ? bookTask.name : 'default'}-${
bookTaskDetail ? bookTaskDetail.name : 'default'
}-${taskType}`
let name = `${book.name}-${bookTask ? bookTask.name : 'default'}-${bookTaskDetail ? bookTaskDetail.name : 'default'
}-${taskType}`
let bookBackTask = {
id: uuidv4(),
@@ -183,15 +180,14 @@ export class BookBackTaskListService extends BaseRealmService {
executeType: executeType,
status: BookBackTaskStatus.WAIT,
createTime: new Date(),
updateTime: new Date()
}
updateTime: new Date(),
startTime: 0,
endTime: 0
} as TaskModal.Task
this.realm.write(() => {
this.realm.create('BookBackTaskList', bookBackTask)
})
// 添加成功之后,调用开始执行任务的方法
await global.taskManager.ExecuteAutoTask()
return successMessage(
bookBackTask,
'新增后台队列任务到数据库成功',
@@ -210,7 +206,7 @@ export class BookBackTaskListService extends BaseRealmService {
* (对于后台的队列任务只能修改状态)和错误信息
* @param bookBackTask 修改的数据
*/
UpdateTaskStatus(bookBackTask) {
UpdateTaskStatus(bookBackTask: Book.UpdateBookTaskListStatus): GeneralResponse.SuccessItem {
try {
// 判断数据是不是存在
if (isEmpty(bookBackTask.id) || isEmpty(bookBackTask.status)) {
@@ -219,7 +215,7 @@ export class BookBackTaskListService extends BaseRealmService {
// 开始修改
this.transaction(() => {
// 获取指定ID的队列任务
let _bookBackTask = this.realm.objectForPrimaryKey('BookBackTaskList', bookBackTask.id)
let _bookBackTask = this.realm.objectForPrimaryKey('BookBackTaskList', bookBackTask.id) as TaskModal.Task
// 判断数据是不是存在
if (_bookBackTask == null) {
throw new Error('修改后台队列任务失败,数据不存在')
@@ -229,6 +225,16 @@ export class BookBackTaskListService extends BaseRealmService {
if (bookBackTask.errorMessage) {
_bookBackTask.errorMessage = bookBackTask.errorMessage
}
// 根据状态修改结束和完成时间
if (bookBackTask.status == BookBackTaskStatus.RUNNING) {
_bookBackTask.startTime = new Date().getTime()
} else if (bookBackTask.status == BookBackTaskStatus.DONE || bookBackTask.status == BookBackTaskStatus.FAIL || bookBackTask.status == BookBackTaskStatus.PAUSE) {
_bookBackTask.endTime = new Date().getTime()
} else if (bookBackTask.status == BookBackTaskStatus.RECONNECT) {
_bookBackTask.startTime = 0;
_bookBackTask.endTime = 0;
}
})
return successMessage(
bookBackTask,
+81 -2
View File
@@ -7,12 +7,13 @@ import path from 'path'
import {
BookTaskDetailModel,
MJMessage,
ReversePrompt,
SDConfig,
Subtitle,
WebuiConfig
} from '../../model/Book/bookTaskDetail'
import { BookBackTaskList } from '../../model/Book/BookBackTaskListModel'
import { TaskExecuteType } from '../../../enum/bookEnum'
import { BookTaskStatus, TaskExecuteType } from '../../../enum/bookEnum'
import { version } from '../../../../../package.json'
let dbPath = path.resolve(define.db_path, 'book.realm')
@@ -77,6 +78,83 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
newBookTask[i].subtitlePosition = null // 设置字幕位置的默认值
}
}
if (oldRealm.schemaVersion < 9) {
const oldBookTask = oldRealm.objects('BookBackTaskList')
const newBookTask = newRealm.objects('BookBackTaskList')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].startTime = 0
newBookTask[i].endTime = 0
}
}
if (oldRealm.schemaVersion < 10) {
const oldBookTask = oldRealm.objects('BookTaskDetail')
const newBookTask = newRealm.objects('BookTaskDetail')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].status = BookTaskStatus.WAIT
}
}
if (oldRealm.schemaVersion < 11) {
const oldBookTask = oldRealm.objects('BookTaskDetail')
const newBookTask = newRealm.objects('BookTaskDetail')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].reversePrompt = null
}
}
if (oldRealm.schemaVersion < 13) {
const oldBookTask = oldRealm.objects('ReversePrompt')
const newBookTask = newRealm.objects('ReversePrompt')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].promptCN = null;
newBookTask[i].isSelect = false;
}
}
if (oldRealm.schemaVersion < 15) {
const oldBookTask = oldRealm.objects('BookTaskDetail')
const newBookTask = newRealm.objects('BookTaskDetail')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].imageCategory = null;
}
}
if (oldRealm.schemaVersion < 16) {
const oldBookTask = oldRealm.objects('BookTask')
const newBookTask = newRealm.objects('BookTask')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].subImageFolder = null;
}
}
if (oldRealm.schemaVersion < 17) {
const oldBookTask = oldRealm.objects('BookTaskDetail')
const newBookTask = newRealm.objects('BookTaskDetail')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].imageLock = false;
}
}
if (oldRealm.schemaVersion < 19) {
const oldBookTask = oldRealm.objects('Book')
const newBookTask = newRealm.objects('Book')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].draftSrtStyle = null;
newBookTask[i].backgroundMusic = null;
newBookTask[i].friendlyReminder = null;
}
}
if (oldRealm.schemaVersion < 20) {
const oldBookTask = oldRealm.objects('BookTask')
const newBookTask = newRealm.objects('BookTask')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].draftSrtStyle = null;
newBookTask[i].backgroundMusic = null;
newBookTask[i].friendlyReminder = null;
}
}
if (oldRealm.schemaVersion < 21) {
const oldBookTask = oldRealm.objects('BookTaskDetail')
const newBookTask = newRealm.objects('BookTaskDetail')
for (let i = 0; i < oldBookTask.length; i++) {
newBookTask[i].subValue = '[]'
}
}
}
export class BaseRealmService extends BaseService {
@@ -114,10 +192,11 @@ export class BaseRealmService extends BaseService {
SDConfig,
WebuiConfig,
BookTaskModel,
ReversePrompt,
BookTaskDetailModel
],
path: this.dbpath,
schemaVersion: 8,
schemaVersion: 21,
migration: migration
}
this.realm = await Realm.open(config)
+36 -13
View File
@@ -3,13 +3,16 @@ import { BookModel } from '../../model/Book/book.js'
import path from 'path'
import { BaseService } from '../baseService.js'
import { define } from '../../../define.js'
import { BookTaskStatus, BookType } from '../../../enum/bookEnum.js'
import { successMessage } from '../../../../main/generalTools.js'
import { CheckFolderExistsOrCreate, CopyFileOrFolder } from '../../../Tools/file.js'
import { BookImageCategory, BookTaskStatus, BookType } from '../../../enum/bookEnum.js'
import { successMessage } from '../../../../main/Public/generalTools'
import { CheckFolderExistsOrCreate, CopyFileOrFolder } from '../../../Tools/file'
const { v4: uuidv4 } = require('uuid')
import { BookTaskService } from './bookTaskService'
import { BaseRealmService } from './bookBasic.js'
import { isEmpty } from 'lodash'
import { FfmpegOptions } from '../../../../main/Service/ffmpegOptions.js'
import { version } from '../../../../../package.json'
import { Book } from '../../../../model/book.js'
export class BookService extends BaseRealmService {
static instance: BookService | null = null
@@ -36,14 +39,14 @@ export class BookService extends BaseRealmService {
* 获取小说信息,没有找到返回null
* @param bookId
*/
GetBookDataById(bookId) {
GetBookDataById(bookId): Book.SelectBook | null {
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')
return null
} else {
// 对返回的数据进行处理
let resBooks = Array.from(books).map((book) => {
@@ -63,8 +66,7 @@ export class BookService extends BaseRealmService {
}
return bookObj
})
return successMessage(resBooks[0], '通过ID获取小说数据成功', 'ReverseBook_GetBookDataById')
return resBooks[0]
}
} catch (error) {
throw error
@@ -120,8 +122,10 @@ export class BookService extends BaseRealmService {
: '',
imageFolder: book.imageFolder
? path.resolve(define.project_path, book.imageFolder.replace(/\\/g, '/'))
: ''
}
: '',
imageStyle: book.imageStyle ? Array.from(book.imageStyle) : [],
customizeImageStyle: book.customizeImageStyle ? Array.from(book.imageStyle) : [],
} as Book.SelectBook
return bookObj
})
@@ -186,14 +190,31 @@ export class BookService extends BaseRealmService {
await CopyFileOrFolder(book.oldVideoPath, oldVideoPath)
}
let ffmpegOptions = new FfmpegOptions();
let res = await ffmpegOptions.FfmpegCompressVideo(oldVideoPath, 800, "2000k")
// 创建对应的文件夹
await CheckFolderExistsOrCreate(bookFolderPath)
await CheckFolderExistsOrCreate(imageFolder)
await CheckFolderExistsOrCreate(bookTaskImageFolder) // 创建默认的任务文件夹
// 修改数据
book.oldVideoPath = path.relative(define.project_path, oldVideoPath)
let imageCategory = BookImageCategory.MJ
if (book.type == BookType.SD_REVERSE) {
imageCategory = BookImageCategory.SD
} else if (book.type == BookType.MJ_REVERSE) {
imageCategory = BookImageCategory.MJ
} else if (book.type == BookType.ORIGINAL) {
imageCategory = BookImageCategory.MJ
} else {
throw new Error('未知的小说类型')
}
this.realm.write(() => {
book.version = version
this.realm.create('Book', book)
// 添加一个任务
let bookTask = {
id: uuidv4(),
@@ -210,7 +231,9 @@ export class BookService extends BaseRealmService {
errorMsg: null,
isAuto: false,
updateTime: new Date(),
createTime: new Date()
createTime: new Date(),
version: version,
imageCategory: imageCategory
}
// 添加任务
@@ -265,7 +288,7 @@ export class BookService extends BaseRealmService {
// 检查小说ID对应的数据是不是存在
let bookRes = this.GetBookDataById(bookId)
if (bookRes.data == null) {
if (bookRes == null) {
throw new Error('修改小说数据失败,小说ID对应的数据不存在')
}
@@ -279,11 +302,11 @@ export class BookService extends BaseRealmService {
})
bookRes = this.GetBookDataById(bookId)
if (bookRes.data == null) {
if (bookRes == null) {
throw new Error('获取修改后的小说数据失败,小说ID对应的数据不存在')
}
return successMessage(bookRes.data, '修改小说数据成功', 'ReverseBook_UpdateBookData')
return successMessage(bookRes, '修改小说数据成功', 'ReverseBook_UpdateBookData')
} catch (error) {
throw error
}
@@ -4,19 +4,21 @@ import { BaseService } from '../baseService.js'
import { define } from '../../../define.js'
import { BookTaskModel } from '../../model/Book/bookTask.js'
import { BookTaskStatus } from '../../../enum/bookEnum.js'
import { successMessage } from '../../../../main/generalTools.js'
import { successMessage } from '../../../../main/Public/generalTools'
import { BaseRealmService } from './bookBasic'
import { endsWith, isEmpty } from 'lodash'
import { cloneDeep, 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'
import { BookTaskDetailModel } from '../../model/Book/bookTaskDetail.js'
import { JoinPath } from '../../../Tools/file'
import { BookTaskDetailModel, ReversePrompt } from '../../model/Book/bookTaskDetail.js'
const { v4: uuidv4 } = require('uuid')
import { Book } from "../../../../model/book"
import { GeneralResponse } from '../../../../model/generalResponse.js'
let dbPath = path.resolve(define.db_path, 'book.realm')
// 版本迁移
const migration = (oldRealm: Realm, newRealm: Realm) => {}
const migration = (oldRealm: Realm, newRealm: Realm) => { }
export class BookTaskDetailService extends BaseRealmService {
static instance: BookTaskDetailService | null = null
@@ -43,7 +45,7 @@ export class BookTaskDetailService extends BaseRealmService {
* 更具条件查询执行的小说的分镜信息
* @param condition 查询的条件,idnamebookIdbookTaskId
*/
GetBookTaskData(condition) {
GetBookTaskData(condition: Book.QueryBookTaskDetailCondition) {
try {
if (condition == null) {
throw new Error('查询小说分镜信息,查询条件不能为空')
@@ -62,6 +64,7 @@ export class BookTaskDetailService extends BaseRealmService {
tasksToDelete = tasksToDelete.filtered('name==$0', condition.name)
}
let resData = Array.from(tasksToDelete).map((item) => {
let resObj = {
...item,
@@ -71,9 +74,17 @@ export class BookTaskDetailService extends BaseRealmService {
outImagePath: JoinPath(define.project_path, item.outImagePath),
subImagePath: (item.subImagePath as string[])?.map((subImage) => {
return JoinPath(define.project_path, subImage)
})
}),
characterTags: item.characterTags ? item.characterTags.map((tag) => tag) : null,
subValue: item.subValue,
reversePrompt: item.reversePrompt.map((reversePrompt) => {
return {
...reversePrompt
}
}),
mjMessage: item.mjMessage ? item.mjMessage.toJSON() : null,
}
return resObj
return cloneDeep(resObj)
})
return successMessage(
resData,
@@ -89,7 +100,7 @@ export class BookTaskDetailService extends BaseRealmService {
* 通过ID获取指定的小说任务分镜详细数据
* @param bookTaskDetailId
*/
public GetBookTaskDetailDataById(bookTaskDetailId: string) {
public GetBookTaskDetailDataById(bookTaskDetailId: string): Book.SelectBookTaskDetail {
try {
if (bookTaskDetailId == null) {
throw new Error('获取小说任务详细信息失败,缺少ID')
@@ -97,17 +108,9 @@ export class BookTaskDetailService extends BaseRealmService {
let bookTaskDetails = this.GetBookTaskData({ id: bookTaskDetailId })
if (bookTaskDetails.data.length <= 0) {
return successMessage(
null,
'未找到对应的小说任务详细信息',
'BookTaskDetailService_GetBookTaskDetailDataById'
)
return null;
} else {
return successMessage(
bookTaskDetails.data[0],
'获取小说任务详细信息成功',
'BookTaskDetailService_GetBookTaskDetailDataById'
)
return bookTaskDetails.data[0]
}
} catch (error) {
throw error
@@ -142,6 +145,7 @@ export class BookTaskDetailService extends BaseRealmService {
bookTaskDetail.name = name
bookTaskDetail.id = uuidv4()
bookTaskDetail.imageLock = false
bookTaskDetail.createTime = new Date()
bookTaskDetail.updateTime = new Date()
bookTaskDetail.adetailer = false // 先写死false
@@ -165,7 +169,7 @@ export class BookTaskDetailService extends BaseRealmService {
* @param bookTaskDetailId
* @param updateData
*/
UpdateBookTaskDetail(bookTaskDetailId: string, updateData) {
UpdateBookTaskDetail(bookTaskDetailId: string, updateData: Book.SelectBookTaskDetail) {
try {
this.transaction(() => {
let bookTaskDetail = this.realm.objectForPrimaryKey('BookTaskDetail', bookTaskDetailId)
@@ -188,6 +192,53 @@ export class BookTaskDetailService extends BaseRealmService {
}
}
UpdateBookTaskDetailMjMessage(bookTaskDetailId: string, mjMessage: Book.MJMessage): void {
try {
this.transaction(() => {
let mjMessageRes = this.realm.objectForPrimaryKey('MJMessage', bookTaskDetailId)
let bookTaskDetail = this.realm.objectForPrimaryKey('BookTaskDetail', bookTaskDetailId)
if (bookTaskDetail.mjMessage == null) {
// 新增
mjMessage.id = bookTaskDetailId
bookTaskDetail.mjMessage = mjMessage
} else {
for (const key in mjMessage) {
mjMessageRes[key] = mjMessage[key]
}
}
})
} catch (error) {
throw error
}
}
/**
* 更新指定ID的反推提示词数据
* @param bookTaskDetailId 分镜数据的ID
* @param reversePromptId 反推出来的提示词ID
* @param updateData 要更新的数据
*/
UpdateBookTaskDetailReversePrompt(bookTaskDetailId: string, reversePromptId: string, reversePrompt: Book.ReversePrompt): GeneralResponse.SuccessItem {
try {
this.transaction(() => {
let bookTaskDetails = this.realm.objects<ReversePrompt>("ReversePrompt");
bookTaskDetails = bookTaskDetails.filtered("id = $0 && bookTaskDetailId = $1", reversePromptId, bookTaskDetailId);
if (bookTaskDetails.length <= 0) {
throw new Error("未找到执行的翻译数据,无法写回")
}
let bookTaskDetail = bookTaskDetails[0];
// 直接写入
for (const key in reversePrompt) {
bookTaskDetail[key] = reversePrompt[key]
}
})
return successMessage(null, `${reversePromptId} 更新完成`, "BookTaskDetailService_UpdateBookTaskDetailReversePrompt")
} catch (error) {
throw error
}
}
/**
* 删除满足条件的对象吗,必传小说ID和小说任务ID
* @param condition bookIdbookTaskIdnameid
@@ -223,4 +274,18 @@ export class BookTaskDetailService extends BaseRealmService {
throw error
}
}
/**
* 删除指定ID的小说任务详细数据中的所有的反推提示词数据
* @param bookTaskDetailId 小说分镜的ID
*/
DeleteBookTaskDetailReversePromptById(bookTaskDetailId: string): void {
let bookTaskDetail = this.realm.objectForPrimaryKey('BookTaskDetail', bookTaskDetailId);
if (bookTaskDetail == null) {
throw new Error('删除小说任务详细信息的反推提示词失败,未找到对应的分镜信息')
}
this.transaction(() => {
this.realm.delete(bookTaskDetail.reversePrompt)
})
}
}
+115 -21
View File
@@ -1,24 +1,29 @@
import Realm from 'realm'
import path from 'path'
import { BaseService } from '../baseService.js'
import { define } from '../../../define.js'
import { BookTaskModel } from '../../model/Book/bookTask.js'
import { BookBackTaskStatus, BookTaskStatus } from '../../../enum/bookEnum.js'
import { successMessage } from '../../../../main/generalTools.js'
import { BookBackTaskStatus, BookImageCategory, BookTaskStatus } from '../../../enum/bookEnum.js'
import { successMessage } from '../../../../main/Public/generalTools'
import { BaseRealmService } from './bookBasic'
import { isEmpty } from 'lodash'
import { JoinPath } from '../../../Tools/file.js'
import { JoinPath } from '../../../Tools/file'
import { BookBackTaskList } from '../../model/Book/BookBackTaskListModel.js'
const { v4: uuidv4 } = require('uuid')
import { Book } from '../../../../model/book'
import { TagDefine } from '../../../tagDefine.js'
import { ImageStyleDefine } from "../../../../define/iamgeStyleDefine"
import { cloneDeep } from 'lodash'
import { GeneralResponse } from '../../../../model/generalResponse'
let dbPath = path.resolve(define.db_path, 'book.realm')
export class BookTaskService extends BaseRealmService {
static instance: BookTaskService | null = null
realm: Realm
tagDefine: TagDefine
private constructor() {
super()
this.tagDefine = new TagDefine()
}
/**
@@ -38,7 +43,7 @@ export class BookTaskService extends BaseRealmService {
* 查询满足条件的小说子任务信息
* @param bookTaskCondition 查询条件 idbookIdnamenopage, pageSize
*/
GetBookTaskData(bookTaskCondition) {
GetBookTaskData(bookTaskCondition: Book.QueryBookTaskCondition): GeneralResponse.ErrorItem | GeneralResponse.SuccessItem {
try {
// 获取所有的小说数据,并进行时间降序排序
let bookTasks = this.realm.objects<BookTaskModel>('BookTask')
@@ -62,7 +67,7 @@ export class BookTaskService extends BaseRealmService {
}
let bookTask_length = bookTasks.length
bookTasks = bookTasks.sorted('updateTime', true)
// bookTasks = bookTasks.sorted('updateTime', true)
// 判断是不是有page和pageSize,有的话对查询返回的信息做分页
if (bookTaskCondition.page && bookTaskCondition.pageSize) {
bookTasks = bookTasks.slice(
@@ -73,22 +78,24 @@ export class BookTaskService extends BaseRealmService {
// 做一下数据转换
// 将realm对象数组转换为普通对象数组
// 将realm对象数组转换为普通对象数组,并处理异步操作
let res_bookTasks = Array.from(bookTasks).map((bookTask) => {
// 这里可以直接操作普通对象
let bookObj = {
// 直接操作普通对象
return {
...bookTask,
styleList: bookTask.styleList ? Array.from(bookTask.styleList) : [],
imageStyle: bookTask.imageStyle ? Array.from(bookTask.imageStyle) : [],
customizeImageStyle: bookTask.customizeImageStyle ? Array.from(bookTask.customizeImageStyle) : [],
generateVideoPath: JoinPath(define.project_path, bookTask.generateVideoPath),
srtPath: JoinPath(define.project_path, bookTask.srtPath),
audioPath: JoinPath(define.project_path, bookTask.audioPath),
imageFolder: JoinPath(define.project_path, bookTask.imageFolder)
}
return bookObj
imageFolder: JoinPath(define.project_path, bookTask.imageFolder),
imageCategory: bookTask.imageCategory ? bookTask.imageCategory : BookImageCategory.MJ, // 默认使用MJ出图
} as Book.SelectBookTask;
})
return successMessage(
{
bookTasks: res_bookTasks,
bookTasks: JSON.parse(JSON.stringify(res_bookTasks)),
total: bookTask_length
},
'查询小说任务成功',
@@ -103,7 +110,7 @@ export class BookTaskService extends BaseRealmService {
* 通过ID获取小说批次任务的数据
* @param bookTaskId
*/
GetBookTaskDataById(bookTaskId: string) {
GetBookTaskDataById(bookTaskId: string): Book.SelectBookTask {
try {
if (bookTaskId == null) {
throw new Error('小说任务ID不能为空')
@@ -111,13 +118,9 @@ export class BookTaskService extends BaseRealmService {
let bookTasks = this.GetBookTaskData({ id: bookTaskId })
if (bookTasks.data.bookTasks.length <= 0) {
return successMessage(null, '未找到对应的小说任务', 'BookTaskService_GetBookTaskDataById')
throw new Error('未找到对应的小说任务')
} else {
return successMessage(
bookTasks.data.bookTasks[0],
'查询小说任务成功',
'BookTaskService_GetBookTaskDataById'
)
return bookTasks.data.bookTasks[0]
}
} catch (error) {
throw error
@@ -183,6 +186,28 @@ export class BookTaskService extends BaseRealmService {
}
}
/**
* 修改小说批次任务数据
* @param bookTaskId 小说批次任务ID
* @param data 要修改的数据
*/
UpdetedBookTaskData(bookTaskId: string, data: Book.SelectBookTask): void {
try {
this.transaction(() => {
let updateData = this.realm.objectForPrimaryKey('BookTask', bookTaskId)
if (updateData == null) {
throw new Error('未找到对应的小说任务详细信息')
}
// 开始修改
for (let key in data) {
updateData[key] = data[key]
}
})
} catch (error) {
throw error
}
}
// 添加一条数据
AddOrModifyBookTask(bookTask) {
try {
@@ -220,4 +245,73 @@ export class BookTaskService extends BaseRealmService {
throw error
}
}
private resetBookTask(bookTaskId: string) {
let modifyBookTask = this.realm.objectForPrimaryKey('BookTask', bookTaskId)
modifyBookTask.status = BookTaskStatus.WAIT
modifyBookTask.errorMsg = "";
modifyBookTask.updateTime = new Date()
modifyBookTask.imageStyle = []
modifyBookTask.autoAnalyzeCharacter = undefined
modifyBookTask.customizeImageStyle = []
modifyBookTask.videoConfig = undefined
modifyBookTask.prefixPrompt = undefined
modifyBookTask.suffixPrompt = undefined
modifyBookTask.subImageFolder = []
let bookTaskDetails = this.realm.objects('BookTaskDetail').filtered('bookTaskId = $0', bookTaskId)
// 开始删除数据
bookTaskDetails.forEach(bookTaskDetail => {
// 删除MJMessage
if (bookTaskDetail.mjMessage) {
this.realm.delete(bookTaskDetail.mjMessage)
}
if (bookTaskDetail.reversePrompt) {
(bookTaskDetail.reversePrompt as any[]).forEach(item => {
this.realm.delete(item)
})
}
if (bookTaskDetail.sdConifg) {
this.realm.delete(bookTaskDetail.sdConifg)
}
this.realm.delete(bookTaskDetail)
})
}
/**
* 删除对应的小说批次数据
* @param bookTaskId 小说批次ID
*/
ResetBookTask(bookTaskId: string): void {
try {
// 开始重置数据,先重置小说批次数据,在重置其他
this.transaction(() => {
this.resetBookTask(bookTaskId)
})
} catch (error) {
throw error
}
}
/**
* 删除对应的小说批次数据
* @param bookTaskId 要删除的批次的ID
*/
DeleteBookTask(bookTaskId: string): void {
try {
this.transaction(() => {
// 先调用清除数据的方法
this.resetBookTask(bookTaskId)
// 删除批次数据
let bookTask = this.realm.objectForPrimaryKey('BookTask', bookTaskId)
if (bookTask == null) {
throw new Error('未找到对应的小说任务,无法执行删除操作')
}
this.realm.delete(bookTask)
})
} catch (error) {
throw error
}
}
}
@@ -2,9 +2,9 @@ import Realm, { UpdateMode } from 'realm'
import path from 'path'
import { BaseService } from '../baseService.js'
import { define } from '../../../define.js'
import { SoftwareModel } from '../../model/SoftWare/software.js'
import { SoftwareModel } from '../../model/SoftWare/software'
import { ComponentSize, SoftwareThemeType } from '../../../enum/softwareEnum.js'
import { errorMessage, successMessage } from '../../../../main/generalTools.js'
import { errorMessage, successMessage } from '../../../../main/Public/generalTools'
import { BaseSoftWareService } from './softwareBasic.js'
import { isEmpty } from 'lodash'
const { v4: uuidv4 } = require('uuid')
@@ -2,13 +2,14 @@ import Realm, { UpdateMode } from 'realm'
import path from 'path'
import { BaseService } from '../baseService'
import { define } from '../../../define.js'
import { SoftwareModel } from '../../model/SoftWare/software.js'
import { SoftwareModel } from '../../model/SoftWare/software'
import { ComponentSize, SoftwareThemeType } from '../../../enum/softwareEnum.js'
import { errorMessage, successMessage } from '../../../../main/generalTools.js'
import { errorMessage, successMessage } from '../../../../main/Public/generalTools'
import { BaseSoftWareService } from './softwareBasic.js'
import { isEmpty, isNumber } from 'lodash'
const { v4: uuidv4 } = require('uuid')
import { version } from '../../../../../package.json'
import { GeneralResponse } from '../../../../model/generalResponse'
export class MJSettingService extends BaseSoftWareService {
static instance: MJSettingService | null = null
@@ -561,7 +562,7 @@ export class MJSettingService extends BaseSoftWareService {
// 判断API设置的数据是不是存在
let apiSetting = mjSetting.apiSetting ? mjSetting.apiSetting : null
if (apiSetting != null) {
let apiSettingRes: { code: number; data: any; message: any }
let apiSettingRes: GeneralResponse.ErrorItem | GeneralResponse.SuccessItem
if (isEmpty(apiSetting.id)) {
// 新增
apiSettingRes = this.AddAPIMjSetting(apiSetting)
@@ -577,7 +578,7 @@ export class MJSettingService extends BaseSoftWareService {
// 判断浏览器模式的数据是不是存在
let browserSetting = mjSetting.browserSetting ? mjSetting.browserSetting : null
if (browserSetting != null) {
let browserSettingRes: { code: number; data: any; message: any }
let browserSettingRes: GeneralResponse.ErrorItem | GeneralResponse.SuccessItem
if (isEmpty(browserSetting.id)) {
// 新增
browserSettingRes = this.AddBrowserMJSetting(browserSetting)
@@ -591,7 +592,7 @@ export class MJSettingService extends BaseSoftWareService {
}
// 添加MJ的基础配置信息
let mjSettingRes: { code: number; data: any; message: any }
let mjSettingRes: GeneralResponse.ErrorItem | GeneralResponse.SuccessItem
if (isEmpty(mjSetting.id)) {
// 新增
mjSettingRes = this.AddMJSetting(mjSetting)
@@ -131,6 +131,22 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
}
})
}
if (oldRealm.schemaVersion < 18) {
newRealm.write(() => {
const newSoftwares = newRealm.objects('Software')
for (let software of newSoftwares) {
software.watermarkSetting = null // 水印的默认设置
}
})
}
if (oldRealm.schemaVersion < 19) {
newRealm.write(() => {
const newSoftwares = newRealm.objects('Software')
for (let software of newSoftwares) {
software.translationSetting = null // 翻译的默认设置
}
})
}
}
export class BaseSoftWareService extends BaseService {
@@ -169,7 +185,7 @@ export class BaseSoftWareService extends BaseService {
MjSettingModel
],
path: dbPath,
schemaVersion: 17, // 当前版本号
schemaVersion: 19, // 当前版本号
migration: migration
}
// 判断当前全局是不是又当前这个
@@ -1,10 +1,5 @@
import Realm, { UpdateMode } from 'realm'
import path from 'path'
import { BaseService } from '../baseService.js'
import { define } from '../../../define.js'
import { SoftwareModel } from '../../model/SoftWare/software.js'
import { ComponentSize, SoftwareThemeType } from '../../../enum/softwareEnum.js'
import { successMessage } from '../../../../main/generalTools.js'
import { successMessage } from '../../../../main/Public/generalTools'
import { BaseSoftWareService } from './softwareBasic.js'
const { v4: uuidv4 } = require('uuid')
@@ -63,12 +58,26 @@ export class SoftwareService extends BaseSoftWareService {
*/
GetSoftwareData() {
try {
let software = this.realm.objects('Software')
let softwares = this.realm.objects('Software')
let res = Array.from(softwares).map((software) => {
// 这里可以直接操作普通对象
let bookObj = {
id: software.id,
theme: software.theme,
reverse_show_book_striped: software.reverse_show_book_striped,
reverse_data_table_size: software.reverse_data_table_size,
reverse_display_show: software.reverse_display_show,
}
return bookObj
})
return successMessage(
software.toJSON(),
res,
'获取软件配置信息成功',
'SoftwareService_GetSoftwareData'
)
} catch (error) {
global.logger.error(
'SoftwareService_GetSoftwareData',
@@ -82,17 +91,15 @@ export class SoftwareService extends BaseSoftWareService {
* 获取当前软件指定属性的数据
* @param property 属性名称
*/
GetSoftWarePropertyData(property: string) {
GetSoftWarePropertyData(property: string): string {
try {
let software = this.realm.objects('Software')
if (software.length <= 0) {
throw new Error('数据库中没有软件配置信息')
}
let softwareData = software.toJSON()[0]
let res = softwareData[property]
return successMessage(res, '获取软件配置信息成功', 'SoftwareService_GetSoftWarePropertyData')
let res = softwareData[property] as string
return res
} catch (error) {
global.logger.error(
'SoftwareService_GetSoftWarePropertyData',