dcc61c8e by Jonille Arreglo

Merge branch '27190_loggedin' of https://gitlab.baytech.ph/baytech/chatgpt.ai-pro.org into 1DEVT

# Conflicts:
#	client/src/App.js
2 parents b804a97b 68aee7cc
let aiUser = btutil_getCookie('aiwp_logged_in');
let objBody = { aiwp_logged_in: aiUser };
let params = [];
params['objBody'] = objBody;
params['strUrl'] = 'https://test.api.ai-pro.org/e/v1/authenticate/'; //use envvar for https://test.api.ai-pro.org/ only
btutil_checkAuthentication(params, cbCheckAuthentication, cbErrCheckAuthentication);
function cbCheckAuthentication(res) {
// console.log(res);
if (!res.success) {
window.location.href = "https://ai-pro.org/redirect-account-required/"; //use envvar
} else {
document.getElementById("root").classList.add("active");
}
}
function cbErrCheckAuthentication(res) {
console.log(res);
}
\ No newline at end of file
......@@ -26,6 +26,33 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>AI-Pro ChatGPT</title>
<script src='%REACT_APP_BTCOMPONENT_S3_URL%/common/btutil-authenticate.min.js'></script>
<script>
let aiUser = btutil_getCookie('aiwp_logged_in');
if(!aiUser) {
window.location.href = '%REACT_APP_AUTH_FAILED_REDIRECTION_URL%';
} else {
let objBody = { aiwp_logged_in: aiUser };
let params = [];
params['objBody'] = objBody;
params['strUrl'] = '%REACT_APP_EXTERNAL_API_URL%/e/v1/authenticate/';
btutil_checkAuthentication(params, cbCheckAuthentication, cbErrCheckAuthentication);
function cbCheckAuthentication(res) {
// console.log(res);
if (!res.success) {
window.location.href = '%REACT_APP_AUTH_FAILED_REDIRECTION_URL%';
} else {
document.getElementById("root").classList.add("active");
}
}
function cbErrCheckAuthentication(res) {
console.log(res);
}
}
</script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
......
......@@ -47,7 +47,9 @@ function App() {
let model_list = [];
for( var i = 1; i < data.models.data.length; i++ ) {
let model = data.models.data[i];
if(model.id != "whisper-1") model_list.push(model);
if( !(model.id == "whisper-1"
|| model.id == "gpt-4"
|| model.id == "gpt-4-0314") ) model_list.push(model);
}
setModels(model_list)
})
......@@ -55,6 +57,28 @@ function App() {
async function handleSubmit(e){
e.preventDefault();
let aiUser = window.btutil_getCookie('aiwp_logged_in');
if(!aiUser) {
window.location.href = process.env.REACT_APP_AUTH_FAILED_REDIRECTION_URL;
return;
} else {
let objBody = { aiwp_logged_in: aiUser };
let params = [];
params['objBody'] = objBody;
params['strUrl'] = process.env.REACT_APP_EXTERNAL_API_URL + '/e/v1/authenticate/';
window.btutil_checkAuthentication(params, function(res) {
if (!res.success) {
window.location.href = process.env.REACT_APP_AUTH_FAILED_REDIRECTION_URL;
} else {
submitPrompt();
}
}, function(res) {});
}
}
async function submitPrompt() {
const userInput = ['what', 'why', 'when', 'where' , 'which', 'did', 'do', 'how', 'can', 'are', 'who'];
const userInputRegex = new RegExp(`\\b(${userInput.join('|')})\\b`, 'gi');
const inputMatches = chatInput.match(userInputRegex);
......@@ -88,7 +112,6 @@ function App() {
messages = JSON.stringify(chatLogTurboNew);
}
let intervalId = startInterval();
try {
const response = await fetch(process.env.REACT_APP_SERVER_URL + "/api", {
method: "POST",
......
const appendScript = (scriptToAppend, callback = null) => {
const script = document.createElement("script");
script.src = scriptToAppend;
script.async = false;
document.body.appendChild(script);
if(!callback) return;
if(script.readyState) { // only required for IE <9
script.onreadystatechange = function() {
if ( script.readyState === "loaded" || script.readyState === "complete" ) {
script.onreadystatechange = null;
callback();
}
};
} else { //Others
script.onload = function() {
callback();
};
}
}
export default appendScript;
\ No newline at end of file
......@@ -2,7 +2,6 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import appendScript from './handlers/appendScript';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
......@@ -16,6 +15,3 @@ root.render(
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
appendScript("https://btcomponent-1devt.s3.us-east-1.amazonaws.com/common/btutil-authenticate.min.js");
appendScript("http://localhost:3000/assets/js/auth.js");
\ No newline at end of file
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!