Skip to content

Commit d449173

Browse files
committed
merge
2 parents d807399 + c6be274 commit d449173

16 files changed

Lines changed: 441 additions & 143 deletions

File tree

bizyui/js/apply_image_to_node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ window.addEventListener('message', async function(event) {
109109
// 发送请求
110110
const headers = {};
111111
if (token) {
112-
headers["Authorization"] = `Bearer ${token}`;
112+
headers["Authorization"] = token;
113113
}
114114

115115
const response = await fetch('/upload/image', {

bizyui/js/bizyair_tools.js

Lines changed: 79 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
11
import { app, ComfyApp } from "../../scripts/app.js";
22
import { api } from "../../../scripts/api.js";
33

4-
app.registerExtension({
5-
name: "bizyair.tool",
6-
setup() {
4+
async function handleFile(json_data) {
5+
const jsonContent = json_data
76

8-
async function handleFile(json_data) {
9-
const jsonContent = json_data
7+
await app.loadGraphData(
8+
jsonContent,
9+
true,
10+
false,
11+
"convert_test"
12+
);
13+
}
1014

11-
await app.loadGraphData(
12-
jsonContent,
13-
true,
14-
false,
15-
"convert_test"
16-
);
15+
// 检查是否为服务器模式
16+
async function isServerMode() {
17+
const serverModeResponse = await fetch("/bizyair/server_mode");
18+
const serverModeData = await serverModeResponse.json();
19+
return serverModeData.data.server_mode === true;
20+
}
1721

18-
}
19-
async function convert(){
20-
const p2 = await app.graphToPrompt();
21-
const json = JSON.stringify(p2["workflow"], null, 2);
22+
async function convert(){
23+
const p2 = await app.graphToPrompt();
24+
const json = JSON.stringify(p2["workflow"], null, 2);
25+
await api.fetchApi("/bizyair/node_converter", {
26+
method: "POST",
27+
headers: {
28+
"Content-Type": "application/json",
29+
},
30+
body: json
31+
}).then(response => response.json())
32+
.then(data => handleFile(data))
33+
.catch(error => console.error("Error:", error));
34+
}
2235

23-
await api.fetchApi("/bizyair/node_converter", {
24-
method: "POST",
25-
headers: {
26-
"Content-Type": "application/json",
27-
},
28-
body: json
29-
}).then(response => response.json())
30-
.then(data => handleFile(data))
31-
.catch(error => console.error("Error:", error));
32-
}
33-
// Add canvas menu options
36+
// 全局变量,用于节流控制
37+
let lastConvertTime = 0;
38+
const MIN_CONVERT_INTERVAL = 3000; // 最小间隔3秒
39+
40+
// 节流函数确保convert不会被频繁调用
41+
async function throttledConvert() {
42+
const serverMode = await isServerMode();
43+
if (!serverMode) {
44+
return;
45+
}
46+
const now = Date.now();
47+
if (now - lastConvertTime > MIN_CONVERT_INTERVAL) {
48+
lastConvertTime = now;;
49+
convert();
50+
}
51+
}
52+
53+
app.registerExtension({
54+
name: "bizyair.tool",
55+
setup() {
56+
console.log('BizyAir Tools extension setup');
57+
// 添加菜单选项
3458
const orig = LGraphCanvas.prototype.getCanvasMenuOptions;
3559
LGraphCanvas.prototype.getCanvasMenuOptions = function () {
3660
const options = orig.apply(this, arguments);
@@ -48,7 +72,33 @@ app.registerExtension({
4872
},
4973
});
5074
return options;
51-
};
52-
53-
},
75+
};
76+
// 监听导入
77+
const origLoadGraphData = app.loadGraphData;
78+
if (origLoadGraphData) {
79+
app.loadGraphData = async function() {
80+
const result = origLoadGraphData.apply(this, arguments);
81+
const serverMode = await isServerMode();
82+
if (serverMode) {
83+
setTimeout(() => {
84+
throttledConvert();
85+
}, 500);
86+
}
87+
return result;
88+
};
89+
}
90+
},
91+
// 添加init钩子,在ComfyUI初始化后调用convert函数
92+
init() {
93+
console.log('BizyAir Tools initializing...');
94+
lastConvertTime = Date.now(); // 记录初始化时间
95+
// 检查是否为服务器模式
96+
setTimeout(async () => {
97+
const serverMode = await isServerMode();
98+
if (serverMode) {
99+
console.log('服务器模式,页面初始化完成,调用convert');
100+
convert();
101+
}
102+
}, 500);
103+
}
54104
});

bizyui/js/model_apply.js

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,39 @@ const NodeInfoLogger = (function() {
3434
return `${baseUrl}?filename=${filename}&subfolder=&type=${type}&rand=${Math.random()}`;
3535
};
3636

37-
// 获取图片并转换为base64
37+
// 获取图片并转换为base64(根据 server_mode 判断逻辑)
3838
const getImageAsBase64 = async (filename, type) => {
3939
try {
4040
// 检查服务器模式
4141
const serverModeResponse = await fetch("/bizyair/server_mode");
4242
const serverModeData = await serverModeResponse.json();
4343

44-
let token = null;
45-
if (serverModeData.data.server_mode) {
46-
// 服务器模式,需要token
47-
token = await new Promise((resolve) => {
48-
const checkToken = () => {
49-
const token = getCookie("bizy_token");
50-
if (token) {
51-
clearInterval(timer);
52-
resolve(token);
53-
}
54-
};
55-
56-
const timer = setInterval(checkToken, 300);
57-
checkToken(); // 立即执行一次检查
58-
});
44+
// 非服务器模式下,如果 filename 已经是 base64 数据,直接返回
45+
if (!serverModeData.data.server_mode && filename.startsWith('data:')) {
46+
console.log('本地模式:filename 已经是 base64 数据,直接返回');
47+
return filename;
5948
}
60-
61-
const imageUrl = buildImageUrl(filename, type);
62-
const headers = {};
63-
if (token) {
64-
headers["Authorization"] = `Bearer ${token}`;
49+
50+
let imageUrl;
51+
let headers = {};
52+
53+
if (serverModeData.data.server_mode) {
54+
// 服务器模式,改为请求后端转发接口
55+
imageUrl = `/bizyair/proxy_view?filename=${encodeURIComponent(filename)}`;
56+
} else {
57+
// 本地模式,使用原有 buildImageUrl
58+
imageUrl = buildImageUrl(filename, type);
6559
}
6660

67-
const response = await fetch(imageUrl, {
68-
headers: headers
69-
});
61+
const response = await fetch(imageUrl, { headers });
7062
if (!response.ok) {
7163
throw new Error(`获取图片失败: ${response.status} ${response.statusText}`);
7264
}
7365
const blob = await response.blob();
74-
75-
// 将blob转为File对象
66+
// 转 base64
7667
const file = new File([blob], filename, { type: blob.type });
77-
78-
// 使用formatToWebp进行压缩
7968
const { base64: compressedBase64 } = await formatToWebp(file);
80-
8169
return compressedBase64;
82-
83-
8470
} catch (error) {
8571
console.error('获取图片并转换为base64失败:', error);
8672
return null;
@@ -121,17 +107,32 @@ const NodeInfoLogger = (function() {
121107
const blob = new Blob([byteArray], { type: mimeType || base64.split(':')[1].split(';')[0] })
122108
return new File([blob], filename, { type: blob.type })
123109
}
124-
// 构建图片信息对象
125-
const buildImageInfo = (imageData) => {
110+
// 构建图片信息对象(根据 server_mode 判断逻辑)
111+
const buildImageInfo = async (imageData) => {
126112
if (!imageData?.filename) return null;
127-
128-
// 根据节点类型确定图片类型
129-
const type = imageData.type || 'temp';
113+
// 检查服务器模式
114+
const serverModeResponse = await fetch("/bizyair/server_mode");
115+
const serverModeData = await serverModeResponse.json();
116+
const type = imageData.type || 'temp';
130117
const path = `/${type}/${imageData.filename}`;
131-
118+
let url;
119+
120+
if (serverModeData.data.server_mode) {
121+
// 服务器模式,使用 view 接口
122+
url = `/view?filename=${encodeURIComponent(imageData.filename)}`;
123+
} else {
124+
// 本地模式,如果 filename 是 base64 数据,直接使用
125+
if (imageData.filename.startsWith('data:')) {
126+
url = imageData.filename;
127+
} else {
128+
// 否则使用 buildImageUrl 构建 URL
129+
url = buildImageUrl(imageData.filename, type);
130+
}
131+
}
132+
132133
return {
133134
filename: imageData.filename,
134-
url: buildImageUrl(imageData.filename, type),
135+
url: url,
135136
path: path,
136137
type: type
137138
};
@@ -252,7 +253,7 @@ const NodeInfoLogger = (function() {
252253
// 使用异步IIFE处理图片,不阻塞主流程
253254
(async () => {
254255
try {
255-
const imageInfo = buildImageInfo(this.images[0]);
256+
const imageInfo = await buildImageInfo(this.images[0]);
256257

257258
// 检查是否存在全局bizyAirLib对象及logNodeInfo函数
258259
if (typeof bizyAirLib !== 'undefined' && typeof bizyAirLib.logNodeInfo === 'function') {

bizyui/js/siliconcloud_llm_api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const createModelFetchExtension = (nodeName, endpoint) => {
5252

5353
// 只有在token存在时才添加Authorization头
5454
if (token) {
55-
headers["Authorization"] = `Bearer ${token}`;
55+
headers["Authorization"] = token;
5656
}
5757

5858
const response = await fetch(endpoint, {

bizyui/js/subassembly/tools.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const hideWidget = (node, widget_name) => {
99

1010
widget.computeSize = () => [0, -4];
1111
widget.type = "hidden";
12+
widget.hidden=true
1213
widget.options = widget.options || {};
1314
widget.show = () => {
1415
widget.computeSize = originalComputeSize;

src/components/assistant/Sidebar.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
v-if="
5858
message.role === 'assistant' &&
5959
sidebarStore.nodeInfo &&
60-
canApplyToNode(sidebarStore.nodeInfo)
60+
canApplyToNode(sidebarStore.nodeInfo) &&
61+
!serverMode
6162
"
6263
class="image-actions"
6364
>
@@ -354,6 +355,9 @@
354355
}
355356
}
356357
358+
// 服务端模式
359+
const serverMode = ref(false)
360+
357361
// 生图功能
358362
const isGeneratingImage = ref(false)
359363
@@ -476,7 +480,10 @@
476480
// 生成成功后,添加带图片的助手消息
477481
const assistantMessage = {
478482
role: 'assistant' as const,
479-
content: `已为您生成图片(点击LoadImage节点可以应用)`,
483+
// 服务端模式下只展示"已为您生成图片"
484+
content: serverMode.value
485+
? '已为您生成图片'
486+
: '已为您生成图片(点击LoadImage节点可以应用)',
480487
time: getCurrentTime(),
481488
hasImage: true,
482489
image: imageUrl
@@ -925,6 +932,17 @@
925932
}
926933
927934
chatMessages.value = [welcomeMessage]
935+
936+
// 异步获取 server_mode
937+
;(async () => {
938+
try {
939+
const res = await fetch('/bizyair/server_mode')
940+
const data = await res.json()
941+
serverMode.value = !!data?.data?.server_mode
942+
} catch (e) {
943+
serverMode.value = false
944+
}
945+
})()
928946
})
929947
</script>
930948

src/components/assistant/util.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ export async function sendStreamChatRequest(
264264
'Content-Type': 'application/json',
265265
Authorization: Cookies.get('bizy_token') || '',
266266
...(options as any)?.headers
267+
'Content-Type': 'application/json',
268+
Authorization: Cookies.get('bizy_token') || '',
269+
...(options as any)?.headers
267270
},
268271
body: JSON.stringify(requestBody),
269272
signal: abortController.signal // 添加中止信号
@@ -430,7 +433,9 @@ export async function generateImage(options: {
430433
const response = await fetch('/bizyair/model/images', {
431434
method: 'POST',
432435
headers: {
433-
'Content-Type': 'application/json'
436+
'Content-Type': 'application/json',
437+
Authorization: Cookies.get('bizy_token') || '',
438+
...(options as any)?.headers
434439
},
435440
body: JSON.stringify({
436441
prompt: prompt,

src/components/community/detail/Index.vue

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
5858
5959
const showAllTags = ref(false)
6060
61+
// 添加视频检测函数
62+
const isVideoUrl = (url: string) => {
63+
if (!url) return false
64+
const videoExtensions = ['.mp4', '.webm', '.ogg', '.mov', '.avi', '.mkv']
65+
const lowercaseUrl = url.toLowerCase()
66+
return videoExtensions.some(ext => lowercaseUrl.includes(ext))
67+
}
68+
6169
const fetchModelDetail = async () => {
6270
try {
6371
const res = await model_detail({
@@ -821,15 +829,30 @@
821829
class="flex flex-col gap-4 items-start justify-start relative min-w-[620px] w-[65%] overflow-hidden"
822830
>
823831
<div class="w-full">
824-
<NImageGroup v-if="currentVersion?.cover_urls && currentVersion?.cover_urls.length > 0">
825-
<NImage
826-
v-for="(cover, index) in currentVersion?.cover_urls"
827-
:key="index"
828-
:src="cover"
829-
:preview-src="cover"
830-
height="512px"
831-
/>
832-
</NImageGroup>
832+
<div
833+
v-if="currentVersion?.cover_urls && currentVersion?.cover_urls.length > 0"
834+
class="space-y-4"
835+
>
836+
<div v-for="(cover, index) in currentVersion?.cover_urls" :key="index" class="w-full">
837+
<!-- 视频显示 -->
838+
<video
839+
v-if="isVideoUrl(cover)"
840+
:src="cover"
841+
controls
842+
class="w-full h-auto max-h-[512px] object-contain rounded-lg"
843+
preload="metadata"
844+
/>
845+
<!-- 图片显示 -->
846+
<NImageGroup v-else>
847+
<NImage
848+
:src="cover"
849+
:preview-src="cover"
850+
height="512px"
851+
class="w-full object-contain"
852+
/>
853+
</NImageGroup>
854+
</div>
855+
</div>
833856
<MdPreview
834857
v-if="currentVersion?.intro"
835858
id="previewRef"

0 commit comments

Comments
 (0)