Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Chatgpt Forwarder
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Chatgpt Forwarder
Commits
8af6f27f
Commit
8af6f27f
authored
Feb 14, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add lock to account add
parent
7ff2e7ab
Pipeline
#20232
passed with stages
in 4 minutes and 38 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
9 deletions
+14
-9
src/account-pool/account-pool.service.ts
src/account-pool/account-pool.service.ts
+14
-9
No files found.
src/account-pool/account-pool.service.ts
View file @
8af6f27f
...
...
@@ -11,6 +11,7 @@ import { AccountState } from './account-state';
import
{
AccountProviderService
}
from
'
../account-provider/account-provider.service
'
;
import
{
AccountPoolStatusDto
}
from
'
./account-pool-status.dto
'
;
import
{
Interval
}
from
'
@nestjs/schedule
'
;
import
BetterLock
from
'
better-lock
'
;
@
Injectable
()
export
class
AccountPoolService
...
...
@@ -31,6 +32,9 @@ export class AccountPoolService
account
:
OpenAIAccount
,
retry
=
true
,
):
Promise
<
boolean
>
{
if
(
this
.
accounts
.
has
(
account
.
email
))
{
return
false
;
}
const
proxy
=
await
this
.
proxyPoolService
.
getProxy
();
const
state
=
new
AccountState
(
account
,
...
...
@@ -43,18 +47,18 @@ export class AccountPoolService
proxyServer
:
proxy
,
}),
);
this
.
log
(
`
Initializ
ing account
${
account
.
email
}
`
);
this
.
log
(
`
Add
ing account
${
account
.
email
}
`
);
const
success
=
await
state
.
init
();
if
(
success
)
{
this
.
accounts
.
set
(
account
.
email
,
state
);
this
.
log
(
`
Initializ
ed account
${
account
.
email
}
`
);
this
.
log
(
`
Add
ed account
${
account
.
email
}
`
);
return
true
;
}
else
if
(
retry
)
{
await
Promise
.
all
([
new
Promise
((
r
)
=>
setTimeout
(
r
,
5000
)),
state
.
close
(),
]);
return
this
.
initAccount
(
account
,
retry
);
return
await
this
.
initAccount
(
account
,
retry
);
}
else
{
await
state
.
close
();
return
false
;
...
...
@@ -87,7 +91,7 @@ export class AccountPoolService
await
eval
(
"
import('chatgpt3')
"
)
).
ChatGPTAPIBrowser
;
this
.
accountInfos
=
await
this
.
accountProvider
.
get
();
this
.
accountInfos
.
forEach
((
a
)
=>
this
.
initAccount
(
a
));
this
.
accountInfos
.
forEach
((
a
)
=>
this
.
addAccount
(
a
,
true
));
}
async
onModuleDestroy
()
{
...
...
@@ -130,11 +134,12 @@ export class AccountPoolService
return
this
.
accounts
.
get
(
email
)
||
this
.
randomAccount
(
exclude
);
}
async
addAccount
(
account
:
OpenAIAccount
)
{
if
(
this
.
accounts
.
has
(
account
.
email
))
{
return
false
;
}
return
this
.
initAccount
(
account
,
false
);
private
addAccountLock
=
new
BetterLock
();
async
addAccount
(
account
:
OpenAIAccount
,
retry
=
false
)
{
return
this
.
addAccountLock
.
acquire
(
account
.
email
,
()
=>
this
.
initAccount
(
account
,
retry
),
);
}
async
removeAccount
(
email
:
string
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment