|
@@ -1,10 +1,10 @@
|
|
|
"use client";
|
|
"use client";
|
|
|
|
|
|
|
|
-import { useState, useRef, useEffect } from "react";
|
|
|
|
|
|
|
+import { useState, useEffect } from "react";
|
|
|
import { Header, AppLayout } from "@/components/layout";
|
|
import { Header, AppLayout } from "@/components/layout";
|
|
|
import { Button } from "@/components/ui/button";
|
|
import { Button } from "@/components/ui/button";
|
|
|
import { Input } from "@/components/ui/input";
|
|
import { Input } from "@/components/ui/input";
|
|
|
-import { Textarea } from "@/components/ui/textarea";
|
|
|
|
|
|
|
+
|
|
|
import { PromptTextarea } from "@/components/forms";
|
|
import { PromptTextarea } from "@/components/forms";
|
|
|
import { Label } from "@/components/ui/label";
|
|
import { Label } from "@/components/ui/label";
|
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
@@ -47,7 +47,7 @@ const defaultFormData: Img2ImgFormData = {
|
|
|
|
|
|
|
|
function Img2ImgForm() {
|
|
function Img2ImgForm() {
|
|
|
// Store form data without the image to avoid localStorage quota issues
|
|
// Store form data without the image to avoid localStorage quota issues
|
|
|
- const { image: _, ...formDataWithoutImage } = defaultFormData;
|
|
|
|
|
|
|
+ const { ...formDataWithoutImage } = defaultFormData;
|
|
|
const [formData, setFormData] = useLocalStorage<
|
|
const [formData, setFormData] = useLocalStorage<
|
|
|
Omit<Img2ImgFormData, "image">
|
|
Omit<Img2ImgFormData, "image">
|
|
|
>("img2img-form-data", formDataWithoutImage);
|
|
>("img2img-form-data", formDataWithoutImage);
|
|
@@ -61,7 +61,7 @@ function Img2ImgForm() {
|
|
|
const [loading, setLoading] = useState(false);
|
|
const [loading, setLoading] = useState(false);
|
|
|
const [jobInfo, setJobInfo] = useState<JobInfo | null>(null);
|
|
const [jobInfo, setJobInfo] = useState<JobInfo | null>(null);
|
|
|
const [generatedImages, setGeneratedImages] = useState<string[]>([]);
|
|
const [generatedImages, setGeneratedImages] = useState<string[]>([]);
|
|
|
- const [previewImage, setPreviewImage] = useState<string | null>(null);
|
|
|
|
|
|
|
+
|
|
|
const [loraModels, setLoraModels] = useState<string[]>([]);
|
|
const [loraModels, setLoraModels] = useState<string[]>([]);
|
|
|
const [embeddings, setEmbeddings] = useState<string[]>([]);
|
|
const [embeddings, setEmbeddings] = useState<string[]>([]);
|
|
|
const [selectedImage, setSelectedImage] = useState<File | string | null>(
|
|
const [selectedImage, setSelectedImage] = useState<File | string | null>(
|
|
@@ -125,7 +125,7 @@ function Img2ImgForm() {
|
|
|
if (!image) {
|
|
if (!image) {
|
|
|
setImageData("");
|
|
setImageData("");
|
|
|
setFormData((prev) => ({ ...prev, image: "" }));
|
|
setFormData((prev) => ({ ...prev, image: "" }));
|
|
|
- setPreviewImage(null);
|
|
|
|
|
|
|
+
|
|
|
setImageValidation(null);
|
|
setImageValidation(null);
|
|
|
setOriginalImage(null);
|
|
setOriginalImage(null);
|
|
|
return;
|
|
return;
|
|
@@ -155,7 +155,7 @@ function Img2ImgForm() {
|
|
|
if (image instanceof File) {
|
|
if (image instanceof File) {
|
|
|
setOriginalImage(imageBase64);
|
|
setOriginalImage(imageBase64);
|
|
|
setImageData(imageBase64);
|
|
setImageData(imageBase64);
|
|
|
- setPreviewImage(previewUrl);
|
|
|
|
|
|
|
+ ;
|
|
|
}
|
|
}
|
|
|
setFormData((prev) => ({ ...prev })); // Don't store image in localStorage
|
|
setFormData((prev) => ({ ...prev })); // Don't store image in localStorage
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
@@ -207,7 +207,7 @@ function Img2ImgForm() {
|
|
|
);
|
|
);
|
|
|
setImageData(result.image);
|
|
setImageData(result.image);
|
|
|
setFormData((prev) => ({ ...prev })); // Don't store image in localStorage
|
|
setFormData((prev) => ({ ...prev })); // Don't store image in localStorage
|
|
|
- setPreviewImage(result.image);
|
|
|
|
|
|
|
+ ;
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
console.error("Failed to resize image:", err);
|
|
console.error("Failed to resize image:", err);
|
|
|
const errorMessage =
|
|
const errorMessage =
|
|
@@ -227,6 +227,8 @@ function Img2ImgForm() {
|
|
|
originalImage,
|
|
originalImage,
|
|
|
imageLoadingFromUrl,
|
|
imageLoadingFromUrl,
|
|
|
isResizing,
|
|
isResizing,
|
|
|
|
|
+ setFormData,
|
|
|
|
|
+ setImageData,
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
const handleImageValidation = (result: ImageValidationResult) => {
|
|
const handleImageValidation = (result: ImageValidationResult) => {
|
|
@@ -244,7 +246,7 @@ function Img2ImgForm() {
|
|
|
? `${window.location.origin}${result.tempUrl}`
|
|
? `${window.location.origin}${result.tempUrl}`
|
|
|
: result.tempUrl;
|
|
: result.tempUrl;
|
|
|
|
|
|
|
|
- setPreviewImage(fullTempUrl);
|
|
|
|
|
|
|
+ ;
|
|
|
setOriginalImage(fullTempUrl);
|
|
setOriginalImage(fullTempUrl);
|
|
|
|
|
|
|
|
// For processing, we still need to convert to base64 or use the URL directly
|
|
// For processing, we still need to convert to base64 or use the URL directly
|
|
@@ -262,7 +264,7 @@ function Img2ImgForm() {
|
|
|
result.base64Data.startsWith("data:image/") &&
|
|
result.base64Data.startsWith("data:image/") &&
|
|
|
result.base64Data.includes("base64,")
|
|
result.base64Data.includes("base64,")
|
|
|
) {
|
|
) {
|
|
|
- setPreviewImage(result.base64Data);
|
|
|
|
|
|
|
+ ;
|
|
|
setImageData(result.base64Data);
|
|
setImageData(result.base64Data);
|
|
|
setOriginalImage(result.base64Data);
|
|
setOriginalImage(result.base64Data);
|
|
|
console.log(
|
|
console.log(
|
|
@@ -304,7 +306,7 @@ function Img2ImgForm() {
|
|
|
// Handle both old format (result.images) and new format (outputs)
|
|
// Handle both old format (result.images) and new format (outputs)
|
|
|
if (status.job.outputs && status.job.outputs.length > 0) {
|
|
if (status.job.outputs && status.job.outputs.length > 0) {
|
|
|
// New format: convert output URLs to authenticated image URLs with cache-busting
|
|
// New format: convert output URLs to authenticated image URLs with cache-busting
|
|
|
- imageUrls = status.job.outputs.map((output: any) => {
|
|
|
|
|
|
|
+ imageUrls = status.job.outputs.map((output: { filename: string }) => {
|
|
|
const filename = output.filename;
|
|
const filename = output.filename;
|
|
|
return apiClient.getImageUrl(jobId, filename);
|
|
return apiClient.getImageUrl(jobId, filename);
|
|
|
});
|
|
});
|