diff --git a/package-lock.json b/package-lock.json index b190bbd..e21e793 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "laitool", - "version": "3.3.3", + "version": "3.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "laitool", - "version": "3.3.3", + "version": "3.3.4", "hasInstallScript": true, "dependencies": { "@alicloud/alimt20181012": "^1.2.0", @@ -11210,4 +11210,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 6e7bf68..0a5f883 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "laitool", - "version": "3.3.3", + "version": "3.3.4", "description": "An AI tool for image processing, video processing, and other functions.", "main": "./out/main/index.js", "author": "laitool.cn", diff --git a/resources/scripts/db/book.realm.lock b/resources/scripts/db/book.realm.lock index 95d5edb..5f703ed 100644 Binary files a/resources/scripts/db/book.realm.lock and b/resources/scripts/db/book.realm.lock differ diff --git a/resources/scripts/db/software.realm.lock b/resources/scripts/db/software.realm.lock index 5f0c50c..3f8b4e1 100644 Binary files a/resources/scripts/db/software.realm.lock and b/resources/scripts/db/software.realm.lock differ diff --git a/src/define/api/apiUrlDefine.ts b/src/define/api/apiUrlDefine.ts index 895a7ce..4c5d32d 100644 --- a/src/define/api/apiUrlDefine.ts +++ b/src/define/api/apiUrlDefine.ts @@ -3,6 +3,7 @@ let apiUrl = [ label: 'LAI API - 香港', value: 'b44c6f24-59e4-4a71-b2c7-3df0c4e35e65', gpt_url: 'https://api.laitool.cc/v1/chat/completions', + isPackage: false, mj_url: { imagine: 'https://api.laitool.cc/mj/submit/imagine', describe: 'https://api.laitool.cc/mj/submit/describe', @@ -18,6 +19,7 @@ let apiUrl = [ label: 'LAI API - 美国', value: '2b443f53-ba12-42b3-a57c-e4df92685c73', gpt_url: 'https://laitool.net/v1/chat/completions', + isPackage: false, mj_url: { imagine: 'https://laitool.net/mj/submit/imagine', describe: 'https://laitool.net/mj/submit/describe', @@ -58,7 +60,20 @@ let apiUrl = [ mj_url: null, d3_url: null, buy_url: 'https://www.volcengine.com/product/doubao' - } + }, + { + label: 'MJ生图包-1', + value: 'babe557a-bbb8-4aed-acca-70ea068c156f', + isPackage: true, + mj_url: { + imagine: 'https://mjapi.bzu.cn/mj/submit/imagine', + describe: 'https://mjapi.bzu.cn/mj/submit/describe', + update_file: 'https://mjapi.bzu.cn/mj/submit/upload-discord-images', + once_get_task: 'https://mjapi.bzu.cn/mj/task/${id}/fetch', + query_url: "https://mjapi.bzu.cn/" + }, + buy_url: 'https://rvgyir5wk1c.feishu.cn/wiki/P94OwwHuCi2qh8kADutcUuw4nUe' + }, ] /** @@ -71,4 +86,19 @@ function getApiMessageByID(id) { throw new Error('没有找到对应的MJ API的配置,请先检查配置') } } -export { apiUrl, getApiMessageByID } + +/** + * 获取MJ API 可用的URL Options + * @returns + */ +function GetMJUrlOptions(type: string) { + if (type != 'api' && type != 'package') { + throw new Error('没有找到对应的MJ API的配置,请先检查配置') + } + if (type == 'api') { + return apiUrl.filter((item) => item.mj_url && item.isPackage == false) + } else if (type == 'package') { + return apiUrl.filter((item) => item.mj_url && item.isPackage == true) + } +} +export { apiUrl, getApiMessageByID, GetMJUrlOptions } diff --git a/src/define/data/settingData.ts b/src/define/data/settingData.ts new file mode 100644 index 0000000..5fe7804 --- /dev/null +++ b/src/define/data/settingData.ts @@ -0,0 +1,33 @@ +/** + * 生图包图片代理方式 + */ +export let ImagePackageProxyOptions = [ + { + label: "香港代理", + value: "https://hk.bzu.cn", + apiId: "babe557a-bbb8-4aed-acca-70ea068c156f" + } + , { + label: "美国代理", + value: "https://mj_jp.bzu.cn", + apiId: "babe557a-bbb8-4aed-acca-70ea068c156f" + }, + { + label: "LaiTool默认代理", + value: "https://mj_us.bzu.cn", + } + +] + +export function GetImageProxyUrlOptions(apiId?: string) { + debugger + if (!apiId) { + return ImagePackageProxyOptions + } + let imageProxyUrl = ImagePackageProxyOptions.filter((item) => item.apiId == apiId || item.apiId == null) + if (imageProxyUrl) { + return imageProxyUrl + } else { + return [] + } +} \ No newline at end of file diff --git a/src/define/enum/mjEnum.ts b/src/define/enum/mjEnum.ts index 1351593..0c73f0f 100644 --- a/src/define/enum/mjEnum.ts +++ b/src/define/enum/mjEnum.ts @@ -8,6 +8,9 @@ export enum MJImageType { // 浏览器模式 BROWSER_MJ = 'browser_mj', + // MJ生图包 + PACKAGE_MJ = 'package_mj', + // API模式 API_MJ = 'api_mj', diff --git a/src/main/Service/MJ/mj.ts b/src/main/Service/MJ/mj.ts index dd9028b..ceae5d1 100644 --- a/src/main/Service/MJ/mj.ts +++ b/src/main/Service/MJ/mj.ts @@ -8,7 +8,7 @@ import MJApi from "./mjApi" import { BookBackTaskStatus, BookBackTaskType, BookTaskStatus, BookType, DialogType, MJAction, OperateBookType, TaskExecuteType } from "../../../define/enum/bookEnum"; import { DEFINE_STRING } from "../../../define/define_string"; import { MJ } from "../../../model/mj"; -import { MJRespoonseType } from "../../../define/enum/mjEnum"; +import { MJImageType, MJRespoonseType } from "../../../define/enum/mjEnum"; import { MJSettingModel } from "../../../model/Setting/mjSetting"; import { GeneralResponse } from "../../../model/generalResponse" import { LoggerStatus, ResponseMessageType } from "../../../define/enum/softwareEnum"; @@ -610,6 +610,13 @@ export class MJOpt { }); // 下载图片 let imagePath = path.join(book.bookFolderPath, `data\\MJOriginalImage\\${task_res.messageId}.png`); + // 判断是不是生图包,是的话需要替换图片的baseurl + if (this.mj_globalSetting.mj_simpleSetting.type == MJImageType.PACKAGE_MJ) { + let imageBaseUrl = this.mj_globalSetting.mj_imagePackageSetting.selectedProxy; + if (imageBaseUrl && imageBaseUrl != '') { + task_res.imageClick = task_res.imageClick.replace(/https?:\/\/[^/]+/, imageBaseUrl) + } + } await CheckFolderExistsOrCreate(path.dirname(imagePath)) await this.tools.downloadFileUrl(task_res.imageClick, imagePath) // 进行图片裁剪 diff --git a/src/main/Service/MJ/mjApi.ts b/src/main/Service/MJ/mjApi.ts index e873a01..37013c5 100644 --- a/src/main/Service/MJ/mjApi.ts +++ b/src/main/Service/MJ/mjApi.ts @@ -92,6 +92,18 @@ class MJApi { this.imagineUrl = localRemoteBaseUrl + ":" + localRemotePort + '/mj/submit/imagine' this.describeUrl = localRemoteBaseUrl + ":" + localRemotePort + '/mj/submit/describe' this.fetchTaskUrl = localRemoteBaseUrl + ":" + localRemotePort + '/mj/task/${id}/fetch' + } else if (this.mjSimpleSetting.type == MJImageType.PACKAGE_MJ) { + let apiUrlIndex = apiUrl.findIndex(item => item.value == this.mj_globalSetting.mj_imagePackageSetting.selectPackage); + if (apiUrlIndex == -1) { + throw new Error('没有找到MJ 生图包对应的请求URL,请检查配置'); + } + let apiUrlItem = apiUrl[apiUrlIndex]; + if (apiUrlItem.mj_url == null) { + throw new Error('没有找到MJ API对应的请求URL,请检查配置'); + } + this.imagineUrl = apiUrlItem.mj_url.imagine + this.describeUrl = apiUrlItem.mj_url.describe + this.fetchTaskUrl = apiUrlItem.mj_url.once_get_task } else { let apiUrlIndex = apiUrl.findIndex(item => item.value == this.mj_globalSetting.mj_apiSetting.mjApiUrl); if (apiUrlIndex == -1) { @@ -101,7 +113,6 @@ class MJApi { if (apiUrlItem.mj_url == null) { throw new Error('没有找到MJ API对应的请求URL,请检查配置'); } - this.imagineUrl = apiUrlItem.mj_url.imagine this.describeUrl = apiUrlItem.mj_url.describe this.fetchTaskUrl = apiUrlItem.mj_url.once_get_task @@ -131,6 +142,11 @@ class MJApi { 'mj-api-secret': this.mj_globalSetting.mj_localRemoteSimpleSetting.token } useTransfer = false; + } else if (this.mjSimpleSetting.type == MJImageType.PACKAGE_MJ) { + headers = { + Authorization: this.mj_globalSetting.mj_imagePackageSetting.token + } + useTransfer = false; } else { headers = { Authorization: this.mj_globalSetting.mj_apiSetting.apiKey @@ -232,7 +248,7 @@ class MJApi { res = await this.SubmitMJDescribeAPI(param) break default: - throw new Error("MJ出图的类型不支持") + throw new Error("MJ反推的类型不支持,反推只支持,API和代理模式") } return res } @@ -320,6 +336,7 @@ class MJApi { switch (this.mjSimpleSetting.type) { case MJImageType.REMOTE_MJ: case MJImageType.API_MJ: + case MJImageType.PACKAGE_MJ: case MJImageType.LOCAL_MJ: res = await this.SubmitMJImagineAPI(taskId, prompt) break @@ -370,8 +387,15 @@ class MJApi { delete data.accountFilter.instanceId; config.headers["Authorization"] = this.mj_globalSetting.mj_apiSetting.apiKey; useTransfer = this.mj_globalSetting.mj_apiSetting.useTransfer + } else if (this.mjSimpleSetting.type == MJImageType.PACKAGE_MJ) { + delete data.accountFilter.remark + delete data.accountFilter.instanceId; + delete data.accountFilter.modes; + config.headers["Authorization"] = this.mj_globalSetting.mj_imagePackageSetting.token; + useTransfer = false; } else if (this.mjSimpleSetting.type == MJImageType.LOCAL_MJ) { delete data.accountFilter.remark + delete data.accountFilter.modes; let instanceId = await this.GetRemoteMJAccountAndRandom('local'); data.accountFilter.instanceId = instanceId; useTransfer = false; @@ -414,6 +438,12 @@ class MJApi { resData = res.data } + if (this.mjSimpleSetting.type == MJImageType.PACKAGE_MJ) { + if (resData.code == -1 || resData.success == false) { + throw new Error(resData.message) + } + } + if (resData == null) { throw new Error("返回的数据为空") } diff --git a/src/main/Service/MJ/mjDefine.ts b/src/main/Service/MJ/mjDefine.ts index 6472983..7091944 100644 --- a/src/main/Service/MJ/mjDefine.ts +++ b/src/main/Service/MJ/mjDefine.ts @@ -12,14 +12,17 @@ function GetMJRequestModelOptions() { value: "api_mj", disable: false }, { - label: "本地代理模式", - value: "local_mj", - disable: false - }, - { label: "代理MJ(token)", value: "remote_mj", disable: false + }, { + label: "MJ生图包", + value: "package_mj", + disable: false + }, { + label: "本地代理模式", + value: "local_mj", + disable: false }, { label: "浏览器模式", @@ -49,6 +52,18 @@ function GetMJRobotOptions() { */ function GetMJRobotModelOptions(mjRobot?: MJRobotType) { let allRobotModel = [ + { + label: "MJ V7.0", + text: "v 7", + type: MJRobotType.MJ, + value: "a26fc136-4558-4426-b827-fa7d0c189fc9" + }, + { + label: "MJ V6.1", + text: "v 6.1", + type: MJRobotType.MJ, + value: "08ffca01-5c8d-4f93-be97-05615fac1a8f" + }, { label: "MJ V6.0", text: "v 6", @@ -137,7 +152,7 @@ function GetMJImageScaleOptions() { * @returns */ function GetMJAPIUrlOptions() { - return apiUrl.filter((item) => item.mj_url) + return apiUrl.filter((item) => item.mj_url && item.isPackage == false) } /** diff --git a/src/model/Setting/mjSetting.d.ts b/src/model/Setting/mjSetting.d.ts index 1e714ce..5d1496a 100644 --- a/src/model/Setting/mjSetting.d.ts +++ b/src/model/Setting/mjSetting.d.ts @@ -107,6 +107,15 @@ declare namespace MJSettingModel { token: string } + /** + * MJ 生图包配置 + */ + type MJImagePackageModel = { + selectPackage: string + token: string + selectedProxy: string + } + /** * MJ 全局设置 */ @@ -116,5 +125,6 @@ declare namespace MJSettingModel { mj_browserSetting: BrowserMJSettingModel mj_remoteSimpleSetting: MJRemoteSimpleSettingModel mj_localRemoteSimpleSetting: MJLocalRemoteSimpleSettingModel + mj_imagePackageSetting: MJImagePackageModel } } diff --git a/src/renderer/src/components/Common/NotesCollapse.vue b/src/renderer/src/components/Common/NotesCollapse.vue index 79f75f4..f7446c6 100644 --- a/src/renderer/src/components/Common/NotesCollapse.vue +++ b/src/renderer/src/components/Common/NotesCollapse.vue @@ -137,4 +137,27 @@ defineProps({ .clickable-link:hover { color: #0055cc; } - \ No newline at end of file + + + diff --git a/src/renderer/src/components/Setting/MJSetting/MJAPISetting.vue b/src/renderer/src/components/Setting/MJSetting/MJAPISetting.vue index b7d4edf..3b77a65 100644 --- a/src/renderer/src/components/Setting/MJSetting/MJAPISetting.vue +++ b/src/renderer/src/components/Setting/MJSetting/MJAPISetting.vue @@ -134,6 +134,3 @@ function openExternalLink(url) { window.api.OpenUrl(url) } - diff --git a/src/renderer/src/components/Setting/MJSetting/MJImagePackage.vue b/src/renderer/src/components/Setting/MJSetting/MJImagePackage.vue new file mode 100644 index 0000000..a53071c --- /dev/null +++ b/src/renderer/src/components/Setting/MJSetting/MJImagePackage.vue @@ -0,0 +1,106 @@ + + + + + diff --git a/src/renderer/src/components/Setting/MJSetting/MJLocalRemoteSetting.vue b/src/renderer/src/components/Setting/MJSetting/MJLocalRemoteSetting.vue index 02dba87..3cffb5f 100644 --- a/src/renderer/src/components/Setting/MJSetting/MJLocalRemoteSetting.vue +++ b/src/renderer/src/components/Setting/MJSetting/MJLocalRemoteSetting.vue @@ -1,6 +1,10 @@