Merge branch '31466_limited_usage_chatbot+' into 'master'
31466_limited_usage_chatbot+ See merge request !118
Showing
3 changed files
with
47 additions
and
38 deletions
| ... | @@ -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(); | ||
| 140 | return; | ||
| 141 | } | ||
| 142 | window.btutil_modalMaxTokenUpgrade(); | ||
| 139 | return; | 143 | return; |
| 140 | } | 144 | } |
| 141 | window.btutil_maxUsage(true); | 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 |
| ... | @@ -430,43 +430,46 @@ async function validation (aiwp_app_id, req, res) { | ... | @@ -430,43 +430,46 @@ async function validation (aiwp_app_id, req, res) { |
| 430 | let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" }); | 430 | let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" }); |
| 431 | 431 | ||
| 432 | if (!auth.success) { | 432 | if (!auth.success) { |
| 433 | IS_FREE_USER = true; | 433 | IS_FREE_USER = true; |
| 434 | if (auth.is_restrict) { | 434 | if (auth.is_restrict) { |
| 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 | res.json({ status: "invalid", restrict: true }); | 439 | typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) { |
| 440 | res.end(); | 440 | res.json({ status: "invalid", restrict: true }); |
| 441 | return false; | 441 | res.end(); |
| 442 | return false; | ||
| 443 | } | ||
| 444 | } else { | ||
| 445 | let data = await getUsage({ | ||
| 446 | aiwp_logged_in, app: 'chatbot+' | ||
| 447 | }); | ||
| 448 | |||
| 449 | if (!(data.success === 1 && data.status === 'valid')) { | ||
| 450 | res.json({ status: "invalid", data }); | ||
| 451 | res.status(200); | ||
| 452 | return false; | ||
| 442 | } | 453 | } |
| 443 | } | 454 | } |
| 444 | let data = await getUsage({ | 455 | } else { |
| 445 | aiwp_logged_in, app: 'chatbot+' | 456 | IS_FREE_USER = true; |
| 446 | }); | ||
| 447 | |||
| 448 | if (!(data.success === 1 && data.status === 'valid')) { | ||
| 449 | res.json({ status: "invalid", data }); | ||
| 450 | res.status(200); | ||
| 451 | return false; | ||
| 452 | } | ||
| 453 | } else { | ||
| 454 | IS_FREE_USER = true; | ||
| 455 | let data = await getLimitedUsage({ | ||
| 456 | "aiwp_app_id": aiwp_app_id | ||
| 457 | }); | ||
| 458 | |||
| 459 | if (data.usage !== null) { | ||
| 460 | TRIED_USAGE = parseInt(data.usage); | ||
| 461 | } | ||
| 462 | |||
| 463 | } | 457 | } |
| 464 | if (IS_FREE_USER && TRIED_USAGE >= limit) { | 458 | if(IS_FREE_USER) { |
| 465 | res.json({ status: "invalid", limited: true }); | 459 | let data = await getLimitedUsage({ |
| 466 | res.end(); | 460 | "aiwp_app_id": aiwp_app_id |
| 467 | return false; | 461 | }); |
| 462 | |||
| 463 | if (data.usage !== null) { | ||
| 464 | TRIED_USAGE = parseInt(data.usage); | ||
| 465 | } | ||
| 466 | if (TRIED_USAGE >= limit) { | ||
| 467 | res.json({ status: "invalid", limited: true }); | ||
| 468 | res.end(); | ||
| 469 | return false; | ||
| 470 | } | ||
| 471 | TRIED_USAGE++; | ||
| 468 | } | 472 | } |
| 469 | if (IS_FREE_USER) TRIED_USAGE++; | ||
| 470 | 473 | ||
| 471 | return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE }; | 474 | return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE }; |
| 472 | }; | 475 | }; | ... | ... |
-
Please register or sign in to post a comment