LaiTool V3.0.1-preview.5
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import Realm, { UpdateMode } from 'realm'
|
||||
import { BookModel } from '../../model/Book/book.js'
|
||||
import path from 'path'
|
||||
import { BaseService } from '../baseService.js'
|
||||
import { define } from '../../../define.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'
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
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 { BookTaskStatus } from '../../../enum/bookEnum.js'
|
||||
import { successMessage } from '../../../../main/Public/generalTools'
|
||||
import { BaseRealmService } from './bookBasic'
|
||||
import { cloneDeep, endsWith, isEmpty } from 'lodash'
|
||||
import { book } from '../../../../preload/book.js'
|
||||
import { DefaultObject } from 'realm/dist/public-types/schema.js'
|
||||
import { cloneDeep, isEmpty } from 'lodash'
|
||||
import { JoinPath } from '../../../Tools/file'
|
||||
import { BookTaskDetailModel, ReversePrompt } from '../../model/Book/bookTaskDetail.js'
|
||||
const { v4: uuidv4 } = require('uuid')
|
||||
|
||||
@@ -1,9 +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'
|
||||
import { ComponentSize, SoftwareThemeType } from '../../../enum/softwareEnum.js'
|
||||
import { errorMessage, successMessage } from '../../../../main/Public/generalTools'
|
||||
import { BaseSoftWareService } from './softwareBasic.js'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
@@ -1,13 +1,36 @@
|
||||
import SoftwareService from './SoftWare/softwareService'
|
||||
import { BookService } from './Book/bookService'
|
||||
import { BookTaskService } from './Book/bookTaskService'
|
||||
import { BookTaskDetailService } from './Book/bookTaskDetailService'
|
||||
import { BookBackTaskListService } from './Book/bookBackTaskListService'
|
||||
import { MJSettingService } from './SoftWare/mjSettingService'
|
||||
|
||||
export class ServiceBase {
|
||||
softService: SoftwareService
|
||||
softService: SoftwareService | undefined
|
||||
bookService: BookService | undefined
|
||||
bookTaskService: BookTaskService | undefined
|
||||
bookTaskDetailService: BookTaskDetailService | undefined
|
||||
bookBackTaskListService: BookBackTaskListService | undefined
|
||||
mjSettingService: MJSettingService | undefined
|
||||
|
||||
constructor() {}
|
||||
|
||||
constructor() { }
|
||||
|
||||
async InitService() {
|
||||
if (!this.softService) {
|
||||
this.softService = await SoftwareService.getInstance()
|
||||
}
|
||||
if (!this.bookService) {
|
||||
this.bookService = await BookService.getInstance()
|
||||
}
|
||||
if (!this.bookTaskDetailService) {
|
||||
this.bookTaskDetailService = await BookTaskDetailService.getInstance()
|
||||
}
|
||||
if (!this.bookBackTaskListService) {
|
||||
this.bookBackTaskListService = await BookBackTaskListService.getInstance()
|
||||
}
|
||||
if (this.mjSettingService) {
|
||||
this.mjSettingService = await MJSettingService.getInstance()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// @ts-ignore
|
||||
import Realm from 'realm'
|
||||
import { TTSSelectModel } from '../../enum/tts'
|
||||
|
||||
export class TTSModel extends Realm.Object<TTSModel> {
|
||||
id: string
|
||||
no: number
|
||||
name: string // 一把就是配音的前几个字
|
||||
textPath: string // 保存生成文本的地址
|
||||
ttsPath: string // 生成的配置文件地址
|
||||
srtPath: string | null // 生成的SRT地址
|
||||
selectModel: TTSSelectModel // 选择模式
|
||||
hasSrt: boolean
|
||||
srtJsonPath: string | null
|
||||
createTime: Date
|
||||
updateTime: Date
|
||||
|
||||
static schema: Realm.ObjectSchema = {
|
||||
name: 'TTSModel',
|
||||
properties: {
|
||||
id: 'string',
|
||||
no: 'int',
|
||||
name: 'string',
|
||||
textPath: 'string',
|
||||
ttsPath: 'string',
|
||||
srtPath: 'string?',
|
||||
selectModel: 'string',
|
||||
hasSrt: 'bool',
|
||||
srtJsonPath: 'string?',
|
||||
createTime: 'date',
|
||||
updateTime: 'date'
|
||||
},
|
||||
// 主键为_id
|
||||
primaryKey: 'id'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import Realm from 'realm'
|
||||
import { BaseService } from '../service/baseService'
|
||||
import { define } from '../../define'
|
||||
import path from 'path'
|
||||
import { TTSModel } from './tts'
|
||||
|
||||
|
||||
let dbPath = path.resolve(define.db_path, 'tts.realm')
|
||||
|
||||
// 版本迁移
|
||||
const migration = (oldRealm: Realm, newRealm: Realm) => {
|
||||
if (oldRealm.schemaVersion < 2) {
|
||||
const oldObjects = oldRealm.objects<TTSModel>('TTSModel')
|
||||
const newObjects = newRealm.objects<TTSModel>('TTSModel')
|
||||
for (let i = 0; i < oldObjects.length; i++) {
|
||||
newObjects[i].textPath = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class BaseTTSService extends BaseService {
|
||||
static instance: BaseTTSService | null = null
|
||||
protected realm: Realm | null = null
|
||||
dbpath: string
|
||||
|
||||
protected constructor() {
|
||||
super()
|
||||
this.dbpath = dbPath
|
||||
}
|
||||
|
||||
public static async getInstance() {
|
||||
if (BaseTTSService.instance === null) {
|
||||
BaseTTSService.instance = new BaseTTSService()
|
||||
await BaseTTSService.instance.open()
|
||||
}
|
||||
return BaseTTSService.instance
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据库连接,如果已经存在则直接返回
|
||||
* @returns
|
||||
*/
|
||||
async open() {
|
||||
try {
|
||||
if (this.realm != null) return
|
||||
// 判断当前全局是不是又当前这个
|
||||
const config = {
|
||||
schema: [
|
||||
TTSModel
|
||||
],
|
||||
path: this.dbpath,
|
||||
schemaVersion: 2,
|
||||
migration: migration
|
||||
}
|
||||
this.realm = await Realm.open(config)
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import Realm from 'realm'
|
||||
import path from 'path'
|
||||
import { BaseTTSService } from './ttsBase'
|
||||
import { define } from '../../define'
|
||||
import { TTSModel } from './tts'
|
||||
import { tts } from '../../../model/tts'
|
||||
import { isEmpty } from 'lodash'
|
||||
const { v4: uuidv4 } = require('uuid')
|
||||
|
||||
export class TTSService extends BaseTTSService {
|
||||
static instance: TTSService | null = null
|
||||
realm: Realm
|
||||
private constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前实例对象,为空则创建一个新的
|
||||
* @returns
|
||||
*/
|
||||
public static async getInstance() {
|
||||
if (TTSService.instance === null) {
|
||||
TTSService.instance = new TTSService()
|
||||
await super.getInstance()
|
||||
}
|
||||
await TTSService.instance.open()
|
||||
return TTSService.instance
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取配音历史信息,可以分页和筛选
|
||||
* @param condition 查询的条件参数
|
||||
* @returns 返回当前的查到的所有数据和没有被分割过的数据的数量
|
||||
*/
|
||||
GetTTSHistory(condition: tts.TTSHistoryQueryParams): tts.TTSModelRes {
|
||||
try {
|
||||
let TTSHistory = this.realm.objects<TTSModel>('TTSModel')
|
||||
|
||||
if (condition.name) {
|
||||
TTSHistory = TTSHistory.filtered('name CONTAINS $0', condition.name)
|
||||
}
|
||||
if (condition.id) {
|
||||
TTSHistory = TTSHistory.filtered('id == $0', condition.id)
|
||||
}
|
||||
TTSHistory = TTSHistory.sorted('updateTime', true)
|
||||
|
||||
let TTSCount = TTSHistory.length
|
||||
|
||||
if (condition.page && condition.pageSize) {
|
||||
TTSHistory = TTSHistory.slice(
|
||||
(condition.page - 1) * condition.pageSize,
|
||||
condition.page * condition.pageSize
|
||||
) as unknown as Realm.Results<TTSModel>
|
||||
}
|
||||
|
||||
// 将数据进行处理
|
||||
// 将realm对象数组转换为普通对象数组
|
||||
let TTSHistoryRes = Array.from(TTSHistory).map((item) => {
|
||||
// 这里可以直接操作普通对象
|
||||
let bookObj = {
|
||||
...item,
|
||||
ttsPath: item.ttsPath ? path.resolve(define.tts_path, item.ttsPath.replace(/\\/g, '/')) : '',
|
||||
srtPath: item.srtPath ? path.resolve(define.tts_path, item.srtPath.replace(/\\/g, '/')) : '',
|
||||
srtJsonPath: item.srtJsonPath ? path.resolve(define.tts_path, item.srtJsonPath.replace(/\\/g, '/')) : '',
|
||||
textPath: item.textPath ? path.resolve(define.tts_path, item.textPath.replace(/\\/g, '/')) : ''
|
||||
} as tts.TTSModel
|
||||
return bookObj
|
||||
}) as tts.TTSModel[]
|
||||
return {
|
||||
ttsList: TTSHistoryRes,
|
||||
ttsCount: TTSCount // 返回筛选的总数
|
||||
}
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过指定ID获取对应的配音历史信息
|
||||
* @param id 配音历史ID
|
||||
*/
|
||||
GetTTSHistoryById(id: string): tts.TTSModel {
|
||||
try {
|
||||
let res = this.GetTTSHistory({ id: id });
|
||||
if (res.ttsList.length < 0) {
|
||||
throw new Error("没有找到指定ID的配音历史数据,请检查");
|
||||
}
|
||||
// 返回第一个数据
|
||||
return res.ttsList[0];
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增一条TTS生成历史记录
|
||||
* @param data 要新增的数据
|
||||
*/
|
||||
AddTTSHistory(data: tts.TTSModel): tts.TTSModel {
|
||||
try {
|
||||
if (isEmpty(data.id)) {
|
||||
throw new Error('新增TTS历史记录失败,缺少ID')
|
||||
}
|
||||
// 获取最大的no
|
||||
let maxNo = this.realm.objects<TTSModel>('TTSModel').max('no')
|
||||
|
||||
data.no = maxNo == undefined ? 1 : Number(maxNo) + 1
|
||||
data.createTime = new Date()
|
||||
data.updateTime = new Date()
|
||||
|
||||
this.transaction(() => {
|
||||
this.realm.create('TTSModel', data)
|
||||
})
|
||||
return data
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新TTS历史记录数据,修改之后,返回修改后的数据
|
||||
* @param ttsId 要更新的TTS历史记录ID
|
||||
* @param data 要更新的数据
|
||||
*/
|
||||
UpdetateTTSHistory(ttsId: string, data: tts.TTSModel): tts.TTSModel {
|
||||
try {
|
||||
this.transaction(() => {
|
||||
let tts = this.realm.objectForPrimaryKey<TTSModel>('TTSModel', ttsId)
|
||||
if (tts == null) {
|
||||
throw new Error('没有找到指定ID的TTS历史记录,请检查')
|
||||
}
|
||||
for (let key in data) {
|
||||
tts[key] = data[key]
|
||||
}
|
||||
tts.updateTime = new Date()
|
||||
})
|
||||
|
||||
// 获取修改后的数据返回
|
||||
let res = this.GetTTSHistoryById(ttsId)
|
||||
return res
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除TTS历史记录
|
||||
* @param ttsId tts历史记录ID
|
||||
*/
|
||||
DeleteTTSHistory(ttsId: string): void {
|
||||
try {
|
||||
this.transaction(() => {
|
||||
let tts = this.realm.objectForPrimaryKey<TTSModel>('TTSModel', ttsId)
|
||||
if (tts == null) {
|
||||
throw new Error('没有找到指定ID的TTS历史记录,请检查')
|
||||
}
|
||||
this.realm.delete(tts)
|
||||
})
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ if (!app.isPackaged) {
|
||||
|
||||
define['remotemj_api'] = 'https://api.laitool.net/'
|
||||
define['serverUrl'] = 'http://lapi.laitool.cn'
|
||||
define['hkServerUrl'] = 'https://api.laitool.cc/'
|
||||
define['bakServerUrl'] = 'https://bakapi.laitool.cc/'
|
||||
define['hkServerUrl'] = 'https://laitool.net/'
|
||||
define['bakServerUrl'] = 'https://laitool.net/'
|
||||
define['API'] = 'f85d39ed5a40fd09966f13f12b6cf0f0'
|
||||
export { define }
|
||||
|
||||
@@ -283,7 +283,10 @@ export const DEFINE_STRING = {
|
||||
TTS: {
|
||||
GET_TTS_CONFIG: 'GET_TTS_CONFIG',
|
||||
GENERATE_AUDIO: 'GENERATE_AUDIO',
|
||||
SAVE_TTS_CONFIG: 'SAVE_TTS_CONFIG'
|
||||
SAVE_TTS_CONFIG: 'SAVE_TTS_CONFIG',
|
||||
GENERATE_SRT: "GENERATE_SRT",
|
||||
GET_TTS_HISTORY_DATA: 'GET_TTS_HISTORY_DATA',
|
||||
DELETE_TTS_HISTORY: 'DELETE_TTS_HISTORY',
|
||||
},
|
||||
WRITE: {
|
||||
GET_WRITE_CONFIG: 'GET_WRITE_CONFIG',
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
export enum TTSSelectModel {
|
||||
// edge-tts
|
||||
edgeTTS = 'edge-tts',
|
||||
}
|
||||
@@ -275,6 +275,14 @@ export const gptDefine = {
|
||||
{
|
||||
label: 'gpt-4',
|
||||
value: 'gpt-4'
|
||||
},
|
||||
{
|
||||
label: 'deepseek-chat',
|
||||
value: 'deepseek-chat'
|
||||
},
|
||||
{
|
||||
label: 'deepseek-coder',
|
||||
value: 'deepseek-coder'
|
||||
}
|
||||
],
|
||||
|
||||
|
||||
@@ -115,10 +115,9 @@ export class TagDefine {
|
||||
let property = value[1]
|
||||
value = JSON.parse(value[0])
|
||||
let tmp_key = uuidv4()
|
||||
|
||||
// 特殊操作。为角色和场景的时候,需要copy图片
|
||||
if (property == 'character_tags' || property == 'scene_tags' || property == 'style_tags') {
|
||||
let show_image = value.show_image
|
||||
let show_image = value.show_image ? value.show_image.split('?t')[0] : null
|
||||
if (show_image && show_image != '') {
|
||||
let file_name = `c_s/${value.key ? value.key : tmp_key}.png`
|
||||
let new_image_path = path.join(define.image_path, file_name)
|
||||
@@ -129,7 +128,6 @@ export class TagDefine {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 获取自定义的GPT数据
|
||||
let tag_setting = JSON.parse(await fspromises.readFile(define.tag_setting, 'utf-8'))
|
||||
let tag = get(tag_setting, property, [])
|
||||
|
||||
Reference in New Issue
Block a user