74c76309 by Administrator

Merge branch '31466_limited_usage_chatbot+' into 'master'

31466_limited_usage_chatbot+

See merge request !118
2 parents 7a230c24 59e26b28
Pipeline #29827 for 74c76309 passed in 16 seconds
...@@ -9,13 +9,15 @@ ...@@ -9,13 +9,15 @@
9 "react": "^18.2.0", 9 "react": "^18.2.0",
10 "react-dom": "^18.2.0", 10 "react-dom": "^18.2.0",
11 "react-scripts": "5.0.1", 11 "react-scripts": "5.0.1",
12 "serve": "^14.2.1",
12 "web-vitals": "^2.1.4" 13 "web-vitals": "^2.1.4"
13 }, 14 },
14 "scripts": { 15 "scripts": {
15 "start": "react-scripts start", 16 "start": "react-scripts start",
16 "build": "react-scripts build", 17 "build": "react-scripts build",
17 "test": "react-scripts test", 18 "test": "react-scripts test",
18 "eject": "react-scripts eject" 19 "eject": "react-scripts eject",
20 "serve": "serve -s build"
19 }, 21 },
20 "eslintConfig": { 22 "eslintConfig": {
21 "extends": [ 23 "extends": [
......
...@@ -131,14 +131,18 @@ function App() { ...@@ -131,14 +131,18 @@ function App() {
131 131
132 if(data.status === 'invalid'){ 132 if(data.status === 'invalid'){
133 if(data.limited) { 133 if(data.limited) {
134 window.btutil_maxUsage(); 134 window.btutil_modalRegisterUpgrade(false);
135 return; 135 return;
136 } 136 }
137 if(data && data.status === 'max-tokens') { 137 if(data && data.status === 'max-tokens') {
138 window.btutil_maxUsage(); 138 if(data.ent_member === 'yes') {
139 window.btutil_modalMaxTokenUpgradeEntMembers();
139 return; 140 return;
140 } 141 }
141 window.btutil_maxUsage(true); 142 window.btutil_modalMaxTokenUpgrade();
143 return;
144 }
145 window.btutil_modalRegisterUpgrade(false);
142 return; 146 return;
143 } 147 }
144 // "gpt-3.5-turbo" 148 // "gpt-3.5-turbo"
......
...@@ -74,7 +74,7 @@ app.use(cookieParser()); ...@@ -74,7 +74,7 @@ app.use(cookieParser());
74 74
75 const max_tokens = process.env.MAX_TOKENS_chatbot_plus ? parseInt(process.env.MAX_TOKENS_chatbot_plus) : 512; 75 const max_tokens = process.env.MAX_TOKENS_chatbot_plus ? parseInt(process.env.MAX_TOKENS_chatbot_plus) : 512;
76 // Routing 76 // Routing
77 const hostapi = process.env.REACT_APP_HOST_API || "https://api.ai-pro.org"; 77 const hostapi = process.env.API_URL || "https://api.ai-pro.org";
78 const user_secret_id = process.env.USER_SECRET_ID || "aiwp_logged_in"; 78 const user_secret_id = process.env.USER_SECRET_ID || "aiwp_logged_in";
79 const aiwp_app_id = "chatbot+"; 79 const aiwp_app_id = "chatbot+";
80 // Primary Open AI Route 80 // Primary Open AI Route
...@@ -435,12 +435,13 @@ async function validation (aiwp_app_id, req, res) { ...@@ -435,12 +435,13 @@ async function validation (aiwp_app_id, req, res) {
435 res.json({ status: "invalid", restrict: true, redirect: auth.redirect }); 435 res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
436 res.end(); 436 res.end();
437 return false; 437 return false;
438 } else if (typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) { 438 } else if (auth.subscription_type &&
439 typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
439 res.json({ status: "invalid", restrict: true }); 440 res.json({ status: "invalid", restrict: true });
440 res.end(); 441 res.end();
441 return false; 442 return false;
442 } 443 }
443 } 444 } else {
444 let data = await getUsage({ 445 let data = await getUsage({
445 aiwp_logged_in, app: 'chatbot+' 446 aiwp_logged_in, app: 'chatbot+'
446 }); 447 });
...@@ -450,8 +451,11 @@ async function validation (aiwp_app_id, req, res) { ...@@ -450,8 +451,11 @@ async function validation (aiwp_app_id, req, res) {
450 res.status(200); 451 res.status(200);
451 return false; 452 return false;
452 } 453 }
454 }
453 } else { 455 } else {
454 IS_FREE_USER = true; 456 IS_FREE_USER = true;
457 }
458 if(IS_FREE_USER) {
455 let data = await getLimitedUsage({ 459 let data = await getLimitedUsage({
456 "aiwp_app_id": aiwp_app_id 460 "aiwp_app_id": aiwp_app_id
457 }); 461 });
...@@ -459,14 +463,13 @@ async function validation (aiwp_app_id, req, res) { ...@@ -459,14 +463,13 @@ async function validation (aiwp_app_id, req, res) {
459 if (data.usage !== null) { 463 if (data.usage !== null) {
460 TRIED_USAGE = parseInt(data.usage); 464 TRIED_USAGE = parseInt(data.usage);
461 } 465 }
462 466 if (TRIED_USAGE >= limit) {
463 }
464 if (IS_FREE_USER && TRIED_USAGE >= limit) {
465 res.json({ status: "invalid", limited: true }); 467 res.json({ status: "invalid", limited: true });
466 res.end(); 468 res.end();
467 return false; 469 return false;
468 } 470 }
469 if (IS_FREE_USER) TRIED_USAGE++; 471 TRIED_USAGE++;
472 }
470 473
471 return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE }; 474 return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE };
472 }; 475 };
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!