Opera8 commited on
Commit
48bf5a1
·
verified ·
1 Parent(s): 7227da4

Update templates/ltxvideo.html

Browse files
Files changed (1) hide show
  1. templates/ltxvideo.html +29 -25
templates/ltxvideo.html CHANGED
@@ -953,16 +953,27 @@
953
  }
954
  async function checkFreeUserCredit() {
955
  if (!userFingerprint) return; const creditInfoDiv = document.getElementById('credit-info-section'); const upgradeBtn = document.getElementById('upgrade-button'); const genBtn = document.getElementById('generateButton');
956
- try {
957
- const response = await fetch('/api/check-credit', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ fingerprint: userFingerprint }) });
958
- const result = await response.json();
959
- if (userSubscriptionStatus !== 'paid') { creditInfoDiv.style.display = 'block'; }
960
- if (result.limit_reached) {
961
- genBtn.disabled = true; upgradeBtn.style.display = 'block'; startCountdown(result.reset_timestamp);
962
- } else {
963
- genBtn.disabled = false; upgradeBtn.style.display = 'none'; if(countdownInterval) clearInterval(countdownInterval); creditInfoDiv.textContent = `شما ${result.credits_remaining} اعتبار ساخت ویدیوی رایگان در این هفته دارید.`;
964
- }
965
- } catch (error) { creditInfoDiv.textContent = "خطا در بررسی اعتبار."; genBtn.disabled = true; }
 
 
 
 
 
 
 
 
 
 
 
966
  }
967
  function startCountdown(resetTimestamp) {
968
  if (countdownInterval) clearInterval(countdownInterval); const creditInfoDiv = document.getElementById('credit-info-section');
@@ -1228,11 +1239,7 @@
1228
  }
1229
 
1230
  if (userSubscriptionStatus === 'free') {
1231
- await fetch('/api/use-credit', {
1232
- method: 'POST',
1233
- headers: {'Content-Type': 'application/json'},
1234
- body: JSON.stringify({ fingerprint: userFingerprint })
1235
- });
1236
  checkFreeUserCredit();
1237
  }
1238
 
@@ -1585,19 +1592,16 @@
1585
  }
1586
 
1587
  if (userSubscriptionStatus !== 'paid') {
1588
- try {
1589
- const response = await fetch('/api/check-credit', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ fingerprint: userFingerprint }) });
1590
- const result = await response.json();
1591
- if (result.limit_reached) {
1592
- updateUIForSubscriptionStatus('free');
1593
- alert("محدودیت ساخت ویدیوی رایگان شما برای این هفته به پایان رسیده است.");
 
1594
  setUiLock(false);
1595
  return;
1596
  }
1597
- } catch (err) {
1598
- alert(!navigator.onLine ? "عدم اتصال به اینترنت." : "خطا در سیستم اعتبار سنجی.");
1599
- setUiLock(false);
1600
- return;
1601
  }
1602
  }
1603
 
 
953
  }
954
  async function checkFreeUserCredit() {
955
  if (!userFingerprint) return; const creditInfoDiv = document.getElementById('credit-info-section'); const upgradeBtn = document.getElementById('upgrade-button'); const genBtn = document.getElementById('generateButton');
956
+ if (userSubscriptionStatus !== 'paid') { creditInfoDiv.style.display = 'block'; }
957
+
958
+ const lastGen = localStorage.getItem('ltx_last_gen_time');
959
+ if (lastGen && userSubscriptionStatus !== 'paid') {
960
+ const lastGenTime = parseInt(lastGen, 10);
961
+ const now = Date.now();
962
+ const oneDayMs = 24 * 60 * 60 * 1000;
963
+ const timeLeft = lastGenTime + oneDayMs - now;
964
+
965
+ if (timeLeft > 0) {
966
+ genBtn.disabled = true;
967
+ upgradeBtn.style.display = 'block';
968
+ startCountdown(Math.floor((lastGenTime + oneDayMs) / 1000));
969
+ return;
970
+ }
971
+ }
972
+
973
+ genBtn.disabled = false;
974
+ upgradeBtn.style.display = 'none';
975
+ if(countdownInterval) clearInterval(countdownInterval);
976
+ creditInfoDiv.textContent = `شما ۱ اعتبار ساخت ویدیوی رایگان روزانه دارید.`;
977
  }
978
  function startCountdown(resetTimestamp) {
979
  if (countdownInterval) clearInterval(countdownInterval); const creditInfoDiv = document.getElementById('credit-info-section');
 
1239
  }
1240
 
1241
  if (userSubscriptionStatus === 'free') {
1242
+ localStorage.setItem('ltx_last_gen_time', Date.now().toString());
 
 
 
 
1243
  checkFreeUserCredit();
1244
  }
1245
 
 
1592
  }
1593
 
1594
  if (userSubscriptionStatus !== 'paid') {
1595
+ const lastGen = localStorage.getItem('ltx_last_gen_time');
1596
+ if (lastGen) {
1597
+ const lastGenTime = parseInt(lastGen, 10);
1598
+ const now = Date.now();
1599
+ const oneDayMs = 24 * 60 * 60 * 1000;
1600
+ if (lastGenTime + oneDayMs > now) {
1601
+ alert("محدودیت ساخت ویدیوی رایگان شما برای امروز به پایان رسیده است.");
1602
  setUiLock(false);
1603
  return;
1604
  }
 
 
 
 
1605
  }
1606
  }
1607