同步
This commit is contained in:
parent
d595e932e3
commit
1ce665a3e5
Binary file not shown.
@ -1,172 +0,0 @@
|
|||||||
export const DEFINE_STRING = {
|
|
||||||
SAVE_DEFINE_CONFIG_JSON_BY_PROPERTY: "SAVE_DEFINE_CONFIG_JSON_BY_PROPERTY",
|
|
||||||
GET_DEFINE_CONFIG_JSON_BY_PROPERTY: "GET_DEFINE_CONFIG_JSON_BY_PROPERTY",
|
|
||||||
GET_IMAGE_GENERATE_CATEGORY: "GET_IMAGE_GENERATE_CATEGORY",
|
|
||||||
SHOW_MAIN_NOTIFICATION: "SHOW_MAIN_NOTIFICATION",
|
|
||||||
CHECK_MACHINE_ID: "CHECK_MACHINE_ID",
|
|
||||||
GET_CUSTOMIZE_GPT_PROMPT: "GET_CUSTOMIZE_GPT_PROMPT",
|
|
||||||
GENERATE_GPT_EXAMPLE_OUT: "GENERATE_GPT_EXAMPLE_OUT",
|
|
||||||
GET_PERMISSION: "GET_PERMISSION",
|
|
||||||
SAVE_IMAGE_TO_OTHER_FOLDER: "SAVE_IMAGE_TO_OTHER_FOLDER",
|
|
||||||
GET_IMAGE_AUTO_SAVE_SETTING: "GET_IMAGE_AUTO_SAVE_SETTING",
|
|
||||||
SAVE_IMAGE_AUTO_SAVE_SETTING: "SAVE_IMAGE_AUTO_SAVE_SETTING",
|
|
||||||
GET_AUTO_SAVE_IMAGE_CLASSIFY_OPTIONS: "GET_AUTO_SAVE_IMAGE_CLASSIFY_OPTIONS",
|
|
||||||
MODIFY_GENERATE_TASK_STATUS: "MODIFY_GENERATE_TASK_STATUS",
|
|
||||||
DELETE_BACK_TASK: "DELETE_BACK_TASK",
|
|
||||||
SAVE_VIDEO_SRT_AND_AUDIO_MESSAGE: "SAVE_VIDEO_SRT_AND_AUDIO_MESSAGE",
|
|
||||||
SAVE_KEY_FRAME_SETTING: "SAVE_KEY_FRAME_SETTING",
|
|
||||||
MODIFY_SAMPLE_SETTING: "MODIFY_SAMPLE_SETTING",
|
|
||||||
GET_SETTING_Dafault_DATA: "GET_SETTING_Dafault_DATA",
|
|
||||||
GET_DRAFT_FILE_LIST: "GET_DRAFT_FILE_LIST",
|
|
||||||
GET_FRAME: "GET_FRAME",
|
|
||||||
PYTHON_ERROR: "PYTHON_ERROR",
|
|
||||||
PYTHON_CLOSE: "PYTHON_CLOSE",
|
|
||||||
PYTHON_OUTPUT: "PYTHON_OUTPUT",
|
|
||||||
RESTART_GENERATE: "RESTART_GENERATE",
|
|
||||||
ALIGN_DRAFT_IMG: "ALIGN_DRAFT_IMG",
|
|
||||||
ALIGN_DRAFT_IMG_TO_TEXT: "ALIGN_DRAFT_IMG_TO_TEXT",
|
|
||||||
REGENERATE_IMAGE_RETUN: "REGENERATE_IMAGE_RETUN",
|
|
||||||
GET_SUBFOLDER_LIST: "GET_SUBFOLDER_LIST",
|
|
||||||
REFRASH_IMAGWE_DATA: "REFRASH_IMAGWE_DATA",
|
|
||||||
GET_IMAGE_PROMPTLIST: "GET_IMAGE_PROMPTLIST",
|
|
||||||
SELECT_FILE: "SELECT_FILE",
|
|
||||||
IMPROVE_IMAGE_RESOULTION: "IMPROVE_IMAGE_RESOULTION",
|
|
||||||
GET_BACKGROUND_MUSIC_CONFIG_LIST: "GET_BACKGROUND_MUSIC_CONFIG_LIST",
|
|
||||||
ADD_BACKGROUND_MUSIC_FOLDER: "ADD_BACKGROUND_MUSIC_FOLDER",
|
|
||||||
DELETE_CLIP_SETTING: "DELETE_CLIP_SETTING",
|
|
||||||
DELETE_FRIENDLY_REMINDER: "DELETE_FRIENDLY_REMINDER",
|
|
||||||
MODIFY_INPUT_CROP_JSON: "MODIFY_INPUT_CROP_JSON",
|
|
||||||
PUSH_BACK_PROMPT: "PUSH_BACK_PROMPT",
|
|
||||||
GET_FRIENDLY_REMINDER_DRAFT: "GET_FRIENDLY_REMINDER_DRAFT",
|
|
||||||
GET_FRIENDLY_REMINDER_LIST: "GET_FRIENDLY_REMINDER_LIST",
|
|
||||||
AUTO_GENERATION_VIDEO: "AUTO_GENERATION_VIDEO",
|
|
||||||
GET_PROJECT_WORD: "GET_PROJECT_WORD",
|
|
||||||
AIMODIFY_ONE_WORD: "AIMODIFY_ONE_WORD",
|
|
||||||
IMPORT_SRT_AND_GET_TIME: "IMPORT_SRT_AND_GET_TIME",
|
|
||||||
SAVE_NEW_WORD: "SAVE_NEW_WORD",
|
|
||||||
SAVE_COPYWRITING_INFOMATION: "SAVE_COPYWRITING_INFOMATION",
|
|
||||||
SAVE_SD_CONFIG: "SAVE_SD_CONFIG",
|
|
||||||
SAVE_GENERAL_SETTING: "SAVE_GENERAL_SETTING",
|
|
||||||
GET_VIDEO_CONFIG_MESSAGE: "GET_VIDEO_CONFIG_MESSAGE",
|
|
||||||
GET_SYSTEM_INSTALL_FONTNAME: "GET_SYSTEM_INSTALL_FONTNAME",
|
|
||||||
SAVE_ASS_CONFIG: "SAVE_ASS_CONFIG",
|
|
||||||
DELETE_VIDEO_CONFIG: "DELETE_VIDEO_CONFIG",
|
|
||||||
SHOW_NEW_WINDOW: "SHOW_NEW_WINDOW",
|
|
||||||
GET_DRAFT_FILE_LIST: "GET_DRAFT_FILE_LIST",
|
|
||||||
SELECT_FOLDER: "SELECT_FOLDER",
|
|
||||||
GET_DRAFT_TEXT_STYLE: "GET_DRAFT_TEXT_STYLE",
|
|
||||||
GET_TEXT_STYLE_LIST: "GET_TEXT_STYLE_LIST",
|
|
||||||
DELETE_DRAFT_TEXT_STYLE: "DELETE_DRAFT_TEXT_STYLE",
|
|
||||||
ADD_DRAFT: "ADD_DRAFT",
|
|
||||||
RETURN_IMAGE_PROMPT: "RETURN_IMAGE_PROMPT",
|
|
||||||
RE_GENERATE_IAMGE_ONE: "RE_GENERATE_IAMGE_ONE",
|
|
||||||
INIT_SD_CONFIG: "INIT_SD_CONFIG",
|
|
||||||
ADD_IMAGE_TASK_LIST: "ADD_IMAGE_TASK_LIST",
|
|
||||||
GET_GENERATE_TASK_LIST: "GET_GENERATE_TASK_LIST",
|
|
||||||
DELETE_IMAGE_TASK_LIST: "DELETE_IMAGE_TASK_LIST",
|
|
||||||
GENERATE_IMAGWE_IN_SELECT_TASK: "GENERATE_IMAGWE_IN_SELECT_TASK",
|
|
||||||
GET_MACHINE_ID: "GET_MACHINE_ID",
|
|
||||||
QUIT_APP: "QUIT_APP",
|
|
||||||
GET_BAD_PROMPT: "GET_BAD_PROMPT",
|
|
||||||
SAVE_BAD_PROMPT: "SAVE_BAD_PROMPT",
|
|
||||||
DELETE_BAD_PROMPT: "DELETE_BAD_PROMPT",
|
|
||||||
ADD_WEBUI_JSON: "ADD_WEBUI_JSON",
|
|
||||||
OPEN_GPT_BUY_URL: "OPEN_GPT_BUY_URL",
|
|
||||||
GET_IAMGE_PROMPT_LIST: "GET_IAMGE_PROMPT_LIST",
|
|
||||||
GET_ADETAILER_LIST: "GET_ADETAILER_LIST",
|
|
||||||
SAVE_DETAILER_CONFIG: "SAVE_DETAILER_CONFIG",
|
|
||||||
OPEN_URL: "OPEN_URL",
|
|
||||||
GET_VERSION: "GET_VERSION",
|
|
||||||
GET_FRAME_RETUN: "GET_FRAME_RETUN",
|
|
||||||
DOWNLOAD_MODEL: "DOWNLOAD_MODEL",
|
|
||||||
START_STORY_BOARDING: "START_STORY_BOARDING",
|
|
||||||
SHOW_MESSAGE_DIALOG: "SHOW_MESSAGE_DIALOG",
|
|
||||||
SHOW_GLOABAL_MESSAGE_DIALOG: "SHOW_GLOABAL_MESSAGE_DIALOG",
|
|
||||||
IMAGE_TASK_STATUS_REFRESH: "IMAGE_TASK_STATUS_REFRESH",
|
|
||||||
SAVE_TRIAL_END_TIME: "SAVE_TRIAL_END_TIME",
|
|
||||||
DOWNLOAD_IMAGE_FILE: "DOWNLOAD_IMAGE_FILE",
|
|
||||||
OPEN_FOLDER: "OPEN_FOLDER",
|
|
||||||
VIDEO_GENERATE_STATUS_REFRESH: "VIDEO_GENERATE_STATUS_REFRESH",
|
|
||||||
AUTO_CONDITION_CHECK: "AUTO_CONDITION_CHECK",
|
|
||||||
MODIFY_IMAGE_TASK_LIST: "MODIFY_IMAGE_TASK_LIST",
|
|
||||||
ACTION_AUTO_VIDEO_TASK: "ACTION_AUTO_VIDEO_TASK",
|
|
||||||
GET_VIDEO_GENERATE_CONFIG: "GET_VIDEO_GENERATE_CONFIG",
|
|
||||||
TRANSLATE_PROMPT: "TRANSLATE_PROMPT",
|
|
||||||
TRANSLATE_RETURN_NOW: "TRANSLATE_RETURN_NOW",
|
|
||||||
TRANSLATE_RETURN_REFRESH: "TRANSLATE_RETURN_REFRESH",
|
|
||||||
GET_SHOW_MESSAGE: "GET_SHOW_MESSAGE",
|
|
||||||
AUTO_ANALYZE_CHARACTER: "AUTO_ANALYZE_CHARACTER",
|
|
||||||
GET_CONFIG_JSON: "GET_CONFIG_JSON",
|
|
||||||
ORIGINAL_ADD_WEBUI_JSON: "ORIGINAL_ADD_WEBUI_JSON",
|
|
||||||
GET_PROMPT_JSON: "GET_PROMPT_JSON",
|
|
||||||
GPT_PROMPT: "GPT_PROMPT",
|
|
||||||
GPT_GENERATE_PROMPT_RETURN: "GPT_GENERATE_PROMPT_RETURN",
|
|
||||||
AUTO_SAVE_DATA_JSON: "AUTO_SAVE_DATA_JSON",
|
|
||||||
ORIGINAL_SD_SINGLE_IMAGE_GENERATE: "ORIGINAL_SD_SINGLE_IMAGE_GENERATE",
|
|
||||||
SD_ORIGINAL_GENERATE_IMAGE_RETURN: "SD_ORIGINAL_GENERATE_IMAGE_RETURN",
|
|
||||||
GET_STYLE_IMAGE_SUB_LIST: "GET_STYLE_IMAGE_SUB_LIST",
|
|
||||||
GET_IMAGE_STYLE_INFOMATION: "GET_IMAGE_STYLE_INFOMATION",
|
|
||||||
GET_IMAGE_STYLE_MENU: "GET_IMAGE_STYLE_MENU",
|
|
||||||
GET_GPT_BUSINESS_OPTION: "GET_GPT_BUSINESS_OPTION",
|
|
||||||
GET_GPT_MODEL_OPTION: "GET_GPT_MODEL_OPTION",
|
|
||||||
GET_GPT_AUTO_INFERENCE_OPTIONS: "GET_GPT_AUTO_INFERENCE_OPTIONS",
|
|
||||||
SAVE_DYNAMIC_GPT_OPTION: "SAVE_DYNAMIC_GPT_OPTION",
|
|
||||||
DELETE_DYNAMIC_GPT_OPTION: "DELETE_DYNAMIC_GPT_OPTION",
|
|
||||||
TEST_GPT_CONNECTION: "TEST_GPT_CONNECTION",
|
|
||||||
SAVE_WORD_TXT: "SAVE_WORD_TXT",
|
|
||||||
GET_KEY_FRAME_CONFIG_DATA: "GET_KEY_FRAME_CONFIG_DATA",
|
|
||||||
GET_KEYFRAME_OPTIONS: "GET_KEYFRAME_OPTIONS",
|
|
||||||
|
|
||||||
QUEUE_BATCH: {
|
|
||||||
SD_ORIGINAL_GENERATE_IMAGE: "SD_ORIGINAL_GENERATE_IMAGE",
|
|
||||||
SD_ORIGINAL_GPT_PROMPT: "SD_ORIGINAL_GPT_PROMPT",
|
|
||||||
SD_BACKSTEP_GENERATE_IMAGE: "SD_BACKSTEP_GENERATE_IMAGE",
|
|
||||||
MJ_ORIGINAL_GENERATE_IMAGE: "MJ_ORIGINAL_GENERATE_IMAGE",
|
|
||||||
LOCAL_IMAGE_IMPROVE: "LOCAL_IMAGE_IMPROVE",
|
|
||||||
AUTO_VIDEO_GENERATE: "AUTO_VIDEO_GENERATE",
|
|
||||||
AUTO_VIDEO_GENERATE_SINGLE: "AUTO_VIDEO_GENERATE_SINGLE",
|
|
||||||
TRANSLATE_PROMPT: "TRANSLATE_PROMPT",
|
|
||||||
TRANSLATE_RETURN_NOW_TASK: "TRANSLATE_RETURN_NOW_TASK",
|
|
||||||
IMAGE_SAVE_TO_OTHER_FOLDER: "IMAGE_SAVE_TO_OTHER_FOLDER",
|
|
||||||
SAVE_FILE_QUEUE: "SAVE_FILE_QUEUE",
|
|
||||||
},
|
|
||||||
PERMISSIONS: {
|
|
||||||
NORMAL_PERMISSION: "NORMAL_PERMISSION",
|
|
||||||
AUTO_SAVE_IMAGE_PERMISSION: "AUTO_SAVE_IMAGE_PERMISSION",
|
|
||||||
},
|
|
||||||
MJ: {
|
|
||||||
SAVE_WORD_SRT: "SAVE_WORD_SRT",
|
|
||||||
GET_MJ_CONFIG_SRT_INFORMATION: "GET_MJ_CONFIG_SRT_INFORMATION",
|
|
||||||
GET_TAG_DATA_BY_TYPE_AND_PROPERTY: "GET_TAG_DATA_BY_TYPE_AND_PROPERTY",
|
|
||||||
SAVE_TAG_PROPERTY_DATA: "SAVE_TAG_PROPERTY_DATA",
|
|
||||||
DELETE_TAG_PROPERTY_DATA: "DELETE_TAG_PROPERTY_DATA",
|
|
||||||
GET_TAG_SELECT_MODEL: "GET_TAG_SELECT_MODEL",
|
|
||||||
TRANSLATE_RETURN_NOW_TASK: "TRANSLATE_RETURN_NOW_TASK",
|
|
||||||
ORIGINAL_MJ_IMAGE_GENERATE: "ORIGINAL_MJ_IMAGE_GENERATE",
|
|
||||||
GET_CHANNEL_ROBOTS: "GET_CHANNEL_ROBOTS",
|
|
||||||
GET_MJ_GENERATE_CATEGORY: "GET_MJ_GENERATE_CATEGORY",
|
|
||||||
IMAGE_SPLIT: "IMAGE_SPLIT",
|
|
||||||
ADD_MJ_BAD_PROMPT: "ADD_MJ_BAD_PROMPT",
|
|
||||||
MJ_BAD_PROMPT_CHECK: "MJ_BAD_PROMPT_CHECK",
|
|
||||||
GET_GENERATED_MJ_IMAGE_AND_SPLIT: "GET_GENERATED_MJ_IMAGE_AND_SPLIT",
|
|
||||||
DOWNLOAD_IMAGE_URL_AND_SPLIT: "DOWNLOAD_IMAGE_URL_AND_SPLIT"
|
|
||||||
},
|
|
||||||
DISCORD: {
|
|
||||||
OPERATE_REFRASH_DISCORD_URL: "OPERATE_REFRASH_DISCORD_URL",
|
|
||||||
GET_DISCORD_WINDOW_URL: "GET_DISCORD_WINDOW_URL",
|
|
||||||
CREATE_MESSAGE: "CREATE_MESSAGE",
|
|
||||||
UPDATE_MESSAGE: "UPDATE_MESSAGE",
|
|
||||||
DELETE_MESSAGE: "DELETE_MESSAGE",
|
|
||||||
MAIN_DISCORD_MESSAGE_CHANGE: "MAIN_DISCORD_MESSAGE_CHANGE",
|
|
||||||
},
|
|
||||||
DISCORD_REQUEST_LISTENER_TYPE: {
|
|
||||||
INPUT_MODEL_IMAGINE_REQUEST: "INPUT_MODEL_IMAGINE_REQUEST",
|
|
||||||
},
|
|
||||||
DISCORD_SIMPLE_DATA_TYPE: {
|
|
||||||
URL: "URL",
|
|
||||||
TOKEN: "TOKEN",
|
|
||||||
},
|
|
||||||
MAIN: {
|
|
||||||
OPEN_DISCORD_WINDOW: "OPEN_DISCORD_WINDOW"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@ -1,72 +0,0 @@
|
|||||||
const {
|
|
||||||
ipcMain
|
|
||||||
} = require("electron")
|
|
||||||
import { DEFINE_STRING } from '../../define/define_string'
|
|
||||||
import {
|
|
||||||
Setting
|
|
||||||
} from '../setting/setting'
|
|
||||||
let setting = new Setting(global);
|
|
||||||
|
|
||||||
function SettingIpc() {
|
|
||||||
|
|
||||||
// 获取背景音乐配置列表
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_BACKGROUND_MUSIC_CONFIG_LIST, async (event) => await setting.GetBackGroundMusicConfigList());
|
|
||||||
|
|
||||||
// 获取剪映关键帧配置列表
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_KEYFRAME_OPTIONS, async (event) => await setting.GetKeyFrameOptions());
|
|
||||||
// 保存剪映关键帧配置
|
|
||||||
ipcMain.handle(DEFINE_STRING.SAVE_KEY_FRAME_SETTING, async (event, value) => await setting.SaveKeyFrameSetting(value));
|
|
||||||
// 监听添加背景音乐文件
|
|
||||||
ipcMain.handle(DEFINE_STRING.ADD_BACKGROUND_MUSIC_FOLDER, async (event, value) => await setting.AddBackgroundMusicFolder(value))
|
|
||||||
// 删除剪映的样式设置
|
|
||||||
ipcMain.handle(DEFINE_STRING.DELETE_DRAFT_TEXT_STYLE, async (event, value) => await setting.deleteClipSetting("text_style", value));
|
|
||||||
|
|
||||||
// 删除剪映的背景音乐设置
|
|
||||||
ipcMain.handle(DEFINE_STRING.DELETE_CLIP_SETTING, async (event, value) => await setting.deleteClipSetting("background_music_setting", value));
|
|
||||||
// 删除剪映的友情提示设置
|
|
||||||
ipcMain.handle(DEFINE_STRING.DELETE_FRIENDLY_REMINDER, async (event, value) => await setting.deleteClipSetting("friendly_reminder_setting", value));
|
|
||||||
|
|
||||||
// 监听获取SD配置任务
|
|
||||||
ipcMain.handle(DEFINE_STRING.INIT_SD_CONFIG, async (event, value) => await setting.InitSDConfig());
|
|
||||||
|
|
||||||
// 获取主页显示信息
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_SHOW_MESSAGE, async (event) => await setting.GetShowMessage())
|
|
||||||
// 获取关键帧的配置数据
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_KEY_FRAME_CONFIG_DATA, async (event) => await setting.GetKeyFrameConfigData());
|
|
||||||
|
|
||||||
// 删除后台队列任务
|
|
||||||
ipcMain.handle(DEFINE_STRING.DELETE_BACK_TASK, async (event, value) => await setting.RemoveTask(value));
|
|
||||||
|
|
||||||
// 获取自动保存图片的分类方式
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_AUTO_SAVE_IMAGE_CLASSIFY_OPTIONS, async (event) => await setting.GetAutoSaveImageClassifyOptions());
|
|
||||||
|
|
||||||
// 保存图片自动保存的配置
|
|
||||||
ipcMain.handle(DEFINE_STRING.SAVE_IMAGE_AUTO_SAVE_SETTING, async (event, value) => await setting.SaveImageAutoSaveSetting(value));
|
|
||||||
|
|
||||||
// 获取当前的自动保存图片的设置
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_IMAGE_AUTO_SAVE_SETTING, async (event) => await setting.GetImageAutoSaveSetting());
|
|
||||||
|
|
||||||
// 开始手动保存图片
|
|
||||||
ipcMain.handle(DEFINE_STRING.SAVE_IMAGE_TO_OTHER_FOLDER, async (event, value) => await setting.SaveImageToOtherFolder(value));
|
|
||||||
// 检查机器码是否存在
|
|
||||||
ipcMain.handle(DEFINE_STRING.CHECK_MACHINE_ID, async (event, value) => await setting.CheckMachineId(value));
|
|
||||||
|
|
||||||
//修改剪映草稿配置
|
|
||||||
ipcMain.handle(DEFINE_STRING.MODIFY_SAMPLE_SETTING, async (event, value) => await setting.ModifySampleSetting(value));
|
|
||||||
|
|
||||||
// 获取选择角色场景模式的options
|
|
||||||
ipcMain.handle(DEFINE_STRING.MJ.GET_TAG_SELECT_MODEL, async (event) => await setting.GetRoleSceneModeOptions());
|
|
||||||
|
|
||||||
// 获取当前生成图片的生图方式(sd,mj,d3)
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_IMAGE_GENERATE_CATEGORY, async (event) => await setting.GetImageGenerateCategory());
|
|
||||||
|
|
||||||
// // 获取指定的配置文件里面指定的属性的数据
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_DEFINE_CONFIG_JSON_BY_PROPERTY, async (event, value) => await setting.GetDefineConfigJsonByProperty(value))
|
|
||||||
|
|
||||||
// // 保存指定的配置文件里面指定的属性的数据
|
|
||||||
ipcMain.handle(DEFINE_STRING.SAVE_DEFINE_CONFIG_JSON_BY_PROPERTY, async (event, value) => await setting.SaveDefineConfigJsonByProperty(value))
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
SettingIpc
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import {
|
|
||||||
ipcMain
|
|
||||||
} from "electron";
|
|
||||||
import { DEFINE_STRING } from '../../define/define_string'
|
|
||||||
import {
|
|
||||||
Writing
|
|
||||||
} from '../backPrompt/writing'
|
|
||||||
let writing = new Writing(global);
|
|
||||||
|
|
||||||
function WritingIpc() {
|
|
||||||
// 监听分镜时间的保存
|
|
||||||
ipcMain.handle(DEFINE_STRING.SAVE_COPYWRITING_INFOMATION, async (event, value) => await writing.SaveCopywritingInformation(value));
|
|
||||||
|
|
||||||
// 监听获取当前项目下面的分镜文案
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_PROJECT_WORD, async (event, value) => await writing.GetProjectWord());
|
|
||||||
|
|
||||||
// 获取config配置文件数据
|
|
||||||
ipcMain.handle(DEFINE_STRING.GET_CONFIG_JSON, async (event, value) => await writing.GetConfigJson(value));
|
|
||||||
|
|
||||||
// 将指定的文案txt数组写入到指定的文件中
|
|
||||||
ipcMain.handle(DEFINE_STRING.SAVE_WORD_TXT, async (event, value) => await writing.SaveWordTxt(value));
|
|
||||||
|
|
||||||
// 监听获取字幕时间
|
|
||||||
ipcMain.handle(DEFINE_STRING.IMPORT_SRT_AND_GET_TIME, async (event, value) => await writing.ImportSrtAndGetTime(value))
|
|
||||||
}
|
|
||||||
export {
|
|
||||||
WritingIpc
|
|
||||||
}
|
|
||||||
@ -1,33 +0,0 @@
|
|||||||
import { TagDefine } from "../../define/tagDefine";
|
|
||||||
export class TagCustomize {
|
|
||||||
constructor(global) {
|
|
||||||
this.global = global;
|
|
||||||
this.tagDefine = new TagDefine(global);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取默认的tag
|
|
||||||
* @param {*} value
|
|
||||||
*/
|
|
||||||
async GetTagDataByTypeAndProperty(value) {
|
|
||||||
return await this.tagDefine.getTagDataByTypeAndProperty(value[0], value[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存数据到指定的tag中
|
|
||||||
* @param {*} value
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async SaveTagPropertyData(value) {
|
|
||||||
return await this.tagDefine.saveTagPropertyData(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除指定的tag数据
|
|
||||||
* @param {*} value
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async DeleteTagPropertyData(value) {
|
|
||||||
return await this.tagDefine.deleteTagPropertyData(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,493 +0,0 @@
|
|||||||
|
|
||||||
import { Tools } from "../tools";
|
|
||||||
import path from "path";
|
|
||||||
import { DEFINE_STRING } from "../../define/define_string";
|
|
||||||
import { define } from "../../define/define";
|
|
||||||
import { PublicMethod } from "../Public/publicMethod";
|
|
||||||
import { SD } from "../Public/SD"
|
|
||||||
const util = require('util');
|
|
||||||
const { spawn, exec } = require('child_process');
|
|
||||||
import axios from "axios";
|
|
||||||
const sharp = require('sharp');
|
|
||||||
const execAsync = util.promisify(exec);
|
|
||||||
const { v4: uuidv4 } = require('uuid'); // 引入UUID库来生成唯一标识符
|
|
||||||
let fspromises = require("fs").promises;
|
|
||||||
import { MD5 } from "crypto-js";
|
|
||||||
import { ImageSetting } from "../../define/setting/imageSetting";
|
|
||||||
|
|
||||||
|
|
||||||
export class ImageGenerate {
|
|
||||||
constructor(global) {
|
|
||||||
this.global = global;
|
|
||||||
this.tools = new Tools();
|
|
||||||
this.pm = new PublicMethod(global);
|
|
||||||
this.sd = new SD(global);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取指定名称的提示词json文件数据
|
|
||||||
* @param {*} value
|
|
||||||
*/
|
|
||||||
async GetPromptJson(value) {
|
|
||||||
try {
|
|
||||||
let json_path = path.join(this.global.config.project_path, "tmp/input_crop/" + value + ".json");
|
|
||||||
let isExist = await this.tools.checkExists(json_path);
|
|
||||||
if (!isExist) {
|
|
||||||
throw new Error("提示词文件不存在");
|
|
||||||
}
|
|
||||||
let res = JSON.parse(await fspromises.readFile(json_path, 'utf-8'));
|
|
||||||
return {
|
|
||||||
value: 1,
|
|
||||||
data: res
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改指定任务队列的状态
|
|
||||||
* @param {*} value 0 使用什么查找(id。out_folder,) 1查找的值 2 状态值
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async ModifyGenerateTaskStatus(value) {
|
|
||||||
try {
|
|
||||||
await this.pm.ModifyTaskStatus(value[0], value[1], value[2]);
|
|
||||||
return {
|
|
||||||
code: 1
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改本地的参数
|
|
||||||
* @param {修改json的参数} value
|
|
||||||
*/
|
|
||||||
async ModifyInpurCropJson(value) {
|
|
||||||
try {
|
|
||||||
value = JSON.parse(value);
|
|
||||||
let prompt = value.prompt;
|
|
||||||
// 重绘幅度
|
|
||||||
let denoising_strength = value.denoising_strength;
|
|
||||||
let json_path = path.join(path.join(global.config.project_path, 'tmp/input_crop'), value.name + ".json");
|
|
||||||
let old_json = JSON.parse(await fspromises.readFile(json_path, 'utf-8'));
|
|
||||||
old_json.webui_config.prompt = prompt;
|
|
||||||
old_json.webui_config.denoising_strength = denoising_strength;
|
|
||||||
old_json.model = value.model;
|
|
||||||
old_json.adetailer = value.adetailer;
|
|
||||||
old_json.chinese_prompt = value.chinese_prompt;
|
|
||||||
|
|
||||||
if (value.modify_old) {
|
|
||||||
old_json.webui_config.init_images = value.modify_old;
|
|
||||||
}
|
|
||||||
|
|
||||||
await fspromises.writeFile(json_path, JSON.stringify(old_json));
|
|
||||||
return {
|
|
||||||
code: 1
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回文件夹里的所有的图片,以及其他信息
|
|
||||||
* @param {图片文件夹} value
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async getFolderImageList(mainWindow, value, isReturn) {
|
|
||||||
try {
|
|
||||||
let img_dir = path.normalize(value);
|
|
||||||
let base_name = path.basename(img_dir);
|
|
||||||
let tmp = path.dirname(img_dir);
|
|
||||||
let input_path = path.join(tmp, "input_crop")
|
|
||||||
// console.log(tmp, input_path)
|
|
||||||
let files = await fspromises.readdir(img_dir)
|
|
||||||
let imageFiles = files.filter(file => /\.(png)$/i.test(file));
|
|
||||||
imageFiles.sort();
|
|
||||||
|
|
||||||
let res = [];
|
|
||||||
let task_list_json = JSON.parse(await fspromises.readFile(path.join(this.global.config.project_path, 'scripts/task_list.json'), 'utf-8'));
|
|
||||||
// 处理数据
|
|
||||||
for (let i = 0; i < imageFiles.length; i++) {
|
|
||||||
const img = imageFiles[i];
|
|
||||||
let imput_path = path.join(input_path, img);
|
|
||||||
let img_json = path.join(input_path, img + '.json');
|
|
||||||
// 判断文件是不是存在
|
|
||||||
let prompt_json = JSON.parse(await fspromises.readFile(img_json));
|
|
||||||
|
|
||||||
let output_list = await this.pm.getSubFolderList(path.join(this.global.config.project_path, "tmp"), 'start', 'output_crop');
|
|
||||||
let output_image_list = [];
|
|
||||||
for (let i = 0; i < output_list.length; i++) {
|
|
||||||
const item = output_list[i];
|
|
||||||
// 找到找到文件对应的任务列表的样式和lora
|
|
||||||
let task_list = task_list_json.task_list.filter(a => a.out_folder == item);
|
|
||||||
let output_1 = path.join(tmp, item);
|
|
||||||
let obj = {
|
|
||||||
id: uuidv4(),
|
|
||||||
img_path: path.join(output_1, img),
|
|
||||||
image_style: task_list[0].image_style,
|
|
||||||
lora: task_list[0].lora
|
|
||||||
}
|
|
||||||
output_image_list.push(obj);
|
|
||||||
|
|
||||||
}
|
|
||||||
let main_task_list = task_list_json.task_list.filter(a => a.out_folder == base_name);
|
|
||||||
let obj = {
|
|
||||||
name: img,
|
|
||||||
id: uuidv4(),
|
|
||||||
sampler_name: prompt_json.webui_config.sampler_name,
|
|
||||||
prompt: prompt_json.webui_config.prompt,
|
|
||||||
chinese_prompt: prompt_json.chinese_prompt,
|
|
||||||
negative_prompt: prompt_json.webui_config.negative_prompt,
|
|
||||||
denoising_strength: prompt_json.webui_config.denoising_strength,
|
|
||||||
seed: prompt_json.webui_config.seed,
|
|
||||||
image: path.join(img_dir, img),
|
|
||||||
oldImage: prompt_json.webui_config.init_images,
|
|
||||||
output_list: output_image_list,
|
|
||||||
model: prompt_json.model,
|
|
||||||
image_style: main_task_list[0].image_style,
|
|
||||||
lora: main_task_list[0].lora,
|
|
||||||
image_style_list: main_task_list[0].image_style_list,
|
|
||||||
adetailer: prompt_json.adetailer,
|
|
||||||
width: prompt_json.webui_config.width,
|
|
||||||
height: prompt_json.webui_config.height
|
|
||||||
}
|
|
||||||
res.push(obj)
|
|
||||||
// 获取提示词
|
|
||||||
}
|
|
||||||
if (isReturn) {
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
windowID: mainWindow.id,
|
|
||||||
value: res
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mainWindow.webContents.send(DEFINE_STRING.RETURN_IMAGE_PROMPT, {
|
|
||||||
code: 1,
|
|
||||||
windowID: mainWindow.id,
|
|
||||||
value: res
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: `Error message ${error.toString()}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将反推的图片的信息添加到一个json文件中
|
|
||||||
*/
|
|
||||||
async AddWebuiJson() {
|
|
||||||
try {
|
|
||||||
return await this.pm.AddWebuiJson();
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改任务队列数据
|
|
||||||
* @param {替换后的值} value
|
|
||||||
*/
|
|
||||||
async ModifyImageTaskList(value) {
|
|
||||||
try {
|
|
||||||
let res = await this.pm.ModifyImageTaskList(value);
|
|
||||||
if (res) {
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
message: "替换成功"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取生成图片的任务队列(可以添加部分判断)
|
|
||||||
*/
|
|
||||||
async GetGenerateTaskList() {
|
|
||||||
try {
|
|
||||||
return await this.pm.GetImageTask()
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成任务中的队列
|
|
||||||
* @param {传入所有执行生图队列的任务} value
|
|
||||||
*/
|
|
||||||
async GenerateImageInSelectTask(value) {
|
|
||||||
try {
|
|
||||||
let batch = DEFINE_STRING.QUEUE_BATCH.SD_BACKSTEP_GENERATE_IMAGE
|
|
||||||
let taskPath = path.join(this.global.config.project_path, 'scripts/task_list.json');
|
|
||||||
let task_list_json = JSON.parse(await fspromises.readFile(taskPath, 'utf-8'));
|
|
||||||
let auto_save_image = await this.tools.getJsonFilePropertyValue(define.img_base, "auto_save_image", {}, false);
|
|
||||||
let png_files = [];
|
|
||||||
// 读取队列中的任务,然后添加队列
|
|
||||||
for (let i = 0; i < value.length; i++) {
|
|
||||||
const element = value[i];
|
|
||||||
let task_list = task_list_json.task_list.filter(item => item.id == element)[0];
|
|
||||||
let seed = -1;
|
|
||||||
let images = await this.tools.getFilesWithExtensions(path.join(this.global.config.project_path, 'tmp/input_crop'), '.png');
|
|
||||||
await fspromises.mkdir(path.join(this.global.config.project_path, 'tmp/' + task_list.out_folder), { recursive: true });
|
|
||||||
if (images.length <= 0) {
|
|
||||||
throw new Error("未检测到抽帧图片。请检查");
|
|
||||||
}
|
|
||||||
if (images.length > auto_save_image.save_match_count) {
|
|
||||||
png_files = await this.tools.getFilesWithExtensions(auto_save_image.main_save_folder, '.png');
|
|
||||||
}
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
let res = await this.sd.OneImageGeneration(images[0], task_list, seed);
|
|
||||||
let tmp_seed = -1;
|
|
||||||
if (seed == -1) {
|
|
||||||
tmp_seed = res;
|
|
||||||
}
|
|
||||||
for (let j = 1; j < images.length; j++) {
|
|
||||||
const item = images[j];
|
|
||||||
|
|
||||||
let has_permission = false;
|
|
||||||
// 判断权限
|
|
||||||
let permission = this.global.permission;
|
|
||||||
|
|
||||||
if (permission && permission.length >= 0) {
|
|
||||||
if (permission.indexOf(DEFINE_STRING.PERMISSIONS.AUTO_SAVE_IMAGE_PERMISSION) >= 0) {
|
|
||||||
has_permission = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
has_permission = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auto_save_image.save_match_count && j >= auto_save_image.save_match_count && has_permission && auto_save_image.auto_match) {
|
|
||||||
// 现在随机匹配视频
|
|
||||||
// 获取指定的文件夹中的图片
|
|
||||||
let randomData = png_files[Math.floor(Math.random() * png_files.length)];
|
|
||||||
let base_name = path.basename(item);
|
|
||||||
let copy_path = path.join(this.global.config.project_path, 'tmp/' + task_list.out_folder, base_name);
|
|
||||||
await this.tools.copyFileOrDirectory(randomData, copy_path);
|
|
||||||
} else {
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
await this.sd.OneImageGeneration(item, task_list, tmp_seed);
|
|
||||||
}, `${task_list.out_folder}_${images[j]}`, batch, task_list.out_folder)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}, `${task_list.out_folder}_${images[0]}`, batch, task_list.out_folder)
|
|
||||||
// }
|
|
||||||
task_list.status = 'queue';
|
|
||||||
|
|
||||||
// 开始批次执行(全部刷新)
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.IMAGE_TASK_STATUS_REFRESH, task_list);
|
|
||||||
|
|
||||||
// 判断是不是还有批次执行的任务
|
|
||||||
// 监听子批次完成(修改当前批次的状态)
|
|
||||||
this.global.requestQuene.setSubBatchCompletionCallback(batch, task_list.out_folder, async (failedTasks) => {
|
|
||||||
console.log(failedTasks)
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// 判断是不是有错误。没有错误的话。直接修改状态。有错误直接记录错误(写入一个就行)
|
|
||||||
task_list_json = JSON.parse(await fspromises.readFile(taskPath, 'utf-8'));
|
|
||||||
// 全部执行完毕之后,修改
|
|
||||||
task_list_json.task_list.map(a => {
|
|
||||||
if (a.out_folder == task_list.out_folder) {
|
|
||||||
a.status = "ok";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 写入
|
|
||||||
await fspromises.writeFile(taskPath, JSON.stringify(task_list_json));
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.IMAGE_TASK_STATUS_REFRESH, {
|
|
||||||
out_folder: task_list.out_folder,
|
|
||||||
status: "ok"
|
|
||||||
});
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, {
|
|
||||||
out_folder: task_list.out_folder,
|
|
||||||
status: "ok"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听总批次完成
|
|
||||||
this.global.requestQuene.setBatchCompletionCallback(batch, (failedTasks) => {
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
let message = `
|
|
||||||
批次生成任务都已完成。
|
|
||||||
但是以下任务执行失败:
|
|
||||||
`
|
|
||||||
failedTasks.forEach(({ taskId, error }) => {
|
|
||||||
message += `${taskId}-, \n 错误信息: ${error}` + '\n';
|
|
||||||
});
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 0,
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 1,
|
|
||||||
message: "所有生成任务完成"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 写回
|
|
||||||
await fspromises.writeFile(taskPath, JSON.stringify(task_list_json));
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 批量高清文件夹
|
|
||||||
* @param {项目下面的文件夹的值} value
|
|
||||||
*/
|
|
||||||
async ImproveResolution(value) {
|
|
||||||
try {
|
|
||||||
let batch = DEFINE_STRING.QUEUE_BATCH.LOCAL_IMAGE_IMPROVE;
|
|
||||||
|
|
||||||
// 加入队列
|
|
||||||
for (let i = 0; i < value.length; i++) {
|
|
||||||
const folder = value[i];
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
await this.pm.ImproveFolder(folder);
|
|
||||||
}, folder, batch)
|
|
||||||
|
|
||||||
// 添加队列后修改状态
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', folder, "video_improving");
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, {
|
|
||||||
out_folder: folder,
|
|
||||||
status: "video_improving"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
global.requestQuene.setBatchCompletionCallback(batch, async (failedTasks) => {
|
|
||||||
|
|
||||||
let permission = this.global.permission;
|
|
||||||
// 判断权限
|
|
||||||
if (permission && permission.length >= 0) {
|
|
||||||
if (permission.indexOf(DEFINE_STRING.PERMISSIONS.AUTO_SAVE_IMAGE_PERMISSION) >= 0) {
|
|
||||||
// 在高清前,先将要高清的图片保存
|
|
||||||
let res = await ImageSetting.SaveImageToOtherFolder(value, null);
|
|
||||||
if (res.code == 0) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 在高清前,先将要高清的图片保存
|
|
||||||
let res = await ImageSetting.SaveImageToOtherFolder(value, null);
|
|
||||||
if (res.code == 0) {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
let message = `
|
|
||||||
高清任务都已完成。
|
|
||||||
但是以下任务执行失败:
|
|
||||||
`
|
|
||||||
failedTasks.forEach(({ taskId, error }) => {
|
|
||||||
message += `${taskId}-, \n 错误信息: ${error}` + '\n';
|
|
||||||
});
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 0,
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 1,
|
|
||||||
message: "所有任务高清完成"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
code: 1
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载文件到指定位置
|
|
||||||
* @param {*} value 0: 源图片地址 1: 类型 2: 目标文件地址
|
|
||||||
*/
|
|
||||||
async DownloadImageFile(value) {
|
|
||||||
try {
|
|
||||||
let type = value[1];
|
|
||||||
let img_file = value[0];
|
|
||||||
let target_file = value[2];
|
|
||||||
if (type == "cover") {
|
|
||||||
// 下载封面
|
|
||||||
// 判断封面是不是存在
|
|
||||||
let cover_path = path.join(this.global.config.project_path, 'data/封面');
|
|
||||||
let isExist = await this.tools.checkExists(cover_path);
|
|
||||||
if (!isExist) {
|
|
||||||
await fspromises.mkdir(cover_path, { recursive: true });
|
|
||||||
}
|
|
||||||
// 复制
|
|
||||||
await fspromises.copyFile(img_file, path.join(cover_path, Date.now() + '.png'));
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
message: "保存成功!"
|
|
||||||
}
|
|
||||||
} else if (type == "replace") {
|
|
||||||
if (!target_file) {
|
|
||||||
throw new Error("目标文件地址不存在");
|
|
||||||
}
|
|
||||||
await fspromises.copyFile(path.normalize(decodeURIComponent(img_file)), path.normalize(decodeURIComponent(target_file)));
|
|
||||||
await this.tools.copyFileOrDirectory(decodeURIComponent(img_file), decodeURIComponent(target_file).replace("output_crop_1", "input_crop"));
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: "参数错误"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,556 +0,0 @@
|
|||||||
import path from "path";
|
|
||||||
import { define } from "../../define/define";
|
|
||||||
import { Tools } from "../tools";
|
|
||||||
import { PublicMethod } from "../Public/publicMethod";
|
|
||||||
import { func } from '../func'
|
|
||||||
import { DEFINE_STRING } from "../../define/define_string";
|
|
||||||
const util = require('util');
|
|
||||||
const { spawn, exec } = require('child_process');
|
|
||||||
const execAsync = util.promisify(exec);
|
|
||||||
const fspromises = require("fs").promises;
|
|
||||||
import { SD } from "../Public/SD"
|
|
||||||
|
|
||||||
export class VideoGenerate {
|
|
||||||
constructor(global) {
|
|
||||||
this.global = global;
|
|
||||||
this.tools = new Tools();
|
|
||||||
this.pm = new PublicMethod(global);
|
|
||||||
this.sd = new SD(global);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取之前的基础配置
|
|
||||||
*/
|
|
||||||
async GetVideoGenerateConfig() {
|
|
||||||
try {
|
|
||||||
let res = await this.tools.getJsonFilePropertyValue(path.join(this.global.config.project_path, "scripts/config.json"), "video_config", {}, false);
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
data: res
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 保存合成视频的基础信息(Srt,audio,background)
|
|
||||||
* @param {*} value 保存合成视频的基础信息(Srt,audio,background)
|
|
||||||
*/
|
|
||||||
async SaveVideoSrtAndAudioMessage(value) {
|
|
||||||
try {
|
|
||||||
value = JSON.parse(value);
|
|
||||||
await this.tools.writeJsonFilePropertyValue(path.join(this.global.config.project_path, "scripts/config.json"), "video_config", value);
|
|
||||||
return {
|
|
||||||
code: 1
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*全自动合成视频的任务(出图、高清、合成视频)
|
|
||||||
* @param {传入的需要执行的task_list的任务} value
|
|
||||||
*/
|
|
||||||
async ActionAutoVideoTask(value) {
|
|
||||||
try {
|
|
||||||
// 开始添加队列任务
|
|
||||||
// 生图
|
|
||||||
// 将当前的所有任务添加到队列中
|
|
||||||
await this.pm.AddWebuiJson();
|
|
||||||
let batch = DEFINE_STRING.QUEUE_BATCH.AUTO_VIDEO_GENERATE;
|
|
||||||
let taskPath = path.join(this.global.config.project_path, "scripts/task_list.json");
|
|
||||||
|
|
||||||
// // 修改数据(保存srt字幕文件位置。配音文件位置。背景音乐文件)
|
|
||||||
// this.global.fileQueue.enqueue(async () => {
|
|
||||||
// let config_json = JSON.parse(await fspromises.readFile(path.join(this.global.config.project_path, "scripts/config.json"), 'utf-8'));
|
|
||||||
// config_json.srt_path = value[1].srt_path;
|
|
||||||
// config_json.audio_path = value[1].audio_path;
|
|
||||||
// config_json.background_music = value[1].background_music;
|
|
||||||
// await fspromises.writeFile(path.join(this.global.config.project_path, "scripts/config.json"), JSON.stringify(config_json));
|
|
||||||
// })
|
|
||||||
|
|
||||||
await this.tools.writeJsonFilePropertyValue(path.join(this.global.config.project_path, "scripts/config.json"), "video_config", value[1]);
|
|
||||||
|
|
||||||
// 便利所有的队列任务
|
|
||||||
for (let i = 0; i < value[0].length; i++) {
|
|
||||||
// 将所有的数据天添加到队列(总的大队列,有很多的小队列)
|
|
||||||
// 将所有生图任务添加到队列中
|
|
||||||
const task_list = value[0][i];
|
|
||||||
let seed = -1;
|
|
||||||
let subBatchId = `${task_list.out_folder}_image`
|
|
||||||
let images = await this.tools.getFilesWithExtensions(path.join(this.global.config.project_path, 'tmp/input_crop'), '.png');
|
|
||||||
await fspromises.mkdir(path.join(this.global.config.project_path, 'tmp/' + task_list.out_folder), { recursive: true });
|
|
||||||
if (images.length <= 0) {
|
|
||||||
throw new Error("未检测到抽帧图片。请检查");
|
|
||||||
}
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
let res = await this.sd.OneImageGeneration(images[0], task_list, seed);
|
|
||||||
let tmp_seed = -1;
|
|
||||||
if (seed == -1) {
|
|
||||||
tmp_seed = res;
|
|
||||||
}
|
|
||||||
for (let j = 1; j < images.length; j++) {
|
|
||||||
const element = images[j];
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
await this.sd.OneImageGeneration(element, task_list, tmp_seed);
|
|
||||||
}, `${task_list.out_folder}_${images[j]}`, batch, subBatchId)
|
|
||||||
}
|
|
||||||
|
|
||||||
}, `${task_list.out_folder}_${images[0]}`, batch, subBatchId)
|
|
||||||
// }
|
|
||||||
task_list.status = 'queue';
|
|
||||||
task_list["isAuto"] = "true";
|
|
||||||
await this.pm.ModifyImageTaskList([task_list]);
|
|
||||||
// 修改状态
|
|
||||||
// await this.pm.ModifyTaskStatus("id", task_list.id, "queue");
|
|
||||||
// this.global.fileQueue.enqueue(async () => {
|
|
||||||
// let task_json = JSON.parse(await fspromises.readFile(taskPath, 'utf-8'));
|
|
||||||
// let index = task_json.task_list.findIndex(item => item.id == task_list.id);
|
|
||||||
// task_json.task_list[index] = task_list;
|
|
||||||
// await fspromises.writeFile(taskPath, JSON.stringify(task_json));
|
|
||||||
// })
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, task_list)
|
|
||||||
|
|
||||||
// 判断是不是还有批次执行的任务
|
|
||||||
// 监听子批次完成(修改当前批次的状态)
|
|
||||||
this.global.requestQuene.setSubBatchCompletionCallback(batch, subBatchId, async (failedTasks) => {
|
|
||||||
console.log(failedTasks)
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
// 之前的任务出现错误
|
|
||||||
// 执行错误
|
|
||||||
} else {
|
|
||||||
// 判断是不是有错误。没有错误的话。直接修改状态。有错误直接记录错误(写入一个就行)
|
|
||||||
task_list.status = "ok";
|
|
||||||
await this.pm.ModifyTaskStatus("id", task_list.id, 'ok');
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, task_list)
|
|
||||||
console.log(subBatchId + "生图执行完毕。可以开始执行高清")
|
|
||||||
|
|
||||||
// 添加高清队列
|
|
||||||
// task_list
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
await this.pm.ImproveFolder(task_list.out_folder);
|
|
||||||
}, `${task_list.out_folder}_improve`, batch, `${task_list.out_folder}_improve`);
|
|
||||||
// 添加队列后修改状态
|
|
||||||
task_list.status = "video_improving"
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', task_list.out_folder, "video_improving");
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, task_list)
|
|
||||||
|
|
||||||
// 监听高清任务完成
|
|
||||||
this.global.requestQuene.setSubBatchCompletionCallback(batch, `${task_list.out_folder}_improve`, async (failedTasks) => {
|
|
||||||
console.log(failedTasks)
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
// 之前的任务出现错误
|
|
||||||
// 执行错误
|
|
||||||
} else {
|
|
||||||
|
|
||||||
console.log(task_list.out_folder + "高清完成,可以开始合成视频");
|
|
||||||
// 添加生成视频队列
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
let video_config = JSON.parse(await fspromises.readFile(define.video_config, 'utf-8'));
|
|
||||||
await this.AutoGeneretionOneVide(task_list.out_folder, video_config, value);
|
|
||||||
}, `${task_list.out_folder}_video`, batch, `${task_list.out_folder}_video`);
|
|
||||||
task_list.status = "video_queue";
|
|
||||||
// 添加后修改状态
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', task_list.out_folder, "video_queue");
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, task_list)
|
|
||||||
|
|
||||||
// 监听生成视频任务完成
|
|
||||||
this.global.requestQuene.setSubBatchCompletionCallback(batch, `${task_list.out_folder}_video`, async (failedTasks) => {
|
|
||||||
console.log(failedTasks)
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
// 之前的任务出现错误
|
|
||||||
// 执行错误
|
|
||||||
} else {
|
|
||||||
console.log(task_list.out_folder + "合成视频完成");
|
|
||||||
// 添加生成视频队列
|
|
||||||
task_list.status = "video_ok";
|
|
||||||
// 添加后修改状态
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', task_list.out_folder, "video_ok");
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, task_list)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听总批次完成
|
|
||||||
this.global.requestQuene.setBatchCompletionCallback(batch, async (failedTasks) => {
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
let message = `
|
|
||||||
批次生成任务都已完成。
|
|
||||||
但是以下任务执行失败:
|
|
||||||
`
|
|
||||||
failedTasks.forEach(({ taskId, error }) => {
|
|
||||||
message += `${taskId}-, \n 错误信息: ${error}` + '\n';
|
|
||||||
});
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 0,
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
console.log("所有的自动生成任务完成");
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 1,
|
|
||||||
message: "所有自动任务完成"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.global.fileQueue.enqueue(async () => {
|
|
||||||
// 读取最新的数据删除
|
|
||||||
// 将自动化标识删除
|
|
||||||
let task_json = JSON.parse(await fspromises.readFile(taskPath, 'utf-8'));
|
|
||||||
for (let i = 0; i < task_json.task_list.length; i++) {
|
|
||||||
let task_list = task_json.task_list[i];
|
|
||||||
task_list["isAuto"] = "false";
|
|
||||||
await this.pm.ModifyImageTaskList([task_list]);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
message: "自动任务添加到队列中"
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取文件夹下面的子文件夹,添加判断条件
|
|
||||||
* @param {value} value
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async getSubFolderList(value) {
|
|
||||||
try {
|
|
||||||
let folder = await this.pm.getSubFolderList(path.join(this.global.config.project_path, "tmp"), value[0], value[1]);
|
|
||||||
// 找到所有的数据(查询状态返回)
|
|
||||||
let task_path = path.join(this.global.config.project_path, "scripts/task_list.json");
|
|
||||||
let isExist = await this.tools.checkExists(task_path);
|
|
||||||
let data = [];
|
|
||||||
if (!isExist) {
|
|
||||||
for (let i = 0; i < folder.length; i++) {
|
|
||||||
const element = folder[i];
|
|
||||||
let obj = {
|
|
||||||
folder: element,
|
|
||||||
status: "unkown error"
|
|
||||||
}
|
|
||||||
data.push(obj);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let task_list = JSON.parse(await fspromises.readFile(task_path, 'utf-8'))["task_list"];
|
|
||||||
// 查询状态
|
|
||||||
for (let i = 0; i < folder.length; i++) {
|
|
||||||
const element = folder[i];
|
|
||||||
let index = task_list.findIndex(item => item.out_folder == element);
|
|
||||||
if (index < 0) {
|
|
||||||
let obj = {
|
|
||||||
folder: element,
|
|
||||||
status: "unkown error"
|
|
||||||
}
|
|
||||||
data.push(obj);
|
|
||||||
} else {
|
|
||||||
let status = task_list[index].status;
|
|
||||||
let obj = {
|
|
||||||
folder: element,
|
|
||||||
status: status
|
|
||||||
}
|
|
||||||
data.push(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
data: data
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: `Error Message ${error}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动生成一个视频
|
|
||||||
* @param {视频生成图片的文件夹} element
|
|
||||||
* @param {视频配置} video_config
|
|
||||||
* @param {参数。第一个值为数组,为生成的图片文件。第二个参数是配置} value
|
|
||||||
*/
|
|
||||||
async AutoGeneretionOneVide(element, video_config, value) {
|
|
||||||
try {
|
|
||||||
let background_music = "";
|
|
||||||
// 读取背景音乐的路径
|
|
||||||
if (value[1].background_music != "") {
|
|
||||||
let background_music_config = (await func.getClipSetting("background_music_setting")).value;
|
|
||||||
let background_music_filter = background_music_config.filter(item => item.id == value[1].background_music);
|
|
||||||
if (background_music_filter.length <= 0) {
|
|
||||||
throw new Error("背景音乐对应的配置没有找到");
|
|
||||||
} else {
|
|
||||||
background_music = background_music_filter[0].folder_path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 随机获取字幕设置
|
|
||||||
let ass_config = video_config.assConfig;
|
|
||||||
let ass_random_index = Math.floor(Math.random() * ass_config.length);
|
|
||||||
let watermark_config = video_config.watermarkConfig;
|
|
||||||
let watermark_random_index = Math.floor(Math.random() * watermark_config.length);
|
|
||||||
|
|
||||||
// 对每个视频生成配置文件并将其添加到配置文件中
|
|
||||||
let obj = {
|
|
||||||
srt_path: value[1].srt_path,
|
|
||||||
// 字幕样式(需要随机)
|
|
||||||
srt_style: ass_config[ass_random_index],
|
|
||||||
audio_path: value[1].audio_path,
|
|
||||||
background_music_folder: background_music,
|
|
||||||
// 水印设置(需要随机)
|
|
||||||
friendly_reminder: watermark_config[watermark_random_index],
|
|
||||||
video_resolution_x: video_config.video_resolution_x,
|
|
||||||
video_resolution_y: video_config.video_resolution_y,
|
|
||||||
outpue_file: path.join(this.global.config.project_path, this.global.config.project_name + element + ".mp4"),
|
|
||||||
image_folder: path.join(this.global.config.project_path, 'tmp/' + element),
|
|
||||||
srt_config: path.join(this.global.config.project_path, 'scripts/config.json'),
|
|
||||||
mp4_file_txt: path.join(this.global.config.project_path, `scripts/${element}.txt`),
|
|
||||||
status: "no",
|
|
||||||
audio_sound_size: video_config.audioSoundSize,
|
|
||||||
background_music_sound_size: video_config.backgroundMusicSoundSize,
|
|
||||||
keyFrame: video_config.keyframe,
|
|
||||||
frameRate: video_config.frameRate,
|
|
||||||
bitRate: video_config.bitRate
|
|
||||||
}
|
|
||||||
// 将配置文件写入
|
|
||||||
let project_config_path = path.join(this.global.config.project_path, `scripts/${element}.json`);
|
|
||||||
await fspromises.writeFile(project_config_path, JSON.stringify(obj));
|
|
||||||
// let task_list = JSON.parse(await fspromises.readFile(path.join(this.global.config.project_path,'scripts/task_')));
|
|
||||||
let scriptPath = path.join(define.scripts_path, 'Lai.exe');
|
|
||||||
// 执行生成图片的脚本
|
|
||||||
let script = `cd "${define.scripts_path}" && "${scriptPath}" -c "${project_config_path.replaceAll('\\', '/')}"`;
|
|
||||||
const output = await execAsync(script, { maxBuffer: 1024 * 1024 * 10, encoding: 'utf-8' });
|
|
||||||
if (output.stderr != '') {
|
|
||||||
obj.status = "video_error";
|
|
||||||
obj.stdout = output.stdout;
|
|
||||||
obj.stderr = output.stderr;
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', element, "video_error");
|
|
||||||
throw new Error(output.stderr);
|
|
||||||
} else {
|
|
||||||
obj.status = "video_ok";
|
|
||||||
obj.stdout = output.stdout;
|
|
||||||
obj.stderr = output.stderr;
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', element, "video_ok");
|
|
||||||
// 将写出的视频中的exif数据删除
|
|
||||||
// await this.tools.deletePngAndDeleteExifData(obj.outpue_file, path.join(this.global.config.project_path, this.global.config.project_name + "_" + element.split('_')[element.split('_').length - 1] + ".mp4"));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, {
|
|
||||||
out_folder: element,
|
|
||||||
status: obj.status
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
//手动修改
|
|
||||||
let task_list_json = JSON.parse(await fspromises.readFile(path.join(this.global.config.project_path, "scripts/task_list.json"), 'utf-8'));
|
|
||||||
let index = task_list_json.task_list.findIndex(item => item.out_folder == element);
|
|
||||||
if (index < 0) {
|
|
||||||
throw new Error("未找到对应的任务");
|
|
||||||
}
|
|
||||||
task_list_json.task_list[index].status = "video_error";
|
|
||||||
task_list_json.task_list[index].errorMessage = error.toString();
|
|
||||||
// 写回
|
|
||||||
await fspromises.writeFile(path.join(this.global.config.project_path, "scripts/task_list.json"), JSON.stringify(task_list_json));
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, {
|
|
||||||
out_folder: element,
|
|
||||||
status: "video_error"
|
|
||||||
})
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加自动合成任务到队列中去
|
|
||||||
* @param {} value
|
|
||||||
*/
|
|
||||||
async AutoGeneretionVideo(value) {
|
|
||||||
try {
|
|
||||||
// 先检查所有的条件
|
|
||||||
let batch = DEFINE_STRING.QUEUE_BATCH.AUTO_VIDEO_GENERATE_SINGLE;
|
|
||||||
// console.log(value);
|
|
||||||
let video_config = JSON.parse(await fspromises.readFile(define.video_config, 'utf-8'));
|
|
||||||
let res = await this.CheckVideoGenerattionAllCondition(video_config, value[1], value[0]);
|
|
||||||
if (res.code == 0) {
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
for (let i = 0; i < value[0].length; i++) {
|
|
||||||
const element = value[0][i];
|
|
||||||
this.global.requestQuene.enqueue(async () => {
|
|
||||||
await this.AutoGeneretionOneVide(element, video_config, value)
|
|
||||||
}, element, batch);
|
|
||||||
|
|
||||||
// 添加队列后修改状态
|
|
||||||
await this.pm.ModifyTaskStatus('out_folder', element, "video_queue");
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.VIDEO_GENERATE_STATUS_REFRESH, {
|
|
||||||
out_folder: element,
|
|
||||||
status: "video_queue"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.global.requestQuene.setBatchCompletionCallback(batch, (failedTasks) => {
|
|
||||||
if (failedTasks.length > 0) {
|
|
||||||
let message = `
|
|
||||||
生成视频任务都已完成。
|
|
||||||
但是以下任务执行失败:
|
|
||||||
`
|
|
||||||
failedTasks.forEach(({ taskId, error }) => {
|
|
||||||
message += `${taskId}-, \n 错误信息: ${error}` + '\n';
|
|
||||||
});
|
|
||||||
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 0,
|
|
||||||
message: message
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 1,
|
|
||||||
message: "所有生成视频任务已完成"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
code: 1
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检测生成视频条件的必要条件
|
|
||||||
* @param {生成视频配置文件} video_config
|
|
||||||
* @param {生成视频的基础配置} simpleData
|
|
||||||
* @param {输出文件夹位置,为null,检查input文件里面的图片文件是不是和配置文件中的图片数量一致} out_folder
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async CheckVideoGenerattionAllCondition(video_config, simpleData, out_folder) {
|
|
||||||
let message = "";
|
|
||||||
if (video_config == null) {
|
|
||||||
video_config = JSON.parse(await fspromises.readFile(define.video_config, 'utf-8'));
|
|
||||||
}
|
|
||||||
// 基础信息检测
|
|
||||||
if (video_config.audioSoundSize == null) {
|
|
||||||
message += "配音大小不能为空" + '\n';
|
|
||||||
}
|
|
||||||
if (video_config.backgroundMusicSoundSize == null) {
|
|
||||||
message += "背景音乐音量大学不能为空" + '\n';
|
|
||||||
}
|
|
||||||
if (video_config.video_resolution_x == null) {
|
|
||||||
message += "生成视频的宽度不能为空" + '\n';
|
|
||||||
}
|
|
||||||
if (video_config.video_resolution_y == null) {
|
|
||||||
message += "生成视频的高度不能为空" + '\r\n';
|
|
||||||
}
|
|
||||||
if (video_config.offsetValue == null) {
|
|
||||||
message += "视频的上下偏移量不能为空" + '\n';
|
|
||||||
}
|
|
||||||
if (video_config.frameRate == null) {
|
|
||||||
message += "生成视频的帧率不能为空" + '\n';
|
|
||||||
}
|
|
||||||
if (video_config.bitRate == null) {
|
|
||||||
message += "生成视频码率的不能为空" + '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断字幕列表中是不是有数据
|
|
||||||
if (video_config.assConfig == null || video_config.assConfig.length <= 0) {
|
|
||||||
message += "字幕设置最少包含一条" + '\n';
|
|
||||||
}
|
|
||||||
if (video_config.watermarkConfig == null || video_config.watermarkConfig.length <= 0) {
|
|
||||||
message += "水印设置最少包含一条" + '\n';
|
|
||||||
}
|
|
||||||
// 判断背景音乐文件夹中是不是存在。并且检查其中是不是有音乐文件
|
|
||||||
if (simpleData.background_music == "") {
|
|
||||||
message += "背景音乐文件夹路径不能为空" + '\n';
|
|
||||||
}
|
|
||||||
// 判断背景音乐文件夹是不是存在
|
|
||||||
if (await this.tools.checkExists(simpleData.background_music)) {
|
|
||||||
message += "背景音乐文件夹不存在" + '\n';
|
|
||||||
}
|
|
||||||
// 判断里面是不是有MP3或者是wav
|
|
||||||
let clip_json = JSON.parse(await fspromises.readFile(define.clip_setting, 'utf-8'))["background_music_setting"];
|
|
||||||
let background_music_obj = clip_json.filter(item => item.id == simpleData.background_music)[0];
|
|
||||||
let mp3_file = await this.tools.getFilesWithExtensions(background_music_obj.folder_path, '.mp3');
|
|
||||||
let wav_file = await this.tools.getFilesWithExtensions(background_music_obj.folder_path, '.wav');
|
|
||||||
if (mp3_file.length <= 0 && wav_file.length <= 0) {
|
|
||||||
message += "背景文件夹中没有 MP3 或 WAV 文件" + '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
let config_path = path.join(this.global.config.project_path, 'scripts/config.json');
|
|
||||||
let isE = await this.tools.checkExists(config_path);
|
|
||||||
if (!isE) {
|
|
||||||
message += "配置文件不存在。请先导入字幕文件。并调整时间轴。"
|
|
||||||
} else {
|
|
||||||
// 判断文案时间信息和图片信息是不是相同
|
|
||||||
let config_json = JSON.parse(await fspromises.readFile(config_path, 'utf-8'));
|
|
||||||
let len = config_json["srt_time_information"].length;
|
|
||||||
if (out_folder == null) {
|
|
||||||
// 判断输入文件中的配置文件中的数量是不是对上
|
|
||||||
let img_l = await this.tools.getFilesWithExtensions(path.join(this.global.config.project_path, "tmp/input_crop"), '.png');
|
|
||||||
if (img_l.length != len) {
|
|
||||||
message += `input_crop 文件里面图片和文案信息对不上。检查是不是图片数量不对`
|
|
||||||
}
|
|
||||||
// 判断是不是有tag文件
|
|
||||||
let tag_txt = await this.tools.getFilesWithExtensions(path.join(this.global.config.project_path, "tmp/input_crop"), '.txt');
|
|
||||||
let c_j = await this.tools.getFilesWithExtensions(path.join(this.global.config.project_path, "tmp/input_crop"), '.json');
|
|
||||||
if (tag_txt.length > 0) {
|
|
||||||
if (tag_txt.length != img_l.length) {
|
|
||||||
message += "反推的tag文件和图片的数量对不上。" + "\n";
|
|
||||||
}
|
|
||||||
} else if (c_j.length > 0) {
|
|
||||||
if (c_j.length != img_l.length) {
|
|
||||||
message += "已存在的配置文件和图片的数量对不上。" + "\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
message += "好像没有反推呢" + "\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 判断当前的输入的 out_folder 中图片数量是不是可以和配置文件中能否对上
|
|
||||||
for (let i = 0; i < out_folder.length; i++) {
|
|
||||||
const element = out_folder[i];
|
|
||||||
let image_l = await this.tools.getFilesWithExtensions(path.join(this.global.config.project_path, "tmp/" + element), '.png');
|
|
||||||
if (image_l.length != len) {
|
|
||||||
message += `${element} 文件里面图片和文案信息对不上。检查是不是图片数量不对`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (message != '') {
|
|
||||||
let res = {
|
|
||||||
code: 0,
|
|
||||||
message: message
|
|
||||||
}
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, res)
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,301 +0,0 @@
|
|||||||
let path = require("path");
|
|
||||||
let fspromises = require("fs").promises;
|
|
||||||
import { Tools } from "../tools";
|
|
||||||
import { DEFINE_STRING } from "../../define/define_string";
|
|
||||||
import { PublicMethod } from "../Public/publicMethod";
|
|
||||||
import { define } from "../../define/define";
|
|
||||||
import { get, has } from "lodash";
|
|
||||||
import { ClipSetting } from "../../define/setting/clipSetting";
|
|
||||||
const { v4: uuidv4 } = require('uuid'); // 引入UUID库来生成唯一标识符
|
|
||||||
let tools = new Tools();
|
|
||||||
|
|
||||||
export class Writing {
|
|
||||||
constructor(global) {
|
|
||||||
this.global = global
|
|
||||||
this.pm = new PublicMethod(global);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将文案信息写入到本地的文案文件中
|
|
||||||
* @param {*} value
|
|
||||||
*/
|
|
||||||
async SaveWordTxt(value) {
|
|
||||||
try {
|
|
||||||
let word_path = path.join(global.config.project_path, "文案.txt");
|
|
||||||
await tools.writeArrayToFile(value, word_path);
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
message: "保存成功"
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将分镜的时间信息添加道配置文件中
|
|
||||||
* @param {*} value 是一个数组,0 :写入的数据 1:写入的属性 2:是否需要解析
|
|
||||||
*/
|
|
||||||
async SaveCopywritingInformation(value) {
|
|
||||||
try {
|
|
||||||
return await this.pm.SaveConfigJsonProperty(value);
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取Config.json文件中指定的属性
|
|
||||||
* @param {Array} value 传入的值 0 : 需要获取的属性 1: 返回的默认值
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
async GetConfigJson(value) {
|
|
||||||
try {
|
|
||||||
return await this.pm.GetConfigJson(value, false);
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取当前项目下面的文案
|
|
||||||
*/
|
|
||||||
async GetProjectWord() {
|
|
||||||
try {
|
|
||||||
// 先判断当前的项目文件下面是不是又配置文件。没有才读取文案
|
|
||||||
let srt_config_path = path.join(global.config.project_path, "scripts/config.json");
|
|
||||||
let isExist = await tools.checkExists(srt_config_path);
|
|
||||||
let data = null;
|
|
||||||
let isImformation = false;
|
|
||||||
if (isExist) {
|
|
||||||
let config_1 = JSON.parse(await fspromises.readFile(srt_config_path));
|
|
||||||
isImformation = has(config_1, 'srt_time_information');
|
|
||||||
if (isImformation) {
|
|
||||||
data = JSON.parse(await fspromises.readFile(srt_config_path)).srt_time_information;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isExist || !isImformation) {
|
|
||||||
let word_path = path.join(global.config.project_path, "文案.txt");
|
|
||||||
let isExistWord = await tools.checkExists(word_path);
|
|
||||||
if (!isExistWord) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: "没有文案文件"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let data = await fspromises.readFile(word_path, { encoding: 'utf-8' });
|
|
||||||
let lines = data.split(/\r?\n/);
|
|
||||||
// 打印或返回这个数组
|
|
||||||
// console.log(lines);
|
|
||||||
// 判断是不是有洗稿后的文件
|
|
||||||
let new_srt_path = path.join(global.config.project_path, "new_word.txt");
|
|
||||||
let isExistAfterGPTWord = await tools.checkExists(new_srt_path);
|
|
||||||
let after_data = null;
|
|
||||||
if (isExistAfterGPTWord) {
|
|
||||||
after_data = (await fspromises.readFile(new_srt_path, { encoding: 'utf-8' })).split(/\r?\n/);
|
|
||||||
}
|
|
||||||
// 判断抽帧文件是不是存在
|
|
||||||
// 返回图片信息
|
|
||||||
let old_image_path_list = await tools.getFilesWithExtensions(path.join(global.config.project_path, "tmp/input_crop"), '.png');
|
|
||||||
let res = [];
|
|
||||||
let lastId = '';
|
|
||||||
// 处理数据
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
|
||||||
const line = lines[i];
|
|
||||||
let id = uuidv4();
|
|
||||||
let after_gpt = null;
|
|
||||||
if (after_data != null) {
|
|
||||||
after_gpt = after_data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
let img_path = null;
|
|
||||||
if (old_image_path_list != null) {
|
|
||||||
img_path = old_image_path_list[i];
|
|
||||||
}
|
|
||||||
let obj = {
|
|
||||||
no: i + 1,
|
|
||||||
id: id,
|
|
||||||
lastId: lastId,
|
|
||||||
word: line,
|
|
||||||
old_image: img_path,
|
|
||||||
after_gpt: after_gpt,
|
|
||||||
start_time: null,
|
|
||||||
end_time: null,
|
|
||||||
timeLimit: null,
|
|
||||||
subValue: []
|
|
||||||
}
|
|
||||||
res.push(obj);
|
|
||||||
lastId = id;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
type: 0,
|
|
||||||
data: res
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let data = JSON.parse(await fspromises.readFile(srt_config_path)).srt_time_information;
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
type: 1,
|
|
||||||
data: data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 搭导入srt。然后加载时间轴。完全匹配失败的将会还是会导入然后手动手动切换
|
|
||||||
* @param {文案洗稿界面信息} textData
|
|
||||||
*/
|
|
||||||
async ImportSrtAndGetTime(data) {
|
|
||||||
let textData = data[0];
|
|
||||||
let init_num = textData.length;
|
|
||||||
let srt_path = data[1];
|
|
||||||
let current_text = "";
|
|
||||||
try {
|
|
||||||
if (!srt_path) {
|
|
||||||
// 获取项目下面的所有的srt
|
|
||||||
let srtfiles = await tools.getFilesWithExtensions(global.config.project_path, '.srt');
|
|
||||||
if (srtfiles.length <= 0) {
|
|
||||||
throw new Error("没有SRT文件");
|
|
||||||
}
|
|
||||||
srt_path = srtfiles[0];
|
|
||||||
}
|
|
||||||
let srt_data = (await fspromises.readFile(srt_path, 'utf-8')).toString("utf-8");
|
|
||||||
const entries = srt_data.replace(/\r\n/g, '\n').split('\n\n');
|
|
||||||
let data = entries.map(entry => {
|
|
||||||
const lines = entry.split('\n');
|
|
||||||
if (lines.length >= 3) {
|
|
||||||
const times = lines[1];
|
|
||||||
const text = lines.slice(2).join(' ');
|
|
||||||
const [start, end] = times.split(' --> ').map(time => {
|
|
||||||
const [hours, minutes, seconds] = time.split(':');
|
|
||||||
const [sec, millis] = seconds.split(',');
|
|
||||||
return ((parseInt(hours) * 3600 + parseInt(minutes) * 60 + parseInt(sec)) * 1000 + parseInt(millis));
|
|
||||||
});
|
|
||||||
return { start, end, text, id: uuidv4() };
|
|
||||||
}
|
|
||||||
}).filter(entry => entry);
|
|
||||||
// 开始匹配(洗稿后的)
|
|
||||||
let srt_list = [];
|
|
||||||
let srt_obj = null
|
|
||||||
let text_count = 0;
|
|
||||||
let tmp_str = "";
|
|
||||||
for (let i = 0; i < data.length;) {
|
|
||||||
let srt_value = data[i].text;
|
|
||||||
current_text = `字幕: “${srt_value}” 和文案第${text_count + 1} 行数据 “${textData[text_count].after_gpt}” 数据不匹配(检查一下上下文)`;
|
|
||||||
let start_time = data[i].start;
|
|
||||||
let end_time = data[i].end;
|
|
||||||
let obj = {
|
|
||||||
start_time,
|
|
||||||
end_time,
|
|
||||||
srt_value,
|
|
||||||
id: data[i].id
|
|
||||||
};
|
|
||||||
// 判断当前字幕是不是在当前句
|
|
||||||
// 不能用简单的包含,而是将数据进行去除特殊符号拼接后判断是不是相同
|
|
||||||
tmp_str += srt_value;
|
|
||||||
if (tools.removePunctuationIncludingEllipsis(textData[text_count].after_gpt).startsWith(tools.removePunctuationIncludingEllipsis(tmp_str))) {
|
|
||||||
if (srt_obj == null) {
|
|
||||||
srt_obj = {}
|
|
||||||
srt_obj.id = uuidv4();
|
|
||||||
srt_obj.start_time = start_time;
|
|
||||||
srt_obj.value = srt_value;
|
|
||||||
srt_obj.subValue = [obj];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
srt_obj.value = srt_obj.value + srt_value;
|
|
||||||
srt_obj.subValue = [...srt_obj.subValue, obj];
|
|
||||||
}
|
|
||||||
textData[text_count].start_time = srt_obj.start_time;
|
|
||||||
textData[text_count].subValue = srt_obj.subValue
|
|
||||||
srt_list.push(obj);
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
// 判断下一句文件是不是以当当前巨开头。是的话继续。不是的话。直接返回后面的所有信息
|
|
||||||
if (tools.removePunctuationIncludingEllipsis(textData[text_count + 1].after_gpt).startsWith(tools.removePunctuationIncludingEllipsis(srt_value))) {
|
|
||||||
textData[text_count].end_time = srt_list[srt_list.length - 1].end_time;
|
|
||||||
text_count++;
|
|
||||||
srt_obj = null;
|
|
||||||
tmp_str = ""
|
|
||||||
} else {
|
|
||||||
// 将下面的数据直接 添加到textData后面。
|
|
||||||
// 修改当前行数据的结束事件为
|
|
||||||
if (srt_list.length > 0) {
|
|
||||||
textData[text_count].end_time = srt_list[srt_list.length - 1].end_time;
|
|
||||||
text_count++;
|
|
||||||
}
|
|
||||||
// 将后面的数据直接添加
|
|
||||||
let lastId = textData[textData.length - 1].id;
|
|
||||||
for (let j = i; j < data.length; j++) {
|
|
||||||
// 直接修改原有数据
|
|
||||||
if (text_count < init_num) {
|
|
||||||
textData[text_count].subValue = [{
|
|
||||||
start_time: data[j].start,
|
|
||||||
end_time: data[j].end,
|
|
||||||
id: data[j].id,
|
|
||||||
srt_value: data[j].text
|
|
||||||
}]
|
|
||||||
textData[text_count].start_time = data[j].start;
|
|
||||||
textData[text_count].end_time = data[j].end;
|
|
||||||
text_count++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let id = uuidv4();
|
|
||||||
// 添加
|
|
||||||
let obj = {
|
|
||||||
no: j + 1,
|
|
||||||
id: id,
|
|
||||||
word: null,
|
|
||||||
lastId: lastId,
|
|
||||||
old_image: path.normalize(define.zhanwei_image),
|
|
||||||
after_gpt: null,
|
|
||||||
start_time: data[j].start,
|
|
||||||
end_time: data[j].end,
|
|
||||||
subValue: [{
|
|
||||||
start_time: data[j].start,
|
|
||||||
end_time: data[j].end,
|
|
||||||
id: data[j].id,
|
|
||||||
srt_value: data[j].text
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
lastId = id;
|
|
||||||
textData.push(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.global.newWindow[0].win.webContents.send(DEFINE_STRING.SHOW_MESSAGE_DIALOG, {
|
|
||||||
code: 0,
|
|
||||||
message: current_text
|
|
||||||
})
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
data: textData
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 最后对齐
|
|
||||||
textData[textData.length - 1].end_time = srt_list[srt_list.length - 1].end_time
|
|
||||||
// 返回数据
|
|
||||||
return {
|
|
||||||
code: 1,
|
|
||||||
data: textData
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
message: error.toString()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,490 +0,0 @@
|
|||||||
const axios = require('axios');
|
|
||||||
// import { Midjourney as mApi} from "midjourney";
|
|
||||||
// const MJapi2 = require('midjourney');
|
|
||||||
// const { midjourney } = require('midjourney')
|
|
||||||
// const Midjourney = require('midjourney');
|
|
||||||
// ES5 的模块引入方式
|
|
||||||
const fetch = require("node-fetch");
|
|
||||||
|
|
||||||
// ES6 的模块引入方式
|
|
||||||
// import fetch from "node-fetch";
|
|
||||||
|
|
||||||
export class DiscordAPI {
|
|
||||||
constructor(mj_setting) {
|
|
||||||
// https://discord.com/api/v9/channels/1208362852482809939/messages?limit=20
|
|
||||||
this.apiClient = axios.create({
|
|
||||||
baseURL: 'https://discord.com'
|
|
||||||
});
|
|
||||||
this.DiscordBaseUrl = 'https://discord.com';
|
|
||||||
this.ServerId = mj_setting.serviceID;
|
|
||||||
this.ChannelId = mj_setting.channelID;
|
|
||||||
this.userToken = mj_setting.token;
|
|
||||||
this.botId = mj_setting.select_robot?.botId;
|
|
||||||
this.commandId = mj_setting.select_robot?.commandId;
|
|
||||||
this.versionId = mj_setting.select_robot?.versionId;
|
|
||||||
this.versionName = mj_setting.select_robot?.versionName;
|
|
||||||
this.botName = mj_setting.select_robot?.botName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 提交任务
|
|
||||||
async imagine(data) {
|
|
||||||
|
|
||||||
// let req_data = {
|
|
||||||
// "token": this.userToken,
|
|
||||||
// "method": "post",
|
|
||||||
// "api_url": "/mj/submit/imagine",
|
|
||||||
// "data":data
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
// await this.interactions(data.prompt);
|
|
||||||
return await this.interactions(data.prompt)
|
|
||||||
// return {
|
|
||||||
// code:1,
|
|
||||||
// result:'taskid_'+new Date().getTime()
|
|
||||||
// }
|
|
||||||
// return response.data;
|
|
||||||
|
|
||||||
}
|
|
||||||
async channelList() {
|
|
||||||
axios.get(`https://discord.com/api/v9/channels/${this.ChannelId}/messages?limit=20`, {
|
|
||||||
method: 'get',
|
|
||||||
headers: {
|
|
||||||
"Authorization": this.userToken
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
// 请求成功处理
|
|
||||||
console.log(typeof response.data);
|
|
||||||
let eList = []
|
|
||||||
let flg = false;
|
|
||||||
let job_id = '';
|
|
||||||
let type = '';
|
|
||||||
if (response && response.data) {
|
|
||||||
try {
|
|
||||||
response.data.forEach(element => {
|
|
||||||
flg = false;
|
|
||||||
type = '';
|
|
||||||
if (element.attachments && element.attachments.length) {
|
|
||||||
const arr = element.attachments[0].filename.split("_");
|
|
||||||
job_id = arr[arr.length - 1].replace(".png", '');
|
|
||||||
if (element.components) {
|
|
||||||
element.components.forEach(e2 => {
|
|
||||||
e2.components.forEach(e3 => {
|
|
||||||
if (e3.label == 'U1') {
|
|
||||||
flg = true;
|
|
||||||
type = 'U1'
|
|
||||||
} else if (e3.label && e3.label.indexOf('Upscale') > -1) {
|
|
||||||
flg = true;
|
|
||||||
type = 'Upscale'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
let t = eList.find((e) => {
|
|
||||||
return e.filename == element.attachments[0].filename;
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!t) {
|
|
||||||
eList.push(
|
|
||||||
{
|
|
||||||
flg: flg, job_id: job_id, filename: element.attachments[0].filename,
|
|
||||||
url: element.attachments[0].url,
|
|
||||||
proxy_url: element.attachments[0].proxy_url,
|
|
||||||
type: type,
|
|
||||||
timestamp: element.timestamp
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// console.log({flg:flg,job_id:job_id,filename:element.attachments[0].filename})
|
|
||||||
} else {
|
|
||||||
console.log({ flg: flg })
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.log('异常2', error)
|
|
||||||
}
|
|
||||||
// console.log(eList)
|
|
||||||
// 8e7406df-bf0c-4e3d-8e49-b2bb8e2c263d
|
|
||||||
// 5abedc71-ba80-4756-8ddc-489c927d3acd
|
|
||||||
}
|
|
||||||
}).catch(error => {
|
|
||||||
// 请求失败处理
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// 混合
|
|
||||||
async blend(data) {
|
|
||||||
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "post",
|
|
||||||
"api_url": "/mj/submit/blend",
|
|
||||||
"data": data
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 反推
|
|
||||||
async describe(data) {
|
|
||||||
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "post",
|
|
||||||
"api_url": "/mj/submit/describe",
|
|
||||||
"data": data
|
|
||||||
}
|
|
||||||
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取任务
|
|
||||||
async getTaskId(task_id) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "get",
|
|
||||||
"api_url": `/mj/task/${task_id}/fetch`,
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//获取seed
|
|
||||||
async imageSeed(task_id) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "get",
|
|
||||||
"api_url": `/mj/task/${task_id}/image-seed`,
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//账号创建
|
|
||||||
async account_create(data) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "post",
|
|
||||||
"api_url": '/mj/account/create',
|
|
||||||
"data": data
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data, { timeout: 20000 });
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//账号创建
|
|
||||||
async account_fetch(cid) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "get",
|
|
||||||
"api_url": `/mj/account/${cid}/fetch`,
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//账号同步信息
|
|
||||||
async account_asyn_info(cid) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "post",
|
|
||||||
"api_url": `/mj/account/${cid}/sync-info`,
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data, { timeout: 20000 });
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
//账号删除信息
|
|
||||||
async account_del_info(cid) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "delete",
|
|
||||||
"api_url": `/mj/account/${cid}/delete`,
|
|
||||||
"data": {}
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//执行动作
|
|
||||||
async action(data) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "post",
|
|
||||||
"api_url": '/mj/submit/action',
|
|
||||||
"data": data
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确认弹窗
|
|
||||||
async modal(data) {
|
|
||||||
let req_data = {
|
|
||||||
"token": this.userToken,
|
|
||||||
"method": "post",
|
|
||||||
"api_url": '/mj/submit/modal',
|
|
||||||
"data": data
|
|
||||||
}
|
|
||||||
const response = await this.apiClient.post('/api/v3/req_mj_api', req_data);
|
|
||||||
return response.data;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async interactions(prompt) {
|
|
||||||
// 直接自己调用
|
|
||||||
prompt = prompt.trim();
|
|
||||||
// prompt = "4k,8k,best quality, masterpiece, woman, divorced, leaving fast-paced city life, serene expression, walking away from cityscape, bustling streets, entering tranquil countryside, peaceful surroundings, rejuvenating atmosphere, , --niji 5 --ar 4:3"
|
|
||||||
var payload = {};
|
|
||||||
if (this.botName == 'niji') {
|
|
||||||
payload = {
|
|
||||||
"type": 2,
|
|
||||||
"application_id": this.botId,
|
|
||||||
"guild_id": this.ServerId,
|
|
||||||
"channel_id": this.ChannelId,
|
|
||||||
"session_id": this.userToken,
|
|
||||||
"data": {
|
|
||||||
"version": this.versionId,
|
|
||||||
"id": this.commandId,
|
|
||||||
"name": "imagine",
|
|
||||||
"type": 1,
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"type": 3,
|
|
||||||
"name": "prompt",
|
|
||||||
"value": prompt
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"application_command": {
|
|
||||||
"id": this.commandId,
|
|
||||||
"type": 1,
|
|
||||||
"application_id": this.botId,
|
|
||||||
"version": this.versionId,
|
|
||||||
"name": "imagine",
|
|
||||||
"description": "Create images with Midjourney",
|
|
||||||
"options": [
|
|
||||||
{
|
|
||||||
"type": 3,
|
|
||||||
"name": "prompt",
|
|
||||||
"description": "The prompt to imagine",
|
|
||||||
"required": true,
|
|
||||||
"description_localized": "The prompt to imagine",
|
|
||||||
"name_localized": "prompt"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"integration_types": [
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"global_popularity_rank": 1,
|
|
||||||
"description_localized": "Create images with Midjourney",
|
|
||||||
"name_localized": "imagine"
|
|
||||||
},
|
|
||||||
"attachments": [
|
|
||||||
|
|
||||||
]
|
|
||||||
},
|
|
||||||
// "nonce": "1210857131343872000",
|
|
||||||
"analytics_location": "slash_ui"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
payload = {
|
|
||||||
"type": 2,
|
|
||||||
// "application_id":"1022952195194359889",//niji
|
|
||||||
"application_id": this.botId,
|
|
||||||
"guild_id": this.ServerId,
|
|
||||||
"channel_id": this.ChannelId,
|
|
||||||
"session_id": this.userToken,
|
|
||||||
"data": {
|
|
||||||
"version": this.versionId,
|
|
||||||
"id": this.commandId,
|
|
||||||
"name": "imagine", "type": 1,
|
|
||||||
"options":
|
|
||||||
[{
|
|
||||||
"type": 3,
|
|
||||||
"name": "prompt",
|
|
||||||
"value": prompt
|
|
||||||
}],
|
|
||||||
"application_command": {
|
|
||||||
"id": this.commandId,
|
|
||||||
"type": 1,
|
|
||||||
"application_id": this.botId,
|
|
||||||
"version": this.versionId,
|
|
||||||
"name": "imagine",
|
|
||||||
"description": "Create images with Niji journey",
|
|
||||||
"options": [{ "type": 3, "name": "prompt", "description": "The prompt to imagine", "required": true, "description_localized": "The prompt to imagine", "name_localized": "prompt" }],
|
|
||||||
"integration_types": [0], "global_popularity_rank": 1, "description_localized": "Create images with Niji journey", "name_localized": "imagine"
|
|
||||||
},
|
|
||||||
"attachments": []
|
|
||||||
},
|
|
||||||
"analytics_location": "slash_ui"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let response = {
|
|
||||||
status: 200,
|
|
||||||
data: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: this.userToken,
|
|
||||||
};
|
|
||||||
await fetch(`${this.DiscordBaseUrl}/api/v9/interactions`, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
headers: headers,
|
|
||||||
}).then(res => res.json()).then(res => {
|
|
||||||
response.data = res;
|
|
||||||
}).catch(e => {
|
|
||||||
console.error("请求失败了,详细信息:" + JSON.stringify(e));
|
|
||||||
response = {
|
|
||||||
status: 500,
|
|
||||||
data: JSON.stringify(e)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
console.log('response结果')
|
|
||||||
console.log(response)
|
|
||||||
// if (response.status == 204) {
|
|
||||||
// //成功
|
|
||||||
|
|
||||||
// }
|
|
||||||
if (response.status >= 400) {
|
|
||||||
console.error("api.error.config", {
|
|
||||||
payload: JSON.stringify(payload)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
code: response.status,
|
|
||||||
response: response
|
|
||||||
};
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
return 500;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
const client = new Midjourney.Midjourney({
|
|
||||||
ServerId: this.ServerId,
|
|
||||||
ChannelId: this.ChannelId,
|
|
||||||
SalaiToken: this.userToken,
|
|
||||||
Debug: true,
|
|
||||||
fetch: fetch,
|
|
||||||
Ws: true, //enable ws is required for remix mode (and custom zoom)
|
|
||||||
});
|
|
||||||
await client.init();
|
|
||||||
console.log('mjmj_begin2', prompt);
|
|
||||||
// const prompt =
|
|
||||||
// "Christmas dinner with spaghetti with family in a cozy house, we see interior details , simple blue&white illustration";
|
|
||||||
//imagine
|
|
||||||
const Imagine = await client.Imagine(
|
|
||||||
prompt,
|
|
||||||
(uri, progress) => {
|
|
||||||
client.Close();
|
|
||||||
|
|
||||||
console.log("loading", uri, "progress", progress);
|
|
||||||
return
|
|
||||||
}
|
|
||||||
);
|
|
||||||
console.log(Imagine);
|
|
||||||
if (!Imagine) {
|
|
||||||
console.log("no message");
|
|
||||||
console.log('mjmj_end2')
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('mjmj_end')
|
|
||||||
client.Close();
|
|
||||||
return
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取频道内的机器人
|
|
||||||
* @returns 返回机器人列表
|
|
||||||
*/
|
|
||||||
async getBotList() {
|
|
||||||
try {
|
|
||||||
|
|
||||||
const headers = {
|
|
||||||
'Host': 'discord.com',
|
|
||||||
'Connection': 'keep-alive',
|
|
||||||
'authorization': this.userToken,
|
|
||||||
}
|
|
||||||
|
|
||||||
await fetch('https://discord.com/api/v9/guilds/1182523906855284826/application-command-index', {
|
|
||||||
method: 'GET',
|
|
||||||
headers: headers,
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
response.json()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then(data => {
|
|
||||||
console.log(data)
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error:', error)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async getMjMsgList() {
|
|
||||||
// const headers = {
|
|
||||||
// "Content-Type": "application/json",
|
|
||||||
// Authorization:this.userToken,
|
|
||||||
// };
|
|
||||||
let response = {
|
|
||||||
status: 200,
|
|
||||||
data: {}
|
|
||||||
};
|
|
||||||
// // `https://discord.com/api/v9/channels/${mj_channelId}/messages?limit=10
|
|
||||||
// await fetch(`${this.DiscordBaseUrl}/api/v9/channels/${this.ChannelId}/messages?limit=50`, {
|
|
||||||
// method: "GET",
|
|
||||||
// headers: headers,
|
|
||||||
// }).then(res => res.json()).then(res => {
|
|
||||||
// response.data=res;
|
|
||||||
// }).catch(e => {
|
|
||||||
// console.error("请求失败了,详细信息:" + JSON.stringify(e));
|
|
||||||
// response ={
|
|
||||||
// status:500,
|
|
||||||
// data:JSON.stringify(e)
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
// console.log('getMjMsgList_response结果')
|
|
||||||
// // console.log(response)
|
|
||||||
|
|
||||||
// return response;
|
|
||||||
axios.get(`https://discord.com/api/v9/channels/${this.ChannelId}/messages?limit=20`, {
|
|
||||||
method: 'get',
|
|
||||||
headers: {
|
|
||||||
"Authorization": this.userToken
|
|
||||||
}
|
|
||||||
}).then(res => {
|
|
||||||
response.data = res;
|
|
||||||
}).catch(error => {
|
|
||||||
// 请求失败处理
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import { contextBridge, ipcRenderer } from 'electron'
|
|
||||||
import { DEFINE_STRING } from '../define/define_string.js';
|
|
||||||
// Custom APIs for renderer
|
|
||||||
|
|
||||||
let events = [];
|
|
||||||
const api = {
|
|
||||||
// 创建MJ消息
|
|
||||||
CreateMessage: (value) => ipcRenderer.send(DEFINE_STRING.DISCORD.CREATE_MESSAGE, value),
|
|
||||||
|
|
||||||
// MJ消息更新
|
|
||||||
UpdateMessage: (value) => ipcRenderer.send(DEFINE_STRING.DISCORD.UPDATE_MESSAGE, value),
|
|
||||||
|
|
||||||
// MJ消息删除
|
|
||||||
DeleteMessage: (value) => ipcRenderer.send(DEFINE_STRING.DISCORD.DELETE_MESSAGE, value),
|
|
||||||
}
|
|
||||||
// Use `contextBridge` APIs to expose Electron APIs to
|
|
||||||
// renderer only if context isolation is enabled, otherwise
|
|
||||||
// just add to the DOM global.
|
|
||||||
if (process.contextIsolated) {
|
|
||||||
try {
|
|
||||||
contextBridge.exposeInMainWorld('api', api)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
window.api = api
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user