Update templates/image_studio.html
Browse files- templates/image_studio.html +14 -6
templates/image_studio.html
CHANGED
|
@@ -235,6 +235,7 @@
|
|
| 235 |
let userSubscriptionStatus = 'free';
|
| 236 |
let userFingerprint = null;
|
| 237 |
let countdownInterval = null;
|
|
|
|
| 238 |
const PREMIUM_PAGE_ID = '1149636'; // ID فرضی از کد قبلی شما
|
| 239 |
|
| 240 |
async function getBrowserFingerprint() {
|
|
@@ -294,7 +295,7 @@
|
|
| 294 |
genBtn.disabled = false;
|
| 295 |
upgradeBtn.style.display = 'none';
|
| 296 |
if(countdownInterval) clearInterval(countdownInterval);
|
| 297 |
-
creditInfoDiv.textContent = `شما ${result.credits_remaining} اعتبار ساخت تصویر رایگان
|
| 298 |
}
|
| 299 |
} catch (error) {
|
| 300 |
creditInfoDiv.textContent = "خطا در بررسی اعتبار.";
|
|
@@ -315,7 +316,7 @@
|
|
| 315 |
const d = Math.floor(timeLeft / 86400);
|
| 316 |
const h = Math.floor((timeLeft % 86400) / 3600);
|
| 317 |
const m = Math.floor((timeLeft % 3600) / 60);
|
| 318 |
-
creditInfoDiv.textContent = `اعتبار شما تمام شده. زمان باقیمانده
|
| 319 |
};
|
| 320 |
updateTimer(); countdownInterval = setInterval(updateTimer, 60000);
|
| 321 |
}
|
|
@@ -434,7 +435,7 @@
|
|
| 434 |
const result = await response.json();
|
| 435 |
if (result.limit_reached) {
|
| 436 |
updateUIForSubscriptionStatus('free');
|
| 437 |
-
alert("محدودیت ساخت عکس رایگان شما برای ا
|
| 438 |
return;
|
| 439 |
}
|
| 440 |
} catch (err) {
|
|
@@ -442,6 +443,7 @@
|
|
| 442 |
}
|
| 443 |
}
|
| 444 |
|
|
|
|
| 445 |
setLoadingState(true, 'در حال ترجمه متن و ارسال به سرور گرافیکی...');
|
| 446 |
const dims = getDimensions(selectedRatio);
|
| 447 |
|
|
@@ -487,11 +489,17 @@
|
|
| 487 |
const res = await fetch(`/api/status/${run_id}`);
|
| 488 |
const data = await res.json();
|
| 489 |
|
| 490 |
-
|
| 491 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
setLoadingState(false);
|
| 493 |
|
| 494 |
-
// کم کردن اعتبار برای کاربر رایگان
|
| 495 |
if (userSubscriptionStatus === 'free') {
|
| 496 |
try {
|
| 497 |
await fetch('/api/use-image-credit', {
|
|
|
|
| 235 |
let userSubscriptionStatus = 'free';
|
| 236 |
let userFingerprint = null;
|
| 237 |
let countdownInterval = null;
|
| 238 |
+
let isResultProcessed = false; // قفل برای جلوگیری از اجرای چندباره دریافت نتیجه
|
| 239 |
const PREMIUM_PAGE_ID = '1149636'; // ID فرضی از کد قبلی شما
|
| 240 |
|
| 241 |
async function getBrowserFingerprint() {
|
|
|
|
| 295 |
genBtn.disabled = false;
|
| 296 |
upgradeBtn.style.display = 'none';
|
| 297 |
if(countdownInterval) clearInterval(countdownInterval);
|
| 298 |
+
creditInfoDiv.textContent = `شما ${result.credits_remaining} اعتبار ساخت تصویر رایگان برای امروز دارید.`;
|
| 299 |
}
|
| 300 |
} catch (error) {
|
| 301 |
creditInfoDiv.textContent = "خطا در بررسی اعتبار.";
|
|
|
|
| 316 |
const d = Math.floor(timeLeft / 86400);
|
| 317 |
const h = Math.floor((timeLeft % 86400) / 3600);
|
| 318 |
const m = Math.floor((timeLeft % 3600) / 60);
|
| 319 |
+
creditInfoDiv.textContent = `اعتبار شما تمام شده. زمان باقیمانده شارژ روزانه: ${h} ساعت و ${m} دقیقه`;
|
| 320 |
};
|
| 321 |
updateTimer(); countdownInterval = setInterval(updateTimer, 60000);
|
| 322 |
}
|
|
|
|
| 435 |
const result = await response.json();
|
| 436 |
if (result.limit_reached) {
|
| 437 |
updateUIForSubscriptionStatus('free');
|
| 438 |
+
alert("محدودیت ساخت عکس رایگان شما برای امروز به پایان رسیده است.");
|
| 439 |
return;
|
| 440 |
}
|
| 441 |
} catch (err) {
|
|
|
|
| 443 |
}
|
| 444 |
}
|
| 445 |
|
| 446 |
+
isResultProcessed = false; // تنظیم مجدد قفل
|
| 447 |
setLoadingState(true, 'در حال ترجمه متن و ارسال به سرور گرافیکی...');
|
| 448 |
const dims = getDimensions(selectedRatio);
|
| 449 |
|
|
|
|
| 489 |
const res = await fetch(`/api/status/${run_id}`);
|
| 490 |
const data = await res.json();
|
| 491 |
|
| 492 |
+
// قفل جلوگیری از اجرای چندین باره کد و کم شدن متوالی اعتبار
|
| 493 |
+
if (data.status === 'ready' && !isResultProcessed) {
|
| 494 |
+
isResultProcessed = true;
|
| 495 |
+
|
| 496 |
+
if(pollTimer) {
|
| 497 |
+
clearInterval(pollTimer);
|
| 498 |
+
pollTimer = null;
|
| 499 |
+
}
|
| 500 |
setLoadingState(false);
|
| 501 |
|
| 502 |
+
// کم کردن اعتبار برای کاربر رایگان (فقط 1 بار)
|
| 503 |
if (userSubscriptionStatus === 'free') {
|
| 504 |
try {
|
| 505 |
await fetch('/api/use-image-credit', {
|