The viewer JS/HTML/bundles are now committed in javascript/ (declared via pyproject [tool.comfy] web = "javascript") instead of being copied from the shared comfy-3d-viewers pip package at prestartup. Consequences: - requirements.txt is now just comfy-env (host env installs nothing else, per the never-touch-the-host-env principle) - prestartup_script.py no longer copies viewers or web_src; it keeps only setup_env() and the input-asset copies - WEB_DIRECTORY attribute removed; the pyproject declaration is the single source (served at /extensions/comfyui-geometrypack/, keyed by project name) - web_src/ deleted; its 6 widgets now live in javascript/js/ as the tracked source, edited directly - viewer_pbr.html hardcoded-fallback URL updated to the new mount name Iframe URLs auto-detect the mount from import.meta.url, so the folder rename and mount-name change are transparent at runtime.
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
/**
|
|
* Screenshot capture and upload utility for ComfyUI viewers
|
|
*/
|
|
|
|
/**
|
|
* Convert base64 data URL to Blob
|
|
* @param {string} dataUrl - Base64 data URL (e.g., "data:image/png;base64,...")
|
|
* @returns {Blob} PNG image blob
|
|
*/
|
|
export function dataUrlToBlob(dataUrl) {
|
|
const base64Data = dataUrl.split(',')[1];
|
|
const byteString = atob(base64Data);
|
|
const arrayBuffer = new ArrayBuffer(byteString.length);
|
|
const uint8Array = new Uint8Array(arrayBuffer);
|
|
|
|
for (let i = 0; i < byteString.length; i++) {
|
|
uint8Array[i] = byteString.charCodeAt(i);
|
|
}
|
|
|
|
return new Blob([uint8Array], { type: 'image/png' });
|
|
}
|
|
|
|
/**
|
|
* Upload screenshot to ComfyUI backend
|
|
* @param {string} dataUrl - Base64 data URL of the screenshot
|
|
* @param {string} prefix - Filename prefix (e.g., "vtk-screenshot")
|
|
* @returns {Promise<{name: string, subfolder: string, type: string}>} Upload result
|
|
*/
|
|
export async function uploadScreenshot(dataUrl, prefix = 'screenshot') {
|
|
const blob = dataUrlToBlob(dataUrl);
|
|
|
|
// Generate filename with timestamp
|
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
const filename = `${prefix}-${timestamp}.png`;
|
|
|
|
// Create FormData for upload
|
|
const formData = new FormData();
|
|
formData.append('image', blob, filename);
|
|
formData.append('type', 'output'); // Save to output directory
|
|
formData.append('subfolder', ''); // Root of output folder
|
|
|
|
// Upload to ComfyUI backend
|
|
const response = await fetch('/upload/image', {
|
|
method: 'POST',
|
|
body: formData
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`Upload failed: ${response.status} ${response.statusText}`);
|
|
}
|
|
|
|
return response.json();
|
|
}
|
|
|
|
/**
|
|
* Create a message handler for screenshot events from iframe
|
|
* @param {string} prefix - Filename prefix for screenshots
|
|
* @param {Function} onError - Error callback
|
|
* @returns {Function} Event handler function
|
|
*/
|
|
export function createScreenshotHandler(prefix = 'screenshot', onError = console.error) {
|
|
return async (event) => {
|
|
if (event.data.type === 'SCREENSHOT' && event.data.image) {
|
|
try {
|
|
await uploadScreenshot(event.data.image, prefix);
|
|
} catch (error) {
|
|
onError(`Error saving screenshot: ${error}`);
|
|
}
|
|
}
|
|
};
|
|
}
|