Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Administrator
/
chatgpt.ai-pro.org
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
3
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
cd44b1b5
authored
2024-09-09 18:48:28 +0800
by
Jonille Arreglo
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
31466_limited_usage_chatbot+
1 parent
74c76309
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
4 deletions
index.js
index.js
View file @
cd44b1b
...
...
@@ -154,7 +154,7 @@ app.post('/api', async (req, res) => {
console
.
log
(
'Error encoding prompt text'
,
e
);
}
let
usage_params
=
{
"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
"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
,
ipdflu
:
getClientIP
(
req
)
};
if
(
IS_FREE_USER
)
{
await
setUsage
(
usage_params
);
...
...
@@ -236,7 +236,7 @@ async function runGPTTurbo(req, res) {
console
.
log
(
'Error encoding prompt text'
,
e
);
}
let
usage_params
=
{
"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
"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
,
ipdflu
:
getClientIP
(
req
)
};
if
(
IS_FREE_USER
)
{
await
setUsage
(
usage_params
);
...
...
@@ -333,7 +333,7 @@ async function runOpensource(req, res) {
console
.
log
(
'Error encoding prompt text'
,
e
);
}
let
usage_params
=
{
"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
"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
,
ipdflu
:
getClientIP
(
req
)
};
if
(
IS_FREE_USER
)
{
await
setUsage
(
usage_params
);
...
...
@@ -425,6 +425,7 @@ async function validation (aiwp_app_id, req, res) {
const
limit
=
req
.
cookies
[
"WcvYPABR"
]
?
parseInt
(
req
.
cookies
[
"WcvYPABR"
].
replace
(
/
\D
/g
,
''
))
:
3
;
let
IS_FREE_USER
=
false
;
let
TRIED_USAGE
=
0
;
const
ip_address
=
getClientIP
(
req
);
if
(
aiwp_logged_in
)
{
let
auth
=
await
authenticate
({
"aiwp_logged_in"
:
aiwp_logged_in
,
"user_event_data"
:
{},
"user_event"
:
"endpoint"
});
...
...
@@ -457,7 +458,7 @@ async function validation (aiwp_app_id, req, res) {
}
if
(
IS_FREE_USER
)
{
let
data
=
await
getLimitedUsage
({
"aiwp_app_id"
:
aiwp_app_id
"aiwp_app_id"
:
aiwp_app_id
,
ipdflu
:
ip_address
});
if
(
data
.
usage
!==
null
)
{
...
...
@@ -474,6 +475,34 @@ async function validation (aiwp_app_id, req, res) {
return
{
IS_FREE_USER
,
aiwp_logged_in
,
TRIED_USAGE
};
};
const
getClientIP
=
(
req
)
=>
{
let
ipAddress
=
''
;
// Order of checking headers for client IP
if
(
req
.
headers
[
'x-forwarded-for'
])
{
ipAddress
=
Array
.
isArray
(
req
.
headers
[
'x-forwarded-for'
])
?
req
.
headers
[
'x-forwarded-for'
][
0
]
:
req
.
headers
[
'x-forwarded-for'
];
}
else
if
(
req
.
headers
[
'x-client-ip'
])
{
ipAddress
=
req
.
headers
[
'x-client-ip'
];
}
else
if
(
req
.
headers
[
'x-cluster-client-ip'
])
{
ipAddress
=
req
.
headers
[
'x-cluster-client-ip'
];
}
else
if
(
req
.
headers
[
'x-forwarded'
])
{
ipAddress
=
req
.
headers
[
'x-forwarded'
];
}
else
if
(
req
.
headers
[
'forwarded-for'
])
{
ipAddress
=
req
.
headers
[
'forwarded-for'
];
}
else
if
(
req
.
headers
[
'forwarded'
])
{
ipAddress
=
req
.
headers
[
'forwarded'
];
}
else
{
ipAddress
=
req
.
socket
?.
remoteAddress
||
'127.0.0.2'
;
}
// Split the IP address in case of multiple entries in 'x-forwarded-for'
const
arrIp
=
ipAddress
.
split
(
','
);
return
arrIp
[
0
]
||
'127.0.0.2'
;
};
// Get Models Route
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment