52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { getEnvVar } from '@/utils/envUtils';
|
|
import { readFileSync } from 'fs';
|
|
|
|
const authConfig = {
|
|
authFilePath: '.auth/',
|
|
indexedDBFilePath: '.auth/',
|
|
};
|
|
|
|
class AuthAccount {
|
|
account: string;
|
|
password: string;
|
|
authFile: string;
|
|
indexedDBFile: string;
|
|
|
|
constructor(account: string, password: string, authFile: string, indexedDBFile: string) {
|
|
this.account = account;
|
|
this.password = password;
|
|
this.authFile = authFile;
|
|
this.indexedDBFile = indexedDBFile;
|
|
}
|
|
|
|
static loadIndexedDBFile(account: string, accountArray: AuthAccount[]) {
|
|
try {
|
|
for (const item of accountArray) {
|
|
if (item.account === account) {
|
|
return JSON.parse(readFileSync(item.indexedDBFile, 'utf-8'));
|
|
}
|
|
}
|
|
} catch (e) {
|
|
throw new Error('indexedDB文件读取失败');
|
|
}
|
|
|
|
throw new Error('未找到该账户');
|
|
}
|
|
}
|
|
|
|
const firstAccount = new AuthAccount(
|
|
getEnvVar('boss_account'),
|
|
getEnvVar('boss_password'),
|
|
`${authConfig.authFilePath}${getEnvVar('boss_account')}.json`,
|
|
`${authConfig.indexedDBFilePath}${getEnvVar('boss_account')}_indexedDB.json`,
|
|
);
|
|
|
|
const secondAccount = new AuthAccount(
|
|
getEnvVar('boss_account_2'),
|
|
getEnvVar('boss_password_2'),
|
|
`${authConfig.authFilePath}${getEnvVar('boss_account_2')}.json`,
|
|
`${authConfig.indexedDBFilePath}${getEnvVar('boss_account_2')}_indexedDB.json`,
|
|
);
|
|
|
|
|
|
export { firstAccount, secondAccount, AuthAccount }; |