LaiTool V3.0.1-preview.7

This commit is contained in:
2024-08-18 16:22:19 +08:00
parent 07f99708da
commit 223678f761
78 changed files with 2827 additions and 917 deletions
@@ -135,13 +135,13 @@ export class BookBackTaskListService extends BaseRealmService {
* 新增一个小说相关的后台任务队列
* @param bookBackTask 要添加的小说数据
*/
async AddBookBackTask(
AddBookBackTask(
bookId: string,
taskType: BookBackTaskType,
executeType = TaskExecuteType.AUTO,
bookTaskId = null,
bookTaskDetailId = null
) {
): GeneralResponse.SuccessItem | GeneralResponse.ErrorItem {
try {
// 通过bookid获取book信息
let book = this.realm.objectForPrimaryKey('Book', bookId)
+23 -3
View File
@@ -11,6 +11,7 @@ import { isEmpty } from 'lodash'
import { FfmpegOptions } from '../../../../main/Service/ffmpegOptions.js'
import { version } from '../../../../../package.json'
import { Book } from '../../../../model/book.js'
import { GeneralResponse } from '../../../../model/generalResponse.js'
export class BookService extends BaseRealmService {
static instance: BookService | null = null
@@ -37,7 +38,7 @@ export class BookService extends BaseRealmService {
* 获取小说信息,没有找到返回null
* @param bookId
*/
GetBookDataById(bookId): Book.SelectBook | null {
GetBookDataById(bookId: string): Book.SelectBook | null {
try {
if (isEmpty(bookId)) {
throw new Error('获取小说信息失败,缺少小说ID')
@@ -275,7 +276,7 @@ export class BookService extends BaseRealmService {
* @param bookId 小说的ID
* @param bookData 要修改的小说数据
*/
async UpdateBookData(bookId: string, bookData: Book.SelectBook) {
UpdateBookData(bookId: string, bookData: Book.SelectBook): Book.SelectBook {
try {
if (bookId == null) {
throw new Error('修改小说数据失败,缺少小说ID')
@@ -303,8 +304,27 @@ export class BookService extends BaseRealmService {
if (bookRes == null) {
throw new Error('获取修改后的小说数据失败,小说ID对应的数据不存在')
}
// return successMessage(bookRes, '修改小说数据成功', 'ReverseBook_UpdateBookData')
return bookRes;
} catch (error) {
throw error
}
}
return successMessage(bookRes, '修改小说数据成功', 'ReverseBook_UpdateBookData')
/**
* 删除指定的小说任务
* @param bookId 需要删除的小说的ID
*/
DeleteBookData(bookId: string): void {
try {
this.transaction(() => {
let book = this.realm.objectForPrimaryKey('Book', bookId);
if (book == null) {
throw new Error('未找到对应的小说')
}
// 删除对应的小说
this.realm.delete(book)
})
} catch (error) {
throw error
}
@@ -72,7 +72,7 @@ export class BookTaskDetailService extends BaseRealmService {
return JoinPath(define.project_path, subImage)
}),
characterTags: item.characterTags ? item.characterTags.map((tag) => tag) : null,
subValue: item.subValue,
subValue: isEmpty(item.subValue) ? null : JSON.parse(item.subValue),
reversePrompt: item.reversePrompt.map((reversePrompt) => {
return {
...reversePrompt
@@ -101,7 +101,6 @@ export class BookTaskDetailService extends BaseRealmService {
if (bookTaskDetailId == null) {
throw new Error('获取小说任务详细信息失败,缺少ID')
}
let bookTaskDetails = this.GetBookTaskData({ id: bookTaskDetailId })
if (bookTaskDetails.data.length <= 0) {
return null;
@@ -165,7 +164,7 @@ export class BookTaskDetailService extends BaseRealmService {
* @param bookTaskDetailId
* @param updateData
*/
UpdateBookTaskDetail(bookTaskDetailId: string, updateData: Book.SelectBookTaskDetail) {
UpdateBookTaskDetail(bookTaskDetailId: string, updateData: Book.SelectBookTaskDetail): Book.SelectBookTaskDetail {
try {
this.transaction(() => {
let bookTaskDetail = this.realm.objectForPrimaryKey('BookTaskDetail', bookTaskDetailId)
@@ -178,18 +177,21 @@ export class BookTaskDetailService extends BaseRealmService {
}
bookTaskDetail.updateTime = new Date()
})
return successMessage(
null,
'修改小说任务详细信息成功',
'BookTaskDetailService_UpdateBookTaskDetail'
)
let res = this.GetBookTaskDetailDataById(bookTaskDetailId)
return res;
} catch (error) {
throw error
}
}
/**
* 更新指定ID的反推提示词数据
* @param bookTaskDetailId
* @param mjMessage
*/
UpdateBookTaskDetailMjMessage(bookTaskDetailId: string, mjMessage: Book.MJMessage): void {
try {
console.log('UpdateBookTaskDetailMjMessage', bookTaskDetailId, mjMessage)
this.transaction(() => {
let mjMessageRes = this.realm.objectForPrimaryKey('MJMessage', bookTaskDetailId)
let bookTaskDetail = this.realm.objectForPrimaryKey('BookTaskDetail', bookTaskDetailId)
@@ -276,12 +278,20 @@ export class BookTaskDetailService extends BaseRealmService {
* @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)
let bookTaskDetails = this.realm.objects<BookTaskDetailModel>('BookTaskDetail').filtered('id = $0', bookTaskDetailId);
if (bookTaskDetails.length <= 0) {
throw new Error('删除小说任务详细信息的反推提示词失败,未找到对应的分镜信息')
}
let bookTaskDetail = bookTaskDetails[0];
bookTaskDetail.gptPrompt = undefined;
// 删除所有的反推提示词
if (bookTaskDetail.reversePrompt) {
bookTaskDetail.reversePrompt.forEach(item => {
this.realm.delete(item)
})
}
})
}
}
@@ -132,7 +132,7 @@ export class BookTaskService extends BaseRealmService {
* @param bookTaskId 小说批次任务Id
* @param status 目标状态
*/
UpdateBookTaskStatus(bookTaskId: string, status: BookTaskStatus, errorMsg: string | null = null) {
UpdateBookTaskStatus(bookTaskId: string, status: BookTaskStatus, errorMsg: string | null = null): GeneralResponse.SuccessItem {
try {
this.transaction(() => {
// 修改对应小说批次任务的状态