Update index.html
Browse files- index.html +35 -16
index.html
CHANGED
|
@@ -67,6 +67,7 @@
|
|
| 67 |
justify-content: center;
|
| 68 |
align-items: center;
|
| 69 |
background-color: #fafafa;
|
|
|
|
| 70 |
}
|
| 71 |
#qr-image {
|
| 72 |
max-width: 100%;
|
|
@@ -94,7 +95,7 @@
|
|
| 94 |
<!-- بخش ساخت QR Code -->
|
| 95 |
<div class="container">
|
| 96 |
<h2>ساخت QR Code</h2>
|
| 97 |
-
<textarea id="text-input" placeholder="متن مورد نظر را اینجا وارد کنید..." rows="4"
|
| 98 |
<button id="generate-btn" onclick="generateQRCode()">ساخت کد</button>
|
| 99 |
<div id="generate-result" class="result-box">
|
| 100 |
<div id="generate-loader" class="loader hidden"></div>
|
|
@@ -115,7 +116,8 @@
|
|
| 115 |
</div>
|
| 116 |
|
| 117 |
<script>
|
| 118 |
-
|
|
|
|
| 119 |
|
| 120 |
// یک session_hash تصادفی ایجاد میکند
|
| 121 |
function generateSessionHash() {
|
|
@@ -146,20 +148,36 @@
|
|
| 146 |
reject(new Error("Failed to get data."));
|
| 147 |
return;
|
| 148 |
}
|
| 149 |
-
const result = await dataResponse.json();
|
| 150 |
|
| 151 |
-
//
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
}
|
| 159 |
-
//
|
|
|
|
| 160 |
} catch (error) {
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
| 163 |
}
|
| 164 |
}, 1000); // هر ۱ ثانیه چک کن
|
| 165 |
});
|
|
@@ -189,7 +207,8 @@
|
|
| 189 |
const result = await callGradioApi(0, data, sessionHash); // fn_index=0 برای ساخت
|
| 190 |
|
| 191 |
if (result.output && result.output.data && result.output.data[0]) {
|
| 192 |
-
|
|
|
|
| 193 |
qrImage.src = imageUrl;
|
| 194 |
qrImage.classList.remove('hidden');
|
| 195 |
} else {
|
|
@@ -234,13 +253,13 @@
|
|
| 234 |
if (!uploadResponse.ok) throw new Error("آپلود فایل با خطا مواجه شد.");
|
| 235 |
|
| 236 |
const uploadResult = await uploadResponse.json();
|
| 237 |
-
const tempFilePath = uploadResult[0];
|
| 238 |
|
| 239 |
// Step 2: Call the API with the uploaded file path
|
| 240 |
const sessionHash = generateSessionHash();
|
| 241 |
const data = [{
|
| 242 |
"path": tempFilePath,
|
| 243 |
-
"url":
|
| 244 |
"orig_name": file.name,
|
| 245 |
"size": file.size,
|
| 246 |
"mime_type": file.type,
|
|
|
|
| 67 |
justify-content: center;
|
| 68 |
align-items: center;
|
| 69 |
background-color: #fafafa;
|
| 70 |
+
word-break: break-all;
|
| 71 |
}
|
| 72 |
#qr-image {
|
| 73 |
max-width: 100%;
|
|
|
|
| 95 |
<!-- بخش ساخت QR Code -->
|
| 96 |
<div class="container">
|
| 97 |
<h2>ساخت QR Code</h2>
|
| 98 |
+
<textarea id="text-input" placeholder="متن مورد نظر را اینجا وارد کنید..." rows="4"></textarea>
|
| 99 |
<button id="generate-btn" onclick="generateQRCode()">ساخت کد</button>
|
| 100 |
<div id="generate-result" class="result-box">
|
| 101 |
<div id="generate-loader" class="loader hidden"></div>
|
|
|
|
| 116 |
</div>
|
| 117 |
|
| 118 |
<script>
|
| 119 |
+
// *** مهم: آدرس API مطابق با اسکرین شات شما تغییر کرد ***
|
| 120 |
+
const API_BASE_URL = "https://elias207-qrcode.hf.space/";
|
| 121 |
|
| 122 |
// یک session_hash تصادفی ایجاد میکند
|
| 123 |
function generateSessionHash() {
|
|
|
|
| 148 |
reject(new Error("Failed to get data."));
|
| 149 |
return;
|
| 150 |
}
|
|
|
|
| 151 |
|
| 152 |
+
// --- بخش اصلاح شده ---
|
| 153 |
+
// پاسخ را به عنوان متن می خوانیم
|
| 154 |
+
const responseText = await dataResponse.text();
|
| 155 |
+
|
| 156 |
+
// ممکن است چندین پیام در استریم باشد، آخرین پیام را پردازش می کنیم
|
| 157 |
+
const lines = responseText.trim().split('\n');
|
| 158 |
+
const lastLine = lines[lines.length - 1];
|
| 159 |
+
|
| 160 |
+
if (lastLine && lastLine.startsWith('data:')) {
|
| 161 |
+
// پیشوند 'data: ' را حذف کرده و نتیجه را به JSON تبدیل می کنیم
|
| 162 |
+
const jsonString = lastLine.substring(5).trim();
|
| 163 |
+
const result = JSON.parse(jsonString);
|
| 164 |
+
|
| 165 |
+
if (result.msg === "process_completed") {
|
| 166 |
+
clearInterval(interval);
|
| 167 |
+
resolve(result);
|
| 168 |
+
} else if (result.msg === "queue_full" || result.msg === "unexpected_error") {
|
| 169 |
+
clearInterval(interval);
|
| 170 |
+
reject(new Error("API Error: " + result.msg));
|
| 171 |
+
}
|
| 172 |
}
|
| 173 |
+
// --- پایان بخش اصلاح شده ---
|
| 174 |
+
|
| 175 |
} catch (error) {
|
| 176 |
+
// اگر خطا در حین پارس کردن رخ دهد (مثلا پیام کامل نباشد)، منتظر درخواست بعدی می مانیم
|
| 177 |
+
if (!(error instanceof SyntaxError)) {
|
| 178 |
+
clearInterval(interval);
|
| 179 |
+
reject(error);
|
| 180 |
+
}
|
| 181 |
}
|
| 182 |
}, 1000); // هر ۱ ثانیه چک کن
|
| 183 |
});
|
|
|
|
| 207 |
const result = await callGradioApi(0, data, sessionHash); // fn_index=0 برای ساخت
|
| 208 |
|
| 209 |
if (result.output && result.output.data && result.output.data[0]) {
|
| 210 |
+
// Gradio آدرس فایل را به صورت نسبی برمیگرداند، ما آن را کامل میکنیم
|
| 211 |
+
const imageUrl = API_BASE_URL + "file=" + result.output.data[0].path;
|
| 212 |
qrImage.src = imageUrl;
|
| 213 |
qrImage.classList.remove('hidden');
|
| 214 |
} else {
|
|
|
|
| 253 |
if (!uploadResponse.ok) throw new Error("آپلود فایل با خطا مواجه شد.");
|
| 254 |
|
| 255 |
const uploadResult = await uploadResponse.json();
|
| 256 |
+
const tempFilePath = uploadResult[0];
|
| 257 |
|
| 258 |
// Step 2: Call the API with the uploaded file path
|
| 259 |
const sessionHash = generateSessionHash();
|
| 260 |
const data = [{
|
| 261 |
"path": tempFilePath,
|
| 262 |
+
"url": API_BASE_URL + "file=" + tempFilePath,
|
| 263 |
"orig_name": file.name,
|
| 264 |
"size": file.size,
|
| 265 |
"mime_type": file.type,
|