()
| 2504 | } |
| 2505 | |
| 2506 | async function disableUsedLuckmailPurchases() { |
| 2507 | const state = await ensureManualInteractionAllowed('禁用已用 LuckMail 邮箱'); |
| 2508 | const usedPurchases = getLuckmailUsedPurchases(state); |
| 2509 | const preserveTagInfo = getLuckmailPreserveTagInfo(state); |
| 2510 | const client = createLuckmailClient(state); |
| 2511 | const purchases = await listLuckmailPurchasesByProject(state, { |
| 2512 | client, |
| 2513 | projectCode: DEFAULT_LUCKMAIL_PROJECT_CODE, |
| 2514 | }); |
| 2515 | const targets = purchases.filter((purchase) => { |
| 2516 | const purchaseId = normalizeLuckmailPurchaseId(purchase.id); |
| 2517 | return Boolean(purchaseId && usedPurchases[purchaseId]) |
| 2518 | && !isLuckmailPurchasePreserved(purchase, { |
| 2519 | preserveTagId: preserveTagInfo.id, |
| 2520 | preserveTagName: preserveTagInfo.name, |
| 2521 | }) |
| 2522 | && purchase.user_disabled !== 1; |
| 2523 | }); |
| 2524 | |
| 2525 | if (!targets.length) { |
| 2526 | return { disabledIds: [] }; |
| 2527 | } |
| 2528 | |
| 2529 | const targetIds = targets.map((purchase) => purchase.id); |
| 2530 | await client.user.batchSetPurchaseDisabled(targetIds, 1); |
| 2531 | const currentPurchase = getCurrentLuckmailPurchase(await getState()); |
| 2532 | if (currentPurchase?.id && targetIds.includes(currentPurchase.id)) { |
| 2533 | await clearLuckmailRuntimeState({ clearEmail: isLuckmailProvider(await getState()) }); |
| 2534 | } |
| 2535 | await addLog(`LuckMail:已禁用 ${targetIds.length} 个本地已用邮箱`, 'ok'); |
| 2536 | return { disabledIds: targetIds }; |
| 2537 | } |
| 2538 | |
| 2539 | async function ensureLuckmailPurchaseForFlow(options = {}) { |
| 2540 | const { allowReuse = true } = options; |
no test coverage detected