Commit cc44f8dc authored by nanahira's avatar nanahira

update account provider interface

parent b2c925c3
...@@ -113,22 +113,22 @@ export class AccountPoolService ...@@ -113,22 +113,22 @@ export class AccountPoolService
if (result) { if (result) {
this.accountInfos.push(account); this.accountInfos.push(account);
} }
await this.accountProvider.writeBack(this.accountInfos); await this.accountProvider.writeBack(this.accountInfos, 'add', account);
return result; return result;
} }
async removeAccount(email: string) { async removeAccount(email: string) {
const index = this.accountInfos.findIndex((a) => a.email === email); const index = this.accountInfos.findIndex((a) => a.email === email);
this.accountInfos.splice(index, 1);
if (index === -1) { if (index === -1) {
return false; return false;
} }
const account = this.accounts.get(email); const [account] = this.accountInfos.splice(index, 1);
if (account) { const state = this.accounts.get(email);
if (state) {
this.accounts.delete(email); this.accounts.delete(email);
await account.close(); await state.close();
} }
await this.accountProvider.writeBack(this.accountInfos); await this.accountProvider.writeBack(this.accountInfos, 'remove', account);
return true; return true;
} }
......
...@@ -9,5 +9,9 @@ export class AccountProviderService { ...@@ -9,5 +9,9 @@ export class AccountProviderService {
return this.config.get<OpenAIAccount[]>('accounts'); return this.config.get<OpenAIAccount[]>('accounts');
} }
async writeBack(accounts: OpenAIAccount[]) {} async writeBack(
accounts: OpenAIAccount[],
type: 'add' | 'remove',
account: OpenAIAccount,
) {}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment