(email: string)
| 38 | } |
| 39 | |
| 40 | export async function cacheGoogleAccount(email: string): Promise<void> { |
| 41 | const filePath = getGoogleAccountsCachePath(); |
| 42 | await fsp.mkdir(path.dirname(filePath), { recursive: true }); |
| 43 | |
| 44 | const accounts = await readAccounts(filePath); |
| 45 | |
| 46 | if (accounts.active && accounts.active !== email) { |
| 47 | if (!accounts.old.includes(accounts.active)) { |
| 48 | accounts.old.push(accounts.active); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // If the new email was in the old list, remove it |
| 53 | accounts.old = accounts.old.filter((oldEmail) => oldEmail !== email); |
| 54 | |
| 55 | accounts.active = email; |
| 56 | await fsp.writeFile(filePath, JSON.stringify(accounts, null, 2), 'utf-8'); |
| 57 | } |
| 58 | |
| 59 | export function getCachedGoogleAccount(): string | null { |
| 60 | try { |
no test coverage detected