Laitool v3.0.1-preview.1
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user