Spaces:
Running
Running
fix: restore 3 upload slots (product, background, model)
Browse files
frontend/src/pages/ListingFree.jsx
CHANGED
|
@@ -18,6 +18,10 @@ export default function ListingFree() {
|
|
| 18 |
const [sessionId, setSessionId] = useState(null);
|
| 19 |
const [productFile, setProductFile] = useState(null);
|
| 20 |
const [productPreview, setProductPreview] = useState(null);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
const [results, setResults] = useState([]);
|
| 22 |
const [status, setStatus] = useState(null);
|
| 23 |
const [logs, setLogs] = useState([]);
|
|
@@ -41,33 +45,49 @@ export default function ListingFree() {
|
|
| 41 |
|
| 42 |
const pollRef = useRef(null);
|
| 43 |
const prodRef = useRef(null);
|
|
|
|
|
|
|
| 44 |
const lastMsgRef = useRef("");
|
| 45 |
|
| 46 |
useEffect(() => {
|
| 47 |
return () => {
|
| 48 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
|
|
|
|
|
|
| 49 |
if (pollRef.current) clearTimeout(pollRef.current);
|
| 50 |
};
|
| 51 |
-
}, [productPreview]);
|
| 52 |
|
| 53 |
useEffect(() => { try { localStorage.setItem("tnt_wangp_url", wangpUrl); } catch {} }, [wangpUrl]);
|
| 54 |
useEffect(() => { try { localStorage.setItem("tnt_openai_key", openaiKey); } catch {} }, [openaiKey]);
|
| 55 |
|
| 56 |
const addLog = (level, msg) => setLogs(prev => [...prev, `[${new Date().toLocaleTimeString()}] ${msg}`]);
|
| 57 |
|
| 58 |
-
const
|
| 59 |
if (!f || !f.type.startsWith("image/")) return;
|
| 60 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
| 61 |
setProductFile(f); setProductPreview(URL.createObjectURL(f));
|
| 62 |
setSessionId(null); setResults([]); setLogs([]); setStatus(null);
|
| 63 |
setPrompts([]); setAutoPrompts(null); setGenerating(false); setBusy(false);
|
| 64 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
const startUpload = async () => {
|
| 67 |
if (!productFile || busy || generating) return;
|
| 68 |
setBusy(true); setStatus("Uploading..."); addLog("info", "Uploading...");
|
| 69 |
const fd = new FormData();
|
| 70 |
fd.append("product", productFile);
|
|
|
|
|
|
|
| 71 |
try {
|
| 72 |
const res = await fetch("/api/listing-free/upload", { method: "POST", body: fd });
|
| 73 |
const data = await res.json();
|
|
@@ -178,7 +198,9 @@ export default function ListingFree() {
|
|
| 178 |
setSessionId(null); setResults([]); setLogs([]); setStatus(null);
|
| 179 |
setPrompts([]); setAutoPrompts(null); setGenerating(false); setBusy(false);
|
| 180 |
if (productPreview) { URL.revokeObjectURL(productPreview); setProductPreview(null); }
|
| 181 |
-
|
|
|
|
|
|
|
| 182 |
};
|
| 183 |
|
| 184 |
return (
|
|
@@ -199,25 +221,35 @@ export default function ListingFree() {
|
|
| 199 |
|
| 200 |
{/* Upload */}
|
| 201 |
<div className="card">
|
| 202 |
-
<div className="panel-title"><IcUpload size={16} /> Upload
|
| 203 |
-
<div
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
<
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
</div>
|
| 216 |
-
)}
|
| 217 |
</div>
|
| 218 |
{productPreview && !sessionId && (
|
| 219 |
<button className="btn primary" style={{ marginTop: 8, width: "100%" }} disabled={busy} onClick={startUpload}>
|
| 220 |
-
{busy ? "Uploading..." : "Upload"}
|
| 221 |
</button>
|
| 222 |
)}
|
| 223 |
</div>
|
|
|
|
| 18 |
const [sessionId, setSessionId] = useState(null);
|
| 19 |
const [productFile, setProductFile] = useState(null);
|
| 20 |
const [productPreview, setProductPreview] = useState(null);
|
| 21 |
+
const [bgFile, setBgFile] = useState(null);
|
| 22 |
+
const [bgPreview, setBgPreview] = useState(null);
|
| 23 |
+
const [modelFile, setModelFile] = useState(null);
|
| 24 |
+
const [modelPreview, setModelPreview] = useState(null);
|
| 25 |
const [results, setResults] = useState([]);
|
| 26 |
const [status, setStatus] = useState(null);
|
| 27 |
const [logs, setLogs] = useState([]);
|
|
|
|
| 45 |
|
| 46 |
const pollRef = useRef(null);
|
| 47 |
const prodRef = useRef(null);
|
| 48 |
+
const bgRef = useRef(null);
|
| 49 |
+
const modelRef = useRef(null);
|
| 50 |
const lastMsgRef = useRef("");
|
| 51 |
|
| 52 |
useEffect(() => {
|
| 53 |
return () => {
|
| 54 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
| 55 |
+
if (bgPreview) URL.revokeObjectURL(bgPreview);
|
| 56 |
+
if (modelPreview) URL.revokeObjectURL(modelPreview);
|
| 57 |
if (pollRef.current) clearTimeout(pollRef.current);
|
| 58 |
};
|
| 59 |
+
}, [productPreview, bgPreview, modelPreview]);
|
| 60 |
|
| 61 |
useEffect(() => { try { localStorage.setItem("tnt_wangp_url", wangpUrl); } catch {} }, [wangpUrl]);
|
| 62 |
useEffect(() => { try { localStorage.setItem("tnt_openai_key", openaiKey); } catch {} }, [openaiKey]);
|
| 63 |
|
| 64 |
const addLog = (level, msg) => setLogs(prev => [...prev, `[${new Date().toLocaleTimeString()}] ${msg}`]);
|
| 65 |
|
| 66 |
+
const handleProductFile = (f) => {
|
| 67 |
if (!f || !f.type.startsWith("image/")) return;
|
| 68 |
if (productPreview) URL.revokeObjectURL(productPreview);
|
| 69 |
setProductFile(f); setProductPreview(URL.createObjectURL(f));
|
| 70 |
setSessionId(null); setResults([]); setLogs([]); setStatus(null);
|
| 71 |
setPrompts([]); setAutoPrompts(null); setGenerating(false); setBusy(false);
|
| 72 |
};
|
| 73 |
+
const handleBgFile = (f) => {
|
| 74 |
+
if (!f || !f.type.startsWith("image/")) return;
|
| 75 |
+
if (bgPreview) URL.revokeObjectURL(bgPreview);
|
| 76 |
+
setBgFile(f); setBgPreview(URL.createObjectURL(f));
|
| 77 |
+
};
|
| 78 |
+
const handleModelFile = (f) => {
|
| 79 |
+
if (!f || !f.type.startsWith("image/")) return;
|
| 80 |
+
if (modelPreview) URL.revokeObjectURL(modelPreview);
|
| 81 |
+
setModelFile(f); setModelPreview(URL.createObjectURL(f));
|
| 82 |
+
};
|
| 83 |
|
| 84 |
const startUpload = async () => {
|
| 85 |
if (!productFile || busy || generating) return;
|
| 86 |
setBusy(true); setStatus("Uploading..."); addLog("info", "Uploading...");
|
| 87 |
const fd = new FormData();
|
| 88 |
fd.append("product", productFile);
|
| 89 |
+
if (bgFile) fd.append("background", bgFile);
|
| 90 |
+
if (modelFile) fd.append("model", modelFile);
|
| 91 |
try {
|
| 92 |
const res = await fetch("/api/listing-free/upload", { method: "POST", body: fd });
|
| 93 |
const data = await res.json();
|
|
|
|
| 198 |
setSessionId(null); setResults([]); setLogs([]); setStatus(null);
|
| 199 |
setPrompts([]); setAutoPrompts(null); setGenerating(false); setBusy(false);
|
| 200 |
if (productPreview) { URL.revokeObjectURL(productPreview); setProductPreview(null); }
|
| 201 |
+
if (bgPreview) { URL.revokeObjectURL(bgPreview); setBgPreview(null); }
|
| 202 |
+
if (modelPreview) { URL.revokeObjectURL(modelPreview); setModelPreview(null); }
|
| 203 |
+
setProductFile(null); setBgFile(null); setModelFile(null);
|
| 204 |
};
|
| 205 |
|
| 206 |
return (
|
|
|
|
| 221 |
|
| 222 |
{/* Upload */}
|
| 223 |
<div className="card">
|
| 224 |
+
<div className="panel-title"><IcUpload size={16} /> Upload images</div>
|
| 225 |
+
<div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 8 }}>
|
| 226 |
+
{[
|
| 227 |
+
{ ref: prodRef, handler: handleProductFile, preview: productPreview, label: "Product image", required: true },
|
| 228 |
+
{ ref: bgRef, handler: handleBgFile, preview: bgPreview, label: "Background", required: false },
|
| 229 |
+
{ ref: modelRef, handler: handleModelFile, preview: modelPreview, label: "Model / Person", required: false },
|
| 230 |
+
].map(({ ref, handler, preview, label, required }) => (
|
| 231 |
+
<div key={label} className="dropzone" style={{ cursor: "pointer", padding: 8, display: "flex", flexDirection: "column" }}
|
| 232 |
+
onClick={() => ref.current?.click()}>
|
| 233 |
+
<input ref={ref} type="file" accept="image/jpeg,image/png,image/webp" style={{ display: "none" }}
|
| 234 |
+
onChange={(e) => handler(e.target.files?.[0])} />
|
| 235 |
+
{preview ? (
|
| 236 |
+
<div>
|
| 237 |
+
<img src={preview} alt="" style={{ width: "100%", aspectRatio: "1/1", borderRadius: 8, objectFit: "cover" }} />
|
| 238 |
+
<div style={{ fontSize: 11, textAlign: "center", marginTop: 4, color: "var(--muted)" }}>{label}</div>
|
| 239 |
+
</div>
|
| 240 |
+
) : (
|
| 241 |
+
<div style={{ textAlign: "center", padding: "20px 4px", flex: 1, display: "flex", flexDirection: "column", justifyContent: "center" }}>
|
| 242 |
+
<div className="chip" style={{ margin: "0 auto 6px" }}><IcImage size={18} /></div>
|
| 243 |
+
<div style={{ fontSize: 11, fontWeight: 600 }}>{label}</div>
|
| 244 |
+
{required && <div style={{ fontSize: 10, color: "var(--muted)", marginTop: 2 }}>Required</div>}
|
| 245 |
+
</div>
|
| 246 |
+
)}
|
| 247 |
</div>
|
| 248 |
+
))}
|
| 249 |
</div>
|
| 250 |
{productPreview && !sessionId && (
|
| 251 |
<button className="btn primary" style={{ marginTop: 8, width: "100%" }} disabled={busy} onClick={startUpload}>
|
| 252 |
+
{busy ? "Uploading..." : "Upload & Start"}
|
| 253 |
</button>
|
| 254 |
)}
|
| 255 |
</div>
|