LaiTool V3.0.1-preview.7
This commit is contained in:
@@ -236,3 +236,20 @@ export async function GetFileSize(filePath: string): Promise<number> {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹下的所有子文件夹的完整路径
|
||||
* @param folderPath 文件夹的路径
|
||||
* @returns 返回子文件夹的完整路径数组
|
||||
*/
|
||||
export async function GetSubdirectories(folderPath: string): Promise<string[]> {
|
||||
try {
|
||||
const files = await fs.promises.readdir(folderPath, { withFileTypes: true });
|
||||
const directories = files
|
||||
.filter((fileStat) => fileStat.isDirectory())
|
||||
.map((fileStat) => path.join(folderPath, fileStat.name));
|
||||
return directories;
|
||||
} catch (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export class SoftwareModel extends Realm.Object<SoftwareModel> {
|
||||
aiSetting: string | null // AI相关的配置的json字符串
|
||||
watermarkSetting: string | null // 水印相关的配置的json字符串
|
||||
translationSetting: string | null // 翻译相关的配置的json字符串
|
||||
subtitleSetting: string | null // 字幕相关的配置的json字符串
|
||||
|
||||
static schema: ObjectSchema = {
|
||||
name: 'Software',
|
||||
@@ -27,7 +28,8 @@ export class SoftwareModel extends Realm.Object<SoftwareModel> {
|
||||
writeSetting: 'string?',
|
||||
aiSetting: 'string?',
|
||||
watermarkSetting: 'string?',
|
||||
translationSetting: 'string?'
|
||||
translationSetting: 'string?',
|
||||
subtitleSetting: "string?"
|
||||
},
|
||||
// 主键为_id
|
||||
primaryKey: 'id'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(() => {
|
||||
// 修改对应小说批次任务的状态
|
||||
|
||||
@@ -147,6 +147,14 @@ const migration = (oldRealm: Realm, newRealm: Realm) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
if (oldRealm.schemaVersion < 20) {
|
||||
newRealm.write(() => {
|
||||
const newSoftwares = newRealm.objects('Software')
|
||||
for (let software of newSoftwares) {
|
||||
software.subtitleSetting = null // 字幕的默认设置
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export class BaseSoftWareService extends BaseService {
|
||||
@@ -185,7 +193,7 @@ export class BaseSoftWareService extends BaseService {
|
||||
MjSettingModel
|
||||
],
|
||||
path: dbPath,
|
||||
schemaVersion: 19, // 当前版本号
|
||||
schemaVersion: 21, // 当前版本号
|
||||
migration: migration
|
||||
}
|
||||
// 判断当前全局是不是又当前这个
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Realm, { UpdateMode } from 'realm'
|
||||
import { successMessage } from '../../../../main/Public/generalTools'
|
||||
import { BaseSoftWareService } from './softwareBasic.js'
|
||||
import { GeneralResponse } from '../../../../model/generalResponse'
|
||||
const { v4: uuidv4 } = require('uuid')
|
||||
|
||||
export class SoftwareService extends BaseSoftWareService {
|
||||
@@ -24,7 +25,7 @@ export class SoftwareService extends BaseSoftWareService {
|
||||
}
|
||||
|
||||
// 修改数据库中行中的某个属性数据
|
||||
UpdateSoftware(software) {
|
||||
UpdateSoftware(software: SoftwareSettingModel.SoftwareSetting): GeneralResponse.SuccessItem {
|
||||
try {
|
||||
this.realm.write(() => {
|
||||
this.realm.create('Software', software, UpdateMode.Modified)
|
||||
@@ -41,7 +42,7 @@ export class SoftwareService extends BaseSoftWareService {
|
||||
* @param software 软件配置信息
|
||||
* @returns
|
||||
*/
|
||||
AddSfotware(software) {
|
||||
AddSfotware(software: SoftwareSettingModel.SoftwareSetting): GeneralResponse.SuccessItem {
|
||||
try {
|
||||
software.id = uuidv4()
|
||||
this.realm.write(() => {
|
||||
@@ -56,7 +57,7 @@ export class SoftwareService extends BaseSoftWareService {
|
||||
/**
|
||||
* 或软件基础配置信息
|
||||
*/
|
||||
GetSoftwareData() {
|
||||
GetSoftwareData(): GeneralResponse.SuccessItem {
|
||||
try {
|
||||
let softwares = this.realm.objects('Software')
|
||||
|
||||
|
||||
@@ -123,7 +123,8 @@ export const DEFINE_STRING = {
|
||||
GPT: {
|
||||
INIT_SERVER_GPT_OPTIONS: 'INIT_SERVER_GPT_OPTIONS',
|
||||
GET_AI_SETTING: 'GET_AI_SETTING',
|
||||
SAVE_AI_SETTING: 'SAVE_AI_SETTING'
|
||||
SAVE_AI_SETTING: 'SAVE_AI_SETTING',
|
||||
SYNC_GPT_KEY: "SYNC_GPT_KEY"
|
||||
},
|
||||
|
||||
QUEUE_BATCH: {
|
||||
@@ -153,7 +154,6 @@ export const DEFINE_STRING = {
|
||||
SD: {
|
||||
LOAD_SD_SERVICE_DATA: 'LOAD_SD_SERVICE_DATA',
|
||||
TXT2IMG: 'TXT2IMG',
|
||||
SD_MERGE_PROMPT: "SD_MERGE_PROMPT"
|
||||
},
|
||||
MJ: {
|
||||
SAVE_WORD_SRT: 'SAVE_WORD_SRT',
|
||||
@@ -175,7 +175,6 @@ export const DEFINE_STRING = {
|
||||
GET_MJ_IMAGE_ROBOT_MODEL: 'GET_MJ_IMAGE_ROBOT_MODEL',
|
||||
MACTH_USER_RETURN: 'MACTH_USER_RETURN',
|
||||
AUTO_MATCH_USER: 'AUTO_MATCH_USER',
|
||||
MJ_MERGE_PROMPT: "MJ_MERGE_PROMPT",
|
||||
ADD_MJ_GENADD_MJ_GENERATE_IMAGE_TASK: "ADD_MJ_GENADD_MJ_GENERATE_IMAGE_TASK",
|
||||
MJ_IMAGE: "MJ_IMAGE"
|
||||
},
|
||||
@@ -208,6 +207,7 @@ export const DEFINE_STRING = {
|
||||
BOOK: {
|
||||
MAIN_DATA_RETURN: 'MAIN_DATA_RETURN', // 监听任务返回
|
||||
|
||||
REPLACE_VIDEO_CURRENT_FRAME: 'REPLACE_VIDEO_CURRENT_FRAME',
|
||||
GET_BOOK_TYPE: 'GET_BOOK_TYPE',
|
||||
ADD_OR_MODIFY_BOOK: 'ADD_OR_MODIFY_BOOK',
|
||||
GET_BOOK_DATA: 'GET_BOOK_DATA',
|
||||
@@ -232,6 +232,10 @@ export const DEFINE_STRING = {
|
||||
HD_IMAGE: "HD_IMAGE",
|
||||
USE_BOOK_VIDEO_DATA_TO_BOOK_TASK: "USE_BOOK_VIDEO_DATA_TO_BOOK_TASK",
|
||||
ADD_JIANYING_DRAFT: "ADD_JIANYING_DRAFT",
|
||||
EXPORT_COPYWRITING: "EXPORT_COPYWRITING",
|
||||
MERGE_PROMPT: "MERGE_PROMPT",
|
||||
RESET_BOOK_DATA: "RESET_BOOK_DATA",
|
||||
DELETE_BOOK_DATA: "DELETE_BOOK_DATA",
|
||||
|
||||
COMPUTE_STORYBOARD: 'COMPUTE_STORYBOARD',
|
||||
|
||||
@@ -291,7 +295,10 @@ export const DEFINE_STRING = {
|
||||
WRITE: {
|
||||
GET_WRITE_CONFIG: 'GET_WRITE_CONFIG',
|
||||
SAVE_WRITE_CONFIG: 'SAVE_WRITE_CONFIG',
|
||||
ACTION_START: 'ACTION_START'
|
||||
ACTION_START: 'ACTION_START',
|
||||
GET_SUBTITLE_SETTING: "GET_SUBTITLE_SETTING",
|
||||
RESET_SUBTITLE_SETTING: "RESET_SUBTITLE_SETTING",
|
||||
SAVE_SUBTITLE_SETTING: "SAVE_SUBTITLE_SETTING",
|
||||
},
|
||||
DB: {
|
||||
UPDATE_BOOK_TASK_DATA: "UPDATE_BOOK_TASK_DATA",
|
||||
|
||||
@@ -207,10 +207,6 @@ export enum TagDefineType {
|
||||
SCENE_MAIN = "scene_main",
|
||||
}
|
||||
|
||||
export enum MergeType {
|
||||
BOOKTASK = 'bookTask', // 整个小说批次分镜合并
|
||||
BOOKTASKDETAIL = 'bookTaskDetail' // 单个分镜合并
|
||||
}
|
||||
|
||||
export enum OperateBookType {
|
||||
BOOK = 'book', // 这个小说的所有批次
|
||||
@@ -227,3 +223,14 @@ export enum CopyImageType {
|
||||
// 不包含图
|
||||
NONE = 'none'
|
||||
}
|
||||
|
||||
export enum PromptMergeType {
|
||||
// mj 合并
|
||||
MJ_MERGE = 'mj_merge',
|
||||
|
||||
// SD 合并
|
||||
SD_MERGE = 'sd_merge',
|
||||
|
||||
// D3 合并
|
||||
D3_MERGE = 'd3_merge'
|
||||
}
|
||||
|
||||
@@ -60,7 +60,8 @@ export enum ResponseMessageType {
|
||||
GET_TEXT = 'getText', // 获取文案
|
||||
REMOVE_WATERMARK = "REMOVE_WATERMARK",// 删除水印
|
||||
MJ_REVERSE = 'MJ_REVERSE',// MJ反推,返回反推结果
|
||||
PROMPT_TRANSLATE = 'PROMPT_TRANSLATE',// 提示词翻译
|
||||
REVERSE_PROMPT_TRANSLATE = 'REVERSE_PROMPT_TRANSLATE',// 反推提示词翻译
|
||||
GPT_PROMPT_TRANSLATE = 'GPT_PROMPT_TRANSLATE', // GPT提示词翻译
|
||||
MJ_IMAGE = 'MJ_IMAGE',// MJ 生成图片
|
||||
HD_IMAGE = 'HD_IMAGE',// HD 生成图片
|
||||
}
|
||||
@@ -72,4 +73,11 @@ export enum LaiAPIType {
|
||||
HK_PROXY = "hk-proxy",
|
||||
// 备用站点
|
||||
BAK_MAIN = 'bak-main'
|
||||
}
|
||||
|
||||
// 同步GPTkey的分类
|
||||
export enum SyncGptKeyType {
|
||||
// 字幕设置
|
||||
SUBTITLE_SETTING = 'subtitle_setting',
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
export enum TranslateType {
|
||||
// 反推提示词翻译
|
||||
REVERSE_PROMPT_TRANSLATE = 'reverse_prompt_translate',
|
||||
|
||||
// GPT提示词翻译
|
||||
GPT_PROMPT_TRANSLATE = 'gpt_prompt_translate',
|
||||
}
|
||||
|
||||
@@ -27,4 +27,14 @@ export enum WaterMarkResponseDateType {
|
||||
export enum RemoveWatermarkType {
|
||||
LOCAL_LAMA = 'local_lama',
|
||||
IOPAINT = 'iopaint'
|
||||
}
|
||||
|
||||
// 获取字幕的方法类型
|
||||
export enum GetSubtitleType {
|
||||
// 本地OCR
|
||||
LOCAL_OCR = 'local_ocr',
|
||||
// 本地Whisper
|
||||
LOCAL_WHISPER = 'local_whisper',
|
||||
// LAI WHISPER
|
||||
LAI_WHISPER = 'lai_whisper',
|
||||
}
|
||||
Reference in New Issue
Block a user