Elias207 commited on
Commit
a69de9e
·
verified ·
1 Parent(s): d0d3f03

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +7 -12
index.html CHANGED
@@ -3,7 +3,7 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>کلاینت QR Code</title>
7
  <style>
8
  body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f0f2f5; display: flex; justify-content: center; align-items: flex-start; padding: 20px; gap: 30px; flex-wrap: wrap; }
9
  .container { background-color: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); width: 400px; }
@@ -22,7 +22,7 @@
22
 
23
  <div class="container">
24
  <h2>ساخت QR Code</h2>
25
- <textarea id="text-input" placeholder="متن مورد نظر را اینجا وارد کنید..." rows="4">موفقیت!</textarea>
26
  <button id="generate-btn" onclick="generateQRCode()">ساخت کد</button>
27
  <div class="result-box">
28
  <div id="generate-loader" class="loader hidden"></div>
@@ -42,7 +42,7 @@
42
  </div>
43
 
44
  <script>
45
- // این کد به API اسپیس cultrix-qrcode-read-generate متصل می‌شود که فعال است
46
  const API_ROOT_URL = "https://cultrix-qrcode-read-generate.hf.space/";
47
  const API_BASE_URL = API_ROOT_URL + "gradio_api/";
48
 
@@ -55,15 +55,10 @@
55
  });
56
 
57
  return new Promise((resolve, reject) => {
58
- const timeout = setTimeout(() => {
59
- clearInterval(interval);
60
- reject(new Error("پاسخی از سرور دریافت نشد (Timeout)."));
61
- }, 60000); // 60 ثانیه صبر می‌کند
62
-
63
  const interval = setInterval(async () => {
64
  try {
65
  const response = await fetch(API_BASE_URL + `queue/data?session_hash=${sessionHash}`);
66
- if (!response.ok) return;
67
 
68
  const text = await response.text();
69
  const lastLine = text.trim().split('\n').pop();
@@ -71,12 +66,12 @@
71
  if (lastLine && lastLine.startsWith('data:')) {
72
  const result = JSON.parse(lastLine.substring(5).trim());
73
  if (result.msg === "process_completed") {
74
- clearTimeout(timeout); clearInterval(interval); resolve(result);
75
  } else if (result.msg === "unexpected_error") {
76
- clearTimeout(timeout); clearInterval(interval); reject(new Error("API Error"));
77
  }
78
  }
79
- } catch (e) { /* Ignore parsing errors for incomplete streams */ }
80
  }, 1000);
81
  });
82
  }
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>کلاینت QR Code (اجرای محلی)</title>
7
  <style>
8
  body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f0f2f5; display: flex; justify-content: center; align-items: flex-start; padding: 20px; gap: 30px; flex-wrap: wrap; }
9
  .container { background-color: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); width: 400px; }
 
22
 
23
  <div class="container">
24
  <h2>ساخت QR Code</h2>
25
+ <textarea id="text-input" placeholder="متن مورد نظر را اینجا وارد کنید..." rows="4">این بار کار می‌کند!</textarea>
26
  <button id="generate-btn" onclick="generateQRCode()">ساخت کد</button>
27
  <div class="result-box">
28
  <div id="generate-loader" class="loader hidden"></div>
 
42
  </div>
43
 
44
  <script>
45
+ // آدرس اسپیسی که API آن فعال است
46
  const API_ROOT_URL = "https://cultrix-qrcode-read-generate.hf.space/";
47
  const API_BASE_URL = API_ROOT_URL + "gradio_api/";
48
 
 
55
  });
56
 
57
  return new Promise((resolve, reject) => {
 
 
 
 
 
58
  const interval = setInterval(async () => {
59
  try {
60
  const response = await fetch(API_BASE_URL + `queue/data?session_hash=${sessionHash}`);
61
+ if (!response.ok) { clearInterval(interval); reject(new Error("Network Error")); return; }
62
 
63
  const text = await response.text();
64
  const lastLine = text.trim().split('\n').pop();
 
66
  if (lastLine && lastLine.startsWith('data:')) {
67
  const result = JSON.parse(lastLine.substring(5).trim());
68
  if (result.msg === "process_completed") {
69
+ clearInterval(interval); resolve(result);
70
  } else if (result.msg === "unexpected_error") {
71
+ clearInterval(interval); reject(new Error("API Error"));
72
  }
73
  }
74
+ } catch (e) { if (!(e instanceof SyntaxError)) { clearInterval(interval); reject(e); } }
75
  }, 1000);
76
  });
77
  }