bizydraft 0.2.71__py3-none-any.whl → 0.2.72.dev20251013070955__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bizydraft might be problematic. Click here for more details.

@@ -29,7 +29,6 @@ BIZYDRAFT_CHUNK_SIZE = int(os.getenv("BIZYDRAFT_CHUNK_SIZE", 1024 * 16)) # 16KB
29
29
 
30
30
 
31
31
  async def view_image(request):
32
- from bizydraft.oss_utils import CLIPSPACE_TO_OSS_MAPPING
33
32
 
34
33
  logger.debug(f"Received request for /view with query: {request.rel_url.query}")
35
34
  if "filename" not in request.rel_url.query:
@@ -39,12 +38,6 @@ async def view_image(request):
39
38
  filename = request.rel_url.query["filename"]
40
39
  subfolder = request.rel_url.query.get("subfolder", "")
41
40
 
42
- if subfolder == "clipspace" and filename in CLIPSPACE_TO_OSS_MAPPING:
43
- oss_url = CLIPSPACE_TO_OSS_MAPPING[filename]
44
- logger.info(f"[OSS_MAPPING] Found clipspace mapping: {filename} -> {oss_url}")
45
- filename = oss_url
46
- subfolder = "" # Clear subfolder since filename is now the full URL
47
-
48
41
  http_prefix_options = ("http:", "https:")
49
42
 
50
43
  if not filename.startswith(http_prefix_options) and "http" not in subfolder:
@@ -3,53 +3,185 @@ import { api } from "../../scripts/api.js";
3
3
 
4
4
  window.CLIPSPACE_TO_OSS_MAP = window.CLIPSPACE_TO_OSS_MAP || {};
5
5
 
6
+ // ═══════════════════════════════════════════════════════════════════════════
7
+ // 工具函数:查找 clipspace 文件名对应的 OSS URL
8
+ // ═══════════════════════════════════════════════════════════════════════════
9
+ function findOssUrl(filename) {
10
+ return window.CLIPSPACE_TO_OSS_MAP[filename]
11
+ || window.CLIPSPACE_TO_OSS_MAP[`${filename} [input]`]
12
+ || window.CLIPSPACE_TO_OSS_MAP[`${filename} [output]`];
13
+ }
14
+
15
+ // ═══════════════════════════════════════════════════════════════════════════
16
+ // 工具函数:替换 clipspace URL 为 OSS URL
17
+ // ═══════════════════════════════════════════════════════════════════════════
18
+ function replaceClipspaceUrl(urlString) {
19
+ if (!urlString || typeof urlString !== 'string') return urlString;
20
+ if (!urlString.includes('/view?') || !urlString.includes('clipspace')) return urlString;
21
+
22
+ try {
23
+ const url = new URL(urlString, window.location.origin);
24
+ const filename = url.searchParams.get('filename');
25
+ const subfolder = url.searchParams.get('subfolder');
26
+
27
+ if (subfolder === 'clipspace' && filename) {
28
+ const ossUrl = findOssUrl(filename);
29
+ if (ossUrl) {
30
+ url.searchParams.set('filename', ossUrl);
31
+ url.searchParams.set('subfolder', '');
32
+ return url.pathname + url.search;
33
+ }
34
+ }
35
+ } catch (e) {
36
+ console.error('[BizyDraft] Error replacing clipspace URL:', e);
37
+ }
38
+
39
+ return urlString;
40
+ }
41
+
42
+ // ═══════════════════════════════════════════════════════════════════════════
43
+ // 拦截图片加载请求,将 clipspace URL 替换为 OSS URL
44
+ // ═══════════════════════════════════════════════════════════════════════════
45
+ (function interceptImageLoading() {
46
+ const originalSrcDescriptor = Object.getOwnPropertyDescriptor(Image.prototype, 'src');
47
+
48
+ Object.defineProperty(Image.prototype, 'src', {
49
+ get() {
50
+ return originalSrcDescriptor.get.call(this);
51
+ },
52
+ set(value) {
53
+ const modifiedValue = replaceClipspaceUrl(value);
54
+ if (modifiedValue !== value) {
55
+ console.log('[BizyDraft Image] Redirected:', value, '->', modifiedValue);
56
+ }
57
+ originalSrcDescriptor.set.call(this, modifiedValue);
58
+ },
59
+ configurable: true
60
+ });
61
+
62
+ const originalSetAttribute = HTMLImageElement.prototype.setAttribute;
63
+ HTMLImageElement.prototype.setAttribute = function(name, value) {
64
+ if (name === 'src') {
65
+ const modifiedValue = replaceClipspaceUrl(value);
66
+ if (modifiedValue !== value) {
67
+ console.log('[BizyDraft setAttribute] Redirected to OSS');
68
+ }
69
+ return originalSetAttribute.call(this, name, modifiedValue);
70
+ }
71
+ return originalSetAttribute.call(this, name, value);
72
+ };
73
+
74
+ console.log('[BizyDraft] Image interceptor installed');
75
+ })();
6
76
 
77
+ // ═══════════════════════════════════════════════════════════════════════════
78
+ // 拦截上传响应,保存映射并篡改返回值
79
+ // ═══════════════════════════════════════════════════════════════════════════
7
80
  const originalFetchApi = api.fetchApi;
8
81
  api.fetchApi = async function(url, options) {
9
82
  const response = await originalFetchApi.call(this, url, options);
10
- console.log(url,'url--------------------');
11
- if ((url==='/upload/image' || url==='/upload/mask') && response.ok) {
12
- try {
13
- const clonedResponse = response.clone();
14
- const data = await clonedResponse.json();
15
-
16
- if (data && data.name && data.subfolder) {
17
- if (options && options.body && options.body instanceof FormData) {
18
- const imageFile = options.body.get('image');
19
- if (imageFile && imageFile.name) {
20
- const originalFilename = imageFile.name;
21
-
22
- let ossUrl;
23
- if (data.name.startsWith('http://') || data.name.startsWith('https://')) {
24
- ossUrl = data.name;
25
- } else if (data.subfolder && (data.subfolder.includes('http://') || data.subfolder.includes('https://'))) {
26
- ossUrl = `${data.subfolder}/${data.name}`;
27
- } else {
28
- return response;
29
- }
30
83
 
31
- window.CLIPSPACE_TO_OSS_MAP[originalFilename] = ossUrl;
84
+ const isUploadApi = url === '/upload/image' || url === '/upload/mask'
85
+ || url === '/api/upload/image' || url === '/api/upload/mask';
32
86
 
33
- const filenameWithoutSuffix = originalFilename.replace(/ \[(input|output)\]$/, '');
34
- if (filenameWithoutSuffix !== originalFilename) {
35
- window.CLIPSPACE_TO_OSS_MAP[filenameWithoutSuffix] = ossUrl;
36
- }
87
+ if (!isUploadApi || !response.ok) {
88
+ return response;
89
+ }
90
+
91
+ try {
92
+ const data = await response.clone().json();
93
+
94
+ // 检查是否是 OSS 上传响应
95
+ const isOssUpload = data.subfolder?.includes('http://') || data.subfolder?.includes('https://')
96
+ || data.name?.startsWith('http://') || data.name?.startsWith('https://');
97
+
98
+ if (!isOssUpload) {
99
+ return response;
100
+ }
101
+
102
+ // 构造完整的 OSS URL
103
+ const ossUrl = data.subfolder?.includes('http')
104
+ ? `${data.subfolder}/${data.name}`
105
+ : data.name;
106
+
107
+ // 处理映射逻辑
108
+ let finalUrl = ossUrl;
109
+
110
+ if (options?.body instanceof FormData) {
111
+ const imageFile = options.body.get('image');
112
+ if (imageFile?.name) {
113
+ const filename = imageFile.name;
114
+ const idMatch = filename.match(/(\d+)/);
115
+ const baseId = idMatch?.[1];
116
+
117
+ console.log('[BizyDraft Upload]', url, '-', filename, `(${imageFile.size} bytes)`);
118
+ console.log('[BizyDraft Upload] Backend response:', data.name);
119
+
120
+ // 第一次 /upload/mask 的结果是涂改后的完整图片
121
+ if (baseId && url.includes('/upload/mask')) {
122
+ const firstMaskKey = `__FIRST_MASK_${baseId}__`;
123
+
124
+ if (!window.CLIPSPACE_TO_OSS_MAP[firstMaskKey]) {
125
+ // 首次 mask 上传,保存到所有变体
126
+ window.CLIPSPACE_TO_OSS_MAP[firstMaskKey] = ossUrl;
127
+ finalUrl = ossUrl;
128
+
129
+ [`clipspace-mask-${baseId}.png`, `clipspace-paint-${baseId}.png`,
130
+ `clipspace-painted-${baseId}.png`, `clipspace-painted-masked-${baseId}.png`
131
+ ].forEach(v => window.CLIPSPACE_TO_OSS_MAP[v] = ossUrl);
132
+
133
+ console.log('[BizyDraft Upload] ✅ First mask upload, saved to all variants');
134
+ } else {
135
+ // 后续 mask 上传,使用首次的 URL
136
+ finalUrl = window.CLIPSPACE_TO_OSS_MAP[firstMaskKey];
137
+ console.log('[BizyDraft Upload] ⏭️ Later mask upload, using first URL');
138
+ }
139
+ } else if (baseId) {
140
+ // /upload/image 的上传,如果已有 mask 则使用 mask 的 URL
141
+ const firstMaskUrl = window.CLIPSPACE_TO_OSS_MAP[`__FIRST_MASK_${baseId}__`];
142
+ if (firstMaskUrl) {
143
+ finalUrl = firstMaskUrl;
144
+ console.log('[BizyDraft Upload] 📎 Image upload, using first mask URL');
145
+ } else {
146
+ console.log('[BizyDraft Upload] ⏳ Image upload, awaiting mask');
37
147
  }
38
148
  }
149
+
150
+ // 保存映射
151
+ [filename, `${filename} [input]`, `${filename} [output]`].forEach(key => {
152
+ window.CLIPSPACE_TO_OSS_MAP[key] = finalUrl;
153
+ });
154
+
155
+ const filenameWithoutSuffix = filename.replace(/ \[(input|output)\]$/, '');
156
+ if (filenameWithoutSuffix !== filename) {
157
+ window.CLIPSPACE_TO_OSS_MAP[filenameWithoutSuffix] = finalUrl;
158
+ }
159
+
160
+ console.log('[BizyDraft Upload] 💾 Mapped:', filename, '->', finalUrl);
39
161
  }
40
- } catch (e) {
41
- console.warn('[BizyDraft ClipspaceToOss] Failed to parse upload response:', e);
42
162
  }
43
- }
44
163
 
45
- return response;
164
+ // 同时保存后端返回的文件名映射
165
+ window.CLIPSPACE_TO_OSS_MAP[data.name] = finalUrl;
166
+
167
+ // 篡改响应,让 ComfyUI 使用完整的 OSS URL
168
+ const modifiedData = { ...data, name: finalUrl, subfolder: '' };
169
+ console.log('[BizyDraft Upload] ✅ Response modified');
170
+ console.log('═══════════════════════════════════════════════════════\n');
171
+
172
+ return new Response(JSON.stringify(modifiedData), {
173
+ status: response.status,
174
+ statusText: response.statusText,
175
+ headers: response.headers
176
+ });
177
+
178
+ } catch (e) {
179
+ console.error('[BizyDraft Upload] ❌ Error:', e);
180
+ return response;
181
+ }
46
182
  };
47
183
 
48
- /**
49
- * Convert clipspace paths to OSS URLs in a prompt object
50
- * @param {Object} prompt - The prompt object to process
51
- * @returns {Object} The processed prompt object
52
- */
184
+ // 转换 prompt 中的 clipspace 路径为 OSS URL
53
185
  function convertClipspacePathsInPrompt(prompt) {
54
186
  if (!prompt || typeof prompt !== 'object') {
55
187
  return prompt;
@@ -57,46 +189,25 @@ function convertClipspacePathsInPrompt(prompt) {
57
189
 
58
190
  let conversionsCount = 0;
59
191
 
60
- // Iterate through all nodes in the prompt
61
192
  for (const [nodeId, node] of Object.entries(prompt)) {
62
- if (!node || !node.inputs) {
63
- continue;
64
- }
193
+ if (!node?.inputs) continue;
65
194
 
66
- // Check all input values
67
195
  for (const [inputKey, inputValue] of Object.entries(node.inputs)) {
68
196
  if (typeof inputValue === 'string' && inputValue.includes('clipspace')) {
69
- // Extract the filename from paths like:
70
- // "clipspace/clipspace-mask-12345.png [input]"
71
- // "clipspace/clipspace-painted-masked-12345.png [input]"
72
197
  const match = inputValue.match(/clipspace\/([\w-]+\.(?:png|jpg|jpeg|webp|gif))/i);
73
198
  if (match) {
74
- const filename = match[1]; // e.g., "clipspace-mask-12345.png"
75
-
76
- // Look for this filename in our mapping (with or without [input]/[output] suffix)
77
- const filenameWithInput = `${filename} [input]`;
78
- const filenameWithOutput = `${filename} [output]`;
79
-
80
- let ossUrl = window.CLIPSPACE_TO_OSS_MAP[filename]
81
- || window.CLIPSPACE_TO_OSS_MAP[filenameWithInput]
82
- || window.CLIPSPACE_TO_OSS_MAP[filenameWithOutput];
199
+ const filename = match[1];
200
+ const ossUrl = findOssUrl(filename);
83
201
 
84
202
  if (ossUrl) {
85
- console.log(`[BizyDraft ClipspaceToOss] Converting: ${inputValue} -> ${ossUrl}`);
203
+ console.log('[BizyDraft Prompt] Converting:', inputValue, '->', ossUrl);
86
204
  node.inputs[inputKey] = ossUrl;
87
205
 
88
- // Also update image_name if it exists
89
206
  if (inputKey === 'image' && node.inputs['image_name']) {
90
- // Extract just the filename from the OSS URL
91
- const ossFilename = ossUrl.split('/').pop();
92
- node.inputs['image_name'] = ossFilename;
93
- console.log(`[BizyDraft ClipspaceToOss] Also updated image_name to: ${ossFilename}`);
207
+ node.inputs['image_name'] = ossUrl.split('/').pop();
94
208
  }
95
209
 
96
210
  conversionsCount++;
97
- } else {
98
- console.warn(`[BizyDraft ClipspaceToOss] No OSS URL found for clipspace file: ${filename}`);
99
- console.warn('[BizyDraft ClipspaceToOss] Available mappings:', Object.keys(window.CLIPSPACE_TO_OSS_MAP));
100
211
  }
101
212
  }
102
213
  }
@@ -104,12 +215,13 @@ function convertClipspacePathsInPrompt(prompt) {
104
215
  }
105
216
 
106
217
  if (conversionsCount > 0) {
107
- console.log(`[BizyDraft ClipspaceToOss] Converted ${conversionsCount} clipspace path(s) to OSS URLs`);
218
+ console.log(`[BizyDraft Prompt] Converted ${conversionsCount} path(s)`);
108
219
  }
109
220
 
110
221
  return prompt;
111
222
  }
112
223
 
224
+ // 注册 ComfyUI 扩展
113
225
  app.registerExtension({
114
226
  name: "bizyair.clipspace.to.oss",
115
227
 
@@ -117,15 +229,15 @@ app.registerExtension({
117
229
  const originalGraphToPrompt = app.graphToPrompt;
118
230
 
119
231
  app.graphToPrompt = async function(...args) {
120
- console.log('[BizyDraft ClipspaceToOss] graphToPrompt called, intercepting...');
121
-
122
232
  const result = await originalGraphToPrompt.apply(this, args);
123
233
 
124
- if (result && result.output) {
234
+ if (result?.output) {
125
235
  result.output = convertClipspacePathsInPrompt(result.output);
126
236
  }
127
237
 
128
238
  return result;
129
239
  };
240
+
241
+ console.log('[BizyDraft] Extension registered');
130
242
  }
131
243
  });
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bizydraft
3
- Version: 0.2.71
3
+ Version: 0.2.72.dev20251013070955
4
4
  Summary: bizydraft
5
5
  Requires-Dist: loguru
6
6
  Requires-Dist: aiohttp
@@ -4,14 +4,14 @@ bizydraft/env.py,sha256=VFmGopVL2TGWA6hwxyFhIglCEcQxy6iVvL_raMNd6u4,407
4
4
  bizydraft/hijack_nodes.py,sha256=GivcoUsYAOfMjoEMxeViEkSQlmYjMA0RORy04fCbG60,3652
5
5
  bizydraft/hijack_routes.py,sha256=wLu_PWUbUzhN2uZeayTAj1ShdLXVuKsp85a_FX1UCYY,3415
6
6
  bizydraft/oss_utils.py,sha256=JHpMA61NxFzA053y8IzBc01xxMJCF6G2PTHk-rXqIFo,15590
7
- bizydraft/patch_handlers.py,sha256=1aKOAAI1cCLBuQoym6le7GbW0rs_9_m_h7pCCg3xIz8,6574
7
+ bizydraft/patch_handlers.py,sha256=UQudnqKtDTYPnlS3Aq_k7txg7Je6ph9rkioou5-FgZI,6194
8
8
  bizydraft/postload.py,sha256=XFElKcmCajT_oO7SVJJBaN04XcWro54N5HB5cSCxfvI,1308
9
9
  bizydraft/prestartup_patch.py,sha256=4FGjmRcDHELjtlQOrfTfk2Un5OS89QIqfq-gEcB9WDs,998
10
10
  bizydraft/resp.py,sha256=8INvKOe5Dgai3peKfqKjrhUoYeuXWXn358w30-_cY-A,369
11
11
  bizydraft/server.py,sha256=L2zoJgOisr65IRphOyko74AdsLel59gh55peyMaUrO8,2102
12
12
  bizydraft/workflow_io.py,sha256=MYhJbpgkv8hrA5k_aolijOTrWpTtu62nzRznA4hv8JE,4298
13
13
  bizydraft/static/js/aiAppHandler.js,sha256=OQRhhoqvc8iZeCvHTtdaD2VTYBGzkeAGdCk1UMO2RZs,17525
14
- bizydraft/static/js/clipspaceToOss.js,sha256=l0mUiiTsbSZx1mNgDfT9WJaM9Ee-ebP2UcAwrnAquMQ,5355
14
+ bizydraft/static/js/clipspaceToOss.js,sha256=QEd14hbp-gvsK4EszThcVbsqmUeXt0hcxdfoQyZUpDg,10902
15
15
  bizydraft/static/js/freezeModeHandler.js,sha256=SjpHD2nYymR-E13B0YcqkA6e4WycZOVI3c48Ts9qvWE,18027
16
16
  bizydraft/static/js/handleStyle.js,sha256=liIzTu-wnV172g58gHWGLYTfd86xpJxL4A-HuHpFnq4,3616
17
17
  bizydraft/static/js/hookLoadImage.js,sha256=aFRWkgJW-Cp-YHjZh-3j-vsVcNaDZpBVoQqcFZ2Po0g,8186
@@ -24,7 +24,7 @@ bizydraft/static/js/socket.js,sha256=VE3fTAgEfM0FZhL526Skt7OCRokOa3mzTCAjAomI_tE
24
24
  bizydraft/static/js/tool.js,sha256=VupamUuh7tYiDnBTrL5Z_yLmhJinskhzRXwE3zfsKZM,2901
25
25
  bizydraft/static/js/uploadFile.js,sha256=WvglKzHMeOzDhOH3P-fLcPHxCLbKOJpo4DntoRxeJtI,4908
26
26
  bizydraft/static/js/workflow_io.js,sha256=FWAjncvWhvy-3nN_legD2fpRwgnIncpRLHU5X016a-U,5236
27
- bizydraft-0.2.71.dist-info/METADATA,sha256=oGd700wcCxrsNZSUgsP7MdtRSHoGusF2A3FUdvuDfcI,162
28
- bizydraft-0.2.71.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
- bizydraft-0.2.71.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
30
- bizydraft-0.2.71.dist-info/RECORD,,
27
+ bizydraft-0.2.72.dev20251013070955.dist-info/METADATA,sha256=KIlZZuVsJrep6mJiYaeN-WJEtOFpDK6x5-lH-wF61XQ,180
28
+ bizydraft-0.2.72.dev20251013070955.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
29
+ bizydraft-0.2.72.dev20251013070955.dist-info/top_level.txt,sha256=XtoBq6hjZhXIM7aas4GtPDtAiKo8FdLzMABXW8qqQ8M,10
30
+ bizydraft-0.2.72.dev20251013070955.dist-info/RECORD,,