Skip to content

Commit 5d51951

Browse files
dfhfg123doombeaker
andauthored
add frontend directory and update packaging process (#50)
* 更改目录结构和打包 * auto prettier format code * 添加readme说明 * auto prettier format code * 更新readme * 修改ignore文件 * 合并sh文件 * fix lint * auto prettier format code * 删除多余的vite图标 * 修复upload类型错误 * update model_apply js * update gitignore * update version * update package.json and build logical * refine --------- Co-authored-by: Yao Chi <later@usopp.net>
1 parent 2640b30 commit 5d51951

33 files changed

Lines changed: 2417 additions & 10 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,10 @@ Thumbs.db
9494
browser_tests/test-results/
9595
browser_tests/playwright-report/
9696
browser_tests/blob-report/
97+
98+
#packaged product
99+
bizyui.egg-info/
100+
bizyui/js/bizyair_frontend.js
101+
dist/
102+
103+
*.tsbuildinfo

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ npm run format
1313
npx eslint src
1414
# release frontend
1515
npm run dev
16+
#重新打包前端得到.whl包
17+
npm run build:py
18+
#不重新生成forntend_bizyair.js只重新打包bizyui目录得到.whl包
19+
npm run build:bizyui
1620
```
1721

22+
1823
### Installation and Setup

bizyui/__init__.py

Whitespace-only changes.

bizyui/js/__init__.py

Whitespace-only changes.

bizyui/js/apis.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import { dialog } from './subassembly/dialog.js';
2+
3+
const fetchCache = new Map();
4+
5+
function customFetch(url, options = {}) {
6+
const now = Date.now();
7+
if (fetchCache.has(url)) {
8+
const lastFetchTime = fetchCache.get(url);
9+
if (now - lastFetchTime < 1200) {
10+
return Promise.resolve(null);
11+
}
12+
}
13+
fetchCache.set(url, now);
14+
const host = `${window.location.origin}${window.location.pathname === '/' ? '' : window.location.pathname}`
15+
return window.fetch(`${host}${url}`, options)
16+
.then(response => {
17+
if (response.status === 404) {
18+
dialog({
19+
content: "You may be missing dependencies at the moment. For details, please refer to the ComfyUI logs.",
20+
type: 'error',
21+
noText: 'Close'
22+
})
23+
}
24+
return response.json();
25+
})
26+
.then(data => {
27+
const { code, message } = data;
28+
if (code !== 20000) {
29+
dialog({
30+
type: 'warning',
31+
content: message,
32+
noText: 'Close',
33+
onNo: () => {
34+
if (code === 401000) {
35+
document.querySelector('.menus-item-key').click()
36+
}
37+
}
38+
})
39+
40+
return;
41+
}
42+
return data;
43+
})
44+
.catch(error => {
45+
console.error('Fetch error:', error);
46+
throw error;
47+
});
48+
}
49+
50+
51+
export function check_model_exists ( type, name ) {
52+
return customFetch('/bizyair/modelhost/check_model_exists', {
53+
method: 'POST',
54+
body: JSON.stringify({ type, name })
55+
})
56+
}
57+
58+
export function model_upload ( data ) {
59+
return customFetch('/bizyair/modelhost/model_upload', {
60+
method: 'POST',
61+
body: JSON.stringify(data)
62+
})
63+
}
64+
65+
export function file_upload ( data ) {
66+
return customFetch('/bizyair/modelhost/file_upload', {
67+
method: 'POST',
68+
body: data
69+
})
70+
}
71+
72+
export function set_api_key ( data ) {
73+
return customFetch('/bizyair/set_api_key', {
74+
method: 'POST',
75+
headers: {
76+
'Content-Type': 'application/x-www-form-urlencoded'
77+
},
78+
body: data
79+
})
80+
}
81+
82+
export function models_files ( params, data ) {
83+
let actualParams = ''
84+
for (const i in params) {
85+
actualParams += `${i}=${params[i]}&`
86+
}
87+
return customFetch(`/bizyair/community/models/query?${actualParams}`, {
88+
method: 'POST',
89+
body: JSON.stringify(data)
90+
})
91+
}
92+
93+
export function change_public ( data ) {
94+
return customFetch('/bizyair/modelhost/models/change_public', {method: 'PUT', body: JSON.stringify(data)})
95+
}
96+
97+
export function model_types () {
98+
return customFetch('/bizyair/community/model_types', {method: 'GET'})
99+
}
100+
101+
export function check_folder (url) {
102+
return customFetch(`/bizyair/modelhost/check_folder?absolute_path=${encodeURIComponent(url)}`, {method: 'GET'})
103+
}
104+
105+
export function submit_upload (data) {
106+
return customFetch(`/bizyair/community/submit_upload?clientId=${sessionStorage.getItem('clientId')}`, {
107+
method: 'POST',
108+
body: JSON.stringify(data)
109+
})
110+
}
111+
112+
export function delModels ( data ) {
113+
return customFetch('/bizyair/modelhost/models', {
114+
method: 'DELETE',
115+
body: JSON.stringify({
116+
type: data.type,
117+
name: data.name,
118+
}),
119+
})
120+
}
121+
122+
export function getUserInfo () {
123+
return customFetch('/bizyair/user/info', { method: 'get' })
124+
}
125+
126+
export function putShareId (data) {
127+
return customFetch('/bizyair/user/share_id', {
128+
method: 'put',
129+
body: JSON.stringify(data)
130+
})
131+
}
132+
133+
export function getDescription (data) {
134+
return customFetch(`/bizyair/modelhost/models/description?${new URLSearchParams(data).toString()}`, {
135+
method: 'get'
136+
})
137+
}
138+
139+
export function putDescription (data) {
140+
return customFetch('/bizyair/modelhost/models/description', {
141+
method: 'put',
142+
body: JSON.stringify(data)
143+
})
144+
}
145+
146+
export function uploadImage (file) {
147+
const formData = new FormData();
148+
formData.append('file', file);
149+
return customFetch('/bizyair/community/files/upload', {
150+
method: 'POST',
151+
body: formData
152+
})
153+
}

bizyui/js/bizyair_tools.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { app, ComfyApp } from "../../scripts/app.js";
2+
import { api } from "../../../scripts/api.js";
3+
4+
app.registerExtension({
5+
name: "bizyair.tool",
6+
setup() {
7+
8+
async function handleFile(json_data) {
9+
const jsonContent = json_data
10+
11+
await app.loadGraphData(
12+
jsonContent,
13+
true,
14+
false,
15+
"convert_test"
16+
);
17+
18+
}
19+
async function convert(){
20+
const p2 = await app.graphToPrompt();
21+
const json = JSON.stringify(p2["workflow"], null, 2);
22+
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
34+
const orig = LGraphCanvas.prototype.getCanvasMenuOptions;
35+
LGraphCanvas.prototype.getCanvasMenuOptions = function () {
36+
const options = orig.apply(this, arguments);
37+
options.push(null, {
38+
content: "BizyAir Tools",
39+
submenu: {
40+
options: [
41+
{
42+
content: "convert to bizyair node",
43+
callback: async () => {
44+
await convert()
45+
},
46+
},
47+
],
48+
},
49+
});
50+
return options;
51+
};
52+
53+
},
54+
});

bizyui/js/connection_color.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { app } from "../../scripts/app.js";
2+
3+
app.registerExtension({
4+
name: "bizyair.custom.connectionColorByType",
5+
async setup() {
6+
Object.assign(app.canvas.default_connection_color_byType, {
7+
BIZYAIR_MODEL: '#7C5AEC',
8+
BIZYAIR_CLIP: '#FFF4C4',
9+
BIZYAIR_VAE: '#FF5959',
10+
BIZYAIR_CONDITIONING: '#967117',
11+
})
12+
},
13+
});

bizyui/js/dataset_apply.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { app } from "../../scripts/app.js";
2+
3+
import './bizyair_frontend.js'
4+
import { hideWidget } from './subassembly/tools.js'
5+
6+
function createSetWidgetCallback() {
7+
return function setWidgetCallback() {
8+
const targetWidget = this.widgets.find(widget => widget.name == "dataset_path");
9+
if (targetWidget) {
10+
targetWidget.value = targetWidget.value || "to choose"
11+
targetWidget.mouse = function(e, pos, canvas) {
12+
try {
13+
if (e.type === "pointerdown" || e.type === "mousedown" || e.type === "click" || e.type === "pointerup") {
14+
e.preventDefault();
15+
e.stopPropagation();
16+
e.widgetClick = true;
17+
const currentNode = this.node;
18+
19+
if (!currentNode || !currentNode.widgets) {
20+
console.warn("Node or widgets not available");
21+
return false;
22+
}
23+
24+
if (typeof bizyAirLib !== 'undefined' && typeof bizyAirLib.showDatasetSelect === 'function') {
25+
bizyAirLib.showDatasetSelect({
26+
showDatasetSelect: true,
27+
isNodeSelect: true,
28+
onApply: (versionId, name) => {
29+
console.log("onApply", versionId, name)
30+
if (!currentNode || !currentNode.widgets) return;
31+
32+
const datasetPath = currentNode.widgets.find(widget => widget.name == "dataset_path");
33+
const datasetVersionId = currentNode.widgets.find(w => w.name === "dataset_version_id");
34+
if (datasetPath && datasetVersionId) {
35+
datasetPath.value = name;
36+
datasetVersionId.value = versionId;
37+
currentNode.setDirtyCanvas(true);
38+
}
39+
}
40+
})
41+
} else {
42+
console.error("bizyAirLib not available");
43+
}
44+
return false;
45+
}
46+
} catch (error) {
47+
console.error("Error handling mouse event:", error);
48+
}
49+
};
50+
51+
targetWidget.node = this;
52+
targetWidget.options = targetWidget.options || {};
53+
targetWidget.options.values = () => [];
54+
targetWidget.options.editable = false;
55+
targetWidget.clickable = true;
56+
targetWidget.processMouse = true;
57+
}
58+
}
59+
}
60+
61+
function setupNodeMouseBehavior(node) {
62+
hideWidget(node, "dataset_version_id");
63+
64+
if (!node._bizyairState) {
65+
node._bizyairState = {
66+
lastClickTime: 0,
67+
DEBOUNCE_DELAY: 300,
68+
original_onMouseDown: node.onMouseDown
69+
};
70+
}
71+
72+
node.onMouseDown = function(e, pos, canvas) {
73+
if (e.widgetClick) {
74+
return this._bizyairState.original_onMouseDown?.apply(this, arguments);
75+
}
76+
const targetWidget = this.widgets.find(widget => widget.name == "dataset_path");
77+
if (targetWidget && pos[1] - targetWidget.last_y > 0 && pos[1] - targetWidget.last_y < 20) {
78+
const litecontextmenu = document.querySelector('.litegraph.litecontextmenu')
79+
if (litecontextmenu) {
80+
litecontextmenu.style.display = 'none'
81+
}
82+
e.stopImmediatePropagation();
83+
e.preventDefault();
84+
if (e.button !== 0) {
85+
return false;
86+
}
87+
88+
const currentTime = new Date().getTime();
89+
if (currentTime - this._bizyairState.lastClickTime < this._bizyairState.DEBOUNCE_DELAY) {
90+
return false;
91+
}
92+
this._bizyairState.lastClickTime = currentTime;
93+
bizyAirLib.showDatasetSelect({
94+
showDatasetSelect: true,
95+
isNodeSelect: true,
96+
onApply: (versionId, name) => {
97+
console.log("onApply", versionId, name)
98+
if (!currentNode || !currentNode.widgets) return;
99+
100+
const datasetPath = currentNode.widgets.find(widget => widget.name == "dataset_path");
101+
const datasetVersionId = currentNode.widgets.find(w => w.name === "dataset_version_id");
102+
if (datasetPath && datasetVersionId) {
103+
datasetPath.value = name;
104+
datasetVersionId.value = versionId;
105+
currentNode.setDirtyCanvas(true);
106+
}
107+
}
108+
})
109+
return false;
110+
} else {
111+
return this._bizyairState.original_onMouseDown?.apply(this, arguments);
112+
}
113+
}
114+
}
115+
116+
app.registerExtension({
117+
name: "bizyair.siliconcloud.share.dataset.loader.train",
118+
async beforeRegisterNodeDef(nodeType, nodeData, app) {
119+
if (nodeData.name === "BizyAir_TrainDatasetAdd") {
120+
const onNodeCreated = nodeType.prototype.onNodeCreated;
121+
nodeType.prototype.onNodeCreated = function() {
122+
try {
123+
const result = onNodeCreated?.apply(this, arguments);
124+
createSetWidgetCallback().call(this);
125+
return result;
126+
} catch (error) {
127+
console.error("Error in node creation:", error);
128+
}
129+
};
130+
}
131+
},
132+
133+
async nodeCreated(node) {
134+
if (node?.comfyClass === "BizyAir_TrainDatasetAdd") {
135+
setupNodeMouseBehavior(node);
136+
}
137+
}
138+
})

0 commit comments

Comments
 (0)