MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / batchUpdateLuckmailPurchases

Function batchUpdateLuckmailPurchases

background.js:2445–2504  ·  view source on GitHub ↗
(input = {})

Source from the content-addressed store, hash-verified

2443}
2444
2445async function batchUpdateLuckmailPurchases(input = {}) {
2446 const action = String(input.action || '').trim();
2447 const selectedIds = Array.isArray(input.ids)
2448 ? [...new Set(input.ids.map((id) => Number(normalizeLuckmailPurchaseId(id)) || 0).filter((id) => id > 0))]
2449 : [];
2450 if (!selectedIds.length) {
2451 throw new Error('请先选择至少一个 LuckMail 邮箱。');
2452 }
2453
2454 const state = await ensureManualInteractionAllowed('批量更新 LuckMail 邮箱');
2455 const client = createLuckmailClient(state);
2456 const purchases = await listLuckmailPurchasesByProject(state, {
2457 client,
2458 projectCode: DEFAULT_LUCKMAIL_PROJECT_CODE,
2459 });
2460 const purchaseMap = new Map(purchases.map((purchase) => [purchase.id, purchase]));
2461 const targetPurchases = selectedIds.map((id) => purchaseMap.get(id)).filter(Boolean);
2462
2463 if (!targetPurchases.length) {
2464 throw new Error('未找到可批量处理的 openai LuckMail 邮箱。');
2465 }
2466
2467 const targetIds = targetPurchases.map((purchase) => purchase.id);
2468
2469 if (action === 'used' || action === 'unused') {
2470 const nextUsedState = getLuckmailUsedPurchases(state);
2471 targetIds.forEach((id) => {
2472 const key = normalizeLuckmailPurchaseId(id);
2473 if (!key) return;
2474 if (action === 'used') {
2475 nextUsedState[key] = true;
2476 } else {
2477 delete nextUsedState[key];
2478 }
2479 });
2480 await setLuckmailUsedPurchasesState(nextUsedState);
2481 await addLog(`LuckMail:已批量${action === 'used' ? '标记已用' : '标记未用'} ${targetIds.length} 个邮箱`, 'ok');
2482 } else if (action === 'preserve' || action === 'unpreserve') {
2483 if (action === 'preserve') {
2484 const preserveTag = await ensureLuckmailPreserveTag(client, state);
2485 await client.user.batchSetPurchaseTag(targetIds, { tagId: preserveTag.id });
2486 } else {
2487 await client.user.batchSetPurchaseTag(targetIds, { tagId: 0 });
2488 }
2489 await addLog(`LuckMail:已批量${action === 'preserve' ? '保留' : '取消保留'} ${targetIds.length} 个邮箱`, 'ok');
2490 } else if (action === 'disable' || action === 'enable') {
2491 await client.user.batchSetPurchaseDisabled(targetIds, action === 'disable' ? 1 : 0);
2492 const currentPurchase = getCurrentLuckmailPurchase(await getState());
2493 if (action === 'disable' && currentPurchase?.id && targetIds.includes(currentPurchase.id)) {
2494 await clearLuckmailRuntimeState({ clearEmail: isLuckmailProvider(await getState()) });
2495 }
2496 await addLog(`LuckMail:已批量${action === 'disable' ? '禁用' : '启用'} ${targetIds.length} 个邮箱`, 'ok');
2497 } else {
2498 throw new Error(`不支持的 LuckMail 批量操作:${action}`);
2499 }
2500
2501 return {
2502 updatedIds: targetIds,

Callers 1

handleMessageFunction · 0.85

Calls 12

createLuckmailClientFunction · 0.85
getStateFunction · 0.85
getLuckmailUsedPurchasesFunction · 0.70
addLogFunction · 0.70
isLuckmailProviderFunction · 0.70

Tested by

no test coverage detected