2024-05-15 12:57:15 +08:00
|
|
|
|
const fspromises = require("fs").promises;
|
|
|
|
|
|
import path from "path";
|
|
|
|
|
|
import axios from "axios";
|
|
|
|
|
|
const { JSDOM } = require('jsdom');
|
|
|
|
|
|
import { define } from "../../define/define";
|
|
|
|
|
|
import { Tools } from "../tools";
|
|
|
|
|
|
import { ClipSetting } from "../../define/setting/clipSetting";
|
|
|
|
|
|
import { ImageSetting } from "../../define/setting/imageSetting";
|
|
|
|
|
|
import { DEFINE_STRING } from "../../define/define_string";
|
|
|
|
|
|
import { TagDefine } from "../../define/tagDefine";
|
|
|
|
|
|
|
|
|
|
|
|
let tagDefine = new TagDefine(global);
|
|
|
|
|
|
export class Setting {
|
|
|
|
|
|
constructor(global) {
|
|
|
|
|
|
this.global = global;
|
|
|
|
|
|
this.tools = new Tools();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#region 剪映设置
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 添加背景音乐文件夹设置
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
*/
|
|
|
|
|
|
async AddBackgroundMusicFolder(value) {
|
|
|
|
|
|
return await ClipSetting.AddBackgroundMusicFolder(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取剪映背景音乐配置列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetBackGroundMusicConfigList() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let res = await this.tools.getJsonFilePropertyValue(define.clip_setting, "background_music_setting", []);
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
value: res
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 0,
|
|
|
|
|
|
error: error.toString()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除剪辑配置里面对应ID的数据
|
|
|
|
|
|
* @param {要删除的样式ID} value
|
|
|
|
|
|
*/
|
|
|
|
|
|
async deleteClipSetting(property, value) {
|
|
|
|
|
|
return ClipSetting.deleteClipSetting(property, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取剪映的关键帧配置
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetKeyFrameConfigData() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let key_frame = await this.tools.getJsonFilePropertyValue(define.clip_setting, "key_frame", null, false);
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
data: key_frame
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 0,
|
|
|
|
|
|
message: error.toString()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取剪映关键帧配置
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetKeyFrameOptions() {
|
|
|
|
|
|
return await ClipSetting.GetKeyFrameOptions();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async SaveKeyFrameSetting(value) {
|
|
|
|
|
|
return await ClipSetting.SaveKeyFrameSetting(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#region 图片设置
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取自动保存图片的存储文件的方式
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetAutoSaveImageClassifyOptions() {
|
|
|
|
|
|
return await ImageSetting.GetAutoSaveImageClassifyOptions();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存自动保存图片的设置
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async SaveImageAutoSaveSetting(value) {
|
|
|
|
|
|
return await ImageSetting.SaveImageAutoSaveSetting(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取自动保存图片的设置
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetImageAutoSaveSetting(value) {
|
|
|
|
|
|
return await ImageSetting.GetImageAutoSaveSetting(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 手动另存文件夹
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async SaveImageToOtherFolder(value) {
|
|
|
|
|
|
return await ImageSetting.SaveImageToOtherFolder([], value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 移除任务
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
*/
|
|
|
|
|
|
async RemoveTask(value) {
|
|
|
|
|
|
if (value[0] == DEFINE_STRING.QUEUE_BATCH.IMAGE_SAVE_TO_OTHER_FOLDER) {
|
|
|
|
|
|
this.global.fileQueue.removeTask(value[0], value[1], value[2])
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.global.requestQuene.removeTask(value[0], value[1], value[2])
|
|
|
|
|
|
if (this.global.mjGenerateQuene) {
|
|
|
|
|
|
this.global.mjGenerateQuene.removeTask(value[0], value[1], value[2])
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 加载SD配置文件
|
|
|
|
|
|
*/
|
|
|
|
|
|
async InitSDConfig() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let sd_config = JSON.parse(await fspromises.readFile(define.sd_setting, 'utf-8'));
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
data: {
|
|
|
|
|
|
webui_api_url: sd_config.setting.webui_api_url,
|
|
|
|
|
|
type: sd_config.setting.type,
|
|
|
|
|
|
sampler_name: sd_config.webui.sampler_name,
|
|
|
|
|
|
prompt: sd_config.webui.prompt,
|
|
|
|
|
|
negative_prompt: sd_config.webui.negative_prompt,
|
|
|
|
|
|
denoising_strength: sd_config.webui.denoising_strength,
|
|
|
|
|
|
steps: sd_config.webui.steps,
|
|
|
|
|
|
width: sd_config.webui.width,
|
|
|
|
|
|
height: sd_config.webui.height,
|
|
|
|
|
|
adetailer: sd_config.webui.adetailer,
|
|
|
|
|
|
batch_size: sd_config.setting.batch_size,
|
|
|
|
|
|
seed: sd_config.setting.seed,
|
|
|
|
|
|
style_weight: sd_config.setting.style_weight,
|
|
|
|
|
|
cfg_scale: sd_config.webui.cfg_scale,
|
2024-05-24 13:46:19 +08:00
|
|
|
|
sd_model: sd_config.sd_model,
|
|
|
|
|
|
lora: sd_config.lora,
|
|
|
|
|
|
sampler: sd_config.sampler,
|
2024-05-15 12:57:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 0,
|
|
|
|
|
|
message: error
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取主页显示的信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetShowMessage() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let res = await axios.get('https://share.weiyun.com/1EPtoGg8');
|
|
|
|
|
|
const dom = new JSDOM(res.data, {
|
|
|
|
|
|
runScripts: "dangerously",
|
|
|
|
|
|
resources: "usable",
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个函数来异步获取syncData
|
|
|
|
|
|
async function getSyncData() {
|
|
|
|
|
|
// 创建一个Promise来等待onload事件
|
|
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
|
|
dom.window.onload = () => {
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 设置一个超时,以防onload事件永远不触发
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
reject(new Error('Loading timed out'));
|
|
|
|
|
|
}, 5000); // 10秒超时
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 返回syncData对象
|
|
|
|
|
|
return dom.window.syncData;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 使用异步函数并处理结果
|
|
|
|
|
|
let re = await getSyncData();
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
data: re
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 0,
|
|
|
|
|
|
message: error.toString()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 初始化配置
|
|
|
|
|
|
*/
|
|
|
|
|
|
async getSettingDafultData() {
|
|
|
|
|
|
// 加载通用配置
|
|
|
|
|
|
let data = await fspromises.readFile(define.config_path, "utf-8");
|
|
|
|
|
|
let sd_data = await fspromises.readFile(define.sd_setting, 'utf-8');
|
|
|
|
|
|
let config_json_date = JSON.parse(data);
|
|
|
|
|
|
config_json_date.webui_api_url = JSON.parse(sd_data).setting.webui_api_url;
|
2024-05-24 13:46:19 +08:00
|
|
|
|
config_json_date["space_image"] = define.zhanwei_image;
|
2024-05-15 12:57:15 +08:00
|
|
|
|
return config_json_date;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 修改配置文件中的剪映的草稿位置
|
|
|
|
|
|
* @param {剪映的草稿位置} value
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async ModifySampleSetting(value) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
value = JSON.parse(value);
|
|
|
|
|
|
// 当前的配置文件的内容就是global.config的内容
|
|
|
|
|
|
// 直接修改 global.config的内容即可
|
|
|
|
|
|
// 传入的value是一个对象,需要遍历其中的所有属性,并将属性值进行修改
|
|
|
|
|
|
for (let key in value) {
|
|
|
|
|
|
this.global.config[key] = value[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
await fspromises.writeFile(define.config_path, JSON.stringify(this.global.config));
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
message: "保存成功"
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
cdoe: "0",
|
|
|
|
|
|
message: "保存失败,错误信息如下:" + '\n' + error.toString()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 检查机器码是不是存在
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async CheckMachineId(value) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 判断机器码是不是存在
|
|
|
|
|
|
let res = await axios.post('http://api.yu-zhile.com/GetMachineStatus', {
|
|
|
|
|
|
machineId: value
|
|
|
|
|
|
})
|
|
|
|
|
|
if (res.status != 200) {
|
|
|
|
|
|
throw new Error("请求错误");
|
|
|
|
|
|
}
|
|
|
|
|
|
if (res.data.code == 0) {
|
|
|
|
|
|
throw new Error(res.data.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.global.endTime = res.data.endTime;
|
|
|
|
|
|
this.global.permissions = res.data.permissions;
|
|
|
|
|
|
this.global.CheckMachineId = true;
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 1,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
return {
|
|
|
|
|
|
code: 0,
|
|
|
|
|
|
message: error.toString()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取选择角色场景模式的options
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetRoleSceneModeOptions() {
|
|
|
|
|
|
return tagDefine.getTagSelectModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取生图的类别(sd,mj,d3)
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetImageGenerateCategory() {
|
|
|
|
|
|
return ImageSetting.GetImageGenerateCategory();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//#region SD设置
|
|
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
//#region MJ设置
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取指定的配置文件里面指定的属性的数据
|
|
|
|
|
|
* @param {*} value
|
|
|
|
|
|
*/
|
|
|
|
|
|
async GetDefineConfigJsonByProperty(value) {
|
|
|
|
|
|
return ImageSetting.GetDefineConfigJsonByProperty(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存指定的配置文件里面指定的属性的数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
async SaveDefineConfigJsonByProperty(value) {
|
|
|
|
|
|
return ImageSetting.SaveDefineConfigJsonByProperty(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
|
}
|