34 lines
1004 B
JavaScript
34 lines
1004 B
JavaScript
/**
|
|
* File upload and image loading utilities
|
|
*/
|
|
|
|
/**
|
|
* Upload an image file to ComfyUI server
|
|
* @param {File} file - Image file to upload
|
|
* @returns {Promise<Object>} Upload response with filename and subfolder
|
|
*/
|
|
export async function uploadImageFile(file) {
|
|
const body = new FormData();
|
|
body.append("image", file);
|
|
body.append("overwrite", "true");
|
|
const resp = await fetch("/upload/image", { method: "POST", body });
|
|
if (!resp.ok) {
|
|
throw new Error(`Failed to upload image: ${resp.statusText}`);
|
|
}
|
|
return resp.json();
|
|
}
|
|
|
|
/**
|
|
* Load an image asynchronously from a URL
|
|
* @param {string} imageURL - URL of the image to load
|
|
* @returns {Promise<HTMLImageElement>} Loaded image element
|
|
*/
|
|
export async function loadImageAsync(imageURL) {
|
|
return new Promise((resolve) => {
|
|
const img = new Image();
|
|
img.setAttribute("crossorigin", "anonymous");
|
|
img.addEventListener("load", () => resolve(img));
|
|
img.src = imageURL;
|
|
});
|
|
}
|