Merge branch '30852_chatbot_chatgpt' into 'master'
30852 chatbot chatgpt See merge request !103
Showing
1 changed file
with
6 additions
and
10 deletions
| ... | @@ -66,9 +66,6 @@ const rateLimiter = rateLimit({ | ... | @@ -66,9 +66,6 @@ const rateLimiter = rateLimit({ |
| 66 | const app = express() | 66 | const app = express() |
| 67 | const port = 3080 | 67 | const port = 3080 |
| 68 | 68 | ||
| 69 | app.set('trust proxy', 1) | ||
| 70 | app.use(express.json()) | ||
| 71 | app.use(express.urlencoded({ extended: true })) | ||
| 72 | app.use(bodyParser.json()) | 69 | app.use(bodyParser.json()) |
| 73 | app.use(cors()) | 70 | app.use(cors()) |
| 74 | app.use(require('morgan')('dev')) | 71 | app.use(require('morgan')('dev')) |
| ... | @@ -155,7 +152,7 @@ app.post('/api', async (req, res) => { | ... | @@ -155,7 +152,7 @@ app.post('/api', async (req, res) => { |
| 155 | console.log('Error encoding prompt text', e); | 152 | console.log('Error encoding prompt text', e); |
| 156 | } | 153 | } |
| 157 | let usage_params = { | 154 | let usage_params = { |
| 158 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | 155 | "aiwp_logged_in": aiwp_logged_in, "app": "chatbot+", "prompt_token": usage.prompt_tokens, "total_token": usage.total_tokens, "aiwp_app_id":aiwp_app_id , "usage_tries": TRIED_USAGE |
| 159 | }; | 156 | }; |
| 160 | if(IS_FREE_USER) { | 157 | if(IS_FREE_USER) { |
| 161 | await setUsage(usage_params); | 158 | await setUsage(usage_params); |
| ... | @@ -237,7 +234,7 @@ async function runGPTTurbo(req, res) { | ... | @@ -237,7 +234,7 @@ async function runGPTTurbo(req, res) { |
| 237 | console.log('Error encoding prompt text', e); | 234 | console.log('Error encoding prompt text', e); |
| 238 | } | 235 | } |
| 239 | let usage_params = { | 236 | let usage_params = { |
| 240 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | 237 | "aiwp_logged_in": aiwp_logged_in, "app": "chatbot+", "prompt_token": usage.prompt_tokens, "total_token": usage.total_tokens, "aiwp_app_id":aiwp_app_id , "usage_tries": TRIED_USAGE |
| 241 | }; | 238 | }; |
| 242 | if(IS_FREE_USER) { | 239 | if(IS_FREE_USER) { |
| 243 | await setUsage(usage_params); | 240 | await setUsage(usage_params); |
| ... | @@ -324,7 +321,7 @@ async function runOpensource(req, res) { | ... | @@ -324,7 +321,7 @@ async function runOpensource(req, res) { |
| 324 | console.log('Error encoding prompt text', e); | 321 | console.log('Error encoding prompt text', e); |
| 325 | } | 322 | } |
| 326 | let usage_params = { | 323 | let usage_params = { |
| 327 | aiwp_logged_in, app: 'chatbot+', prompt_token: usage.prompt_tokens, total_token: usage.total_tokens, aiwp_app_id, usage_tries: TRIED_USAGE | 324 | "aiwp_logged_in": aiwp_logged_in, "app": "chatbot+", "prompt_token": usage.prompt_tokens, "total_token": usage.total_tokens, "aiwp_app_id":aiwp_app_id , "usage_tries": TRIED_USAGE |
| 328 | }; | 325 | }; |
| 329 | if(IS_FREE_USER) { | 326 | if(IS_FREE_USER) { |
| 330 | await setUsage(usage_params); | 327 | await setUsage(usage_params); |
| ... | @@ -349,7 +346,6 @@ async function runOpensource(req, res) { | ... | @@ -349,7 +346,6 @@ async function runOpensource(req, res) { |
| 349 | } | 346 | } |
| 350 | 347 | ||
| 351 | async function authenticate(params) { | 348 | async function authenticate(params) { |
| 352 | console.log("params", params); | ||
| 353 | let data = await fetch(`${hostapi}/e/authenticate/v2`, { | 349 | let data = await fetch(`${hostapi}/e/authenticate/v2`, { |
| 354 | method: "POST", | 350 | method: "POST", |
| 355 | headers: { | 351 | headers: { |
| ... | @@ -405,13 +401,13 @@ async function setChatUsage(params) { | ... | @@ -405,13 +401,13 @@ async function setChatUsage(params) { |
| 405 | } | 401 | } |
| 406 | 402 | ||
| 407 | async function validation (aiwp_app_id, req, res) { | 403 | async function validation (aiwp_app_id, req, res) { |
| 408 | const aiwp_logged_in = req.cookies[user_secret_id] ? decodeURIComponent(req.cookies[user_secret_id]) : ""; | 404 | const aiwp_logged_in = req.cookies[user_secret_id] ? decodeURIComponent(req.cookies[user_secret_id]) : "asdasd"; |
| 409 | const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : -1; | 405 | const limit = req.cookies["WcvYPABR"] ? parseInt(req.cookies["WcvYPABR"].replace(/\D/g, '')) : -1; |
| 410 | let IS_FREE_USER = false; | 406 | let IS_FREE_USER = false; |
| 411 | let TRIED_USAGE = 0; | 407 | let TRIED_USAGE = 0; |
| 412 | 408 | ||
| 413 | if (aiwp_logged_in) { | 409 | if (aiwp_logged_in) { |
| 414 | let auth = await authenticate({ aiwp_logged_in, user_event_data: {}, user_event: 'endpoint' }); | 410 | let auth = await authenticate({ "aiwp_logged_in": aiwp_logged_in, "user_event_data": {}, "user_event": "endpoint" }); |
| 415 | if (!auth.success) { | 411 | if (!auth.success) { |
| 416 | IS_FREE_USER = true; | 412 | IS_FREE_USER = true; |
| 417 | if (auth.is_restrict) { | 413 | if (auth.is_restrict) { |
| ... | @@ -441,7 +437,7 @@ async function validation (aiwp_app_id, req, res) { | ... | @@ -441,7 +437,7 @@ async function validation (aiwp_app_id, req, res) { |
| 441 | } else { | 437 | } else { |
| 442 | IS_FREE_USER = true; | 438 | IS_FREE_USER = true; |
| 443 | let data = await getLimitedUsage({ | 439 | let data = await getLimitedUsage({ |
| 444 | aiwp_app_id | 440 | "aiwp_app_id": aiwp_app_id |
| 445 | }); | 441 | }); |
| 446 | 442 | ||
| 447 | if (data.usage !== null) { | 443 | if (data.usage !== null) { | ... | ... |
-
Please register or sign in to post a comment