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 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"serve": "^14.2.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"serve": "serve -s build"
},
"eslintConfig": {
"extends": [
......
......@@ -131,14 +131,18 @@ function App() {
if(data.status === 'invalid'){
if(data.limited) {
window.btutil_maxUsage();
window.btutil_modalRegisterUpgrade(false);
return;
}
if(data && data.status === 'max-tokens') {
window.btutil_maxUsage();
if(data.ent_member === 'yes') {
window.btutil_modalMaxTokenUpgradeEntMembers();
return;
}
window.btutil_modalMaxTokenUpgrade();
return;
}
window.btutil_maxUsage(true);
window.btutil_modalRegisterUpgrade(false);
return;
}
// "gpt-3.5-turbo"
......
......@@ -74,7 +74,7 @@ app.use(cookieParser());
const max_tokens = process.env.MAX_TOKENS_chatbot_plus ? parseInt(process.env.MAX_TOKENS_chatbot_plus) : 512;
// Routing
const hostapi = process.env.REACT_APP_HOST_API || "https://api.ai-pro.org";
const hostapi = process.env.API_URL || "https://api.ai-pro.org";
const user_secret_id = process.env.USER_SECRET_ID || "aiwp_logged_in";
const aiwp_app_id = "chatbot+";
// Primary Open AI Route
......@@ -430,43 +430,46 @@ async function validation (aiwp_app_id, req, res) {
let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" });
if (!auth.success) {
IS_FREE_USER = true;
if (auth.is_restrict) {
res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
res.end();
return false;
} else if (typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
res.json({ status: "invalid", restrict: true });
res.end();
return false;
IS_FREE_USER = true;
if (auth.is_restrict) {
res.json({ status: "invalid", restrict: true, redirect: auth.redirect });
res.end();
return false;
} else if (auth.subscription_type &&
typeof auth.has_pro_access === "undefined" && !auth.has_pro_access) {
res.json({ status: "invalid", restrict: true });
res.end();
return false;
}
} else {
let data = await getUsage({
aiwp_logged_in, app: 'chatbot+'
});
if (!(data.success === 1 && data.status === 'valid')) {
res.json({ status: "invalid", data });
res.status(200);
return false;
}
}
let data = await getUsage({
aiwp_logged_in, app: 'chatbot+'
});
if (!(data.success === 1 && data.status === 'valid')) {
res.json({ status: "invalid", data });
res.status(200);
return false;
}
} else {
IS_FREE_USER = true;
let data = await getLimitedUsage({
"aiwp_app_id": aiwp_app_id
});
if (data.usage !== null) {
TRIED_USAGE = parseInt(data.usage);
}
} else {
IS_FREE_USER = true;
}
if (IS_FREE_USER && TRIED_USAGE >= limit) {
res.json({ status: "invalid", limited: true });
res.end();
return false;
if(IS_FREE_USER) {
let data = await getLimitedUsage({
"aiwp_app_id": aiwp_app_id
});
if (data.usage !== null) {
TRIED_USAGE = parseInt(data.usage);
}
if (TRIED_USAGE >= limit) {
res.json({ status: "invalid", limited: true });
res.end();
return false;
}
TRIED_USAGE++;
}
if (IS_FREE_USER) TRIED_USAGE++;
return { IS_FREE_USER, aiwp_logged_in, TRIED_USAGE };
};
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!