Spaces:
Runtime error
Runtime error
File size: 14,161 Bytes
a5d3136 8ab8ce6 a5d3136 8ab8ce6 a5d3136 5edb688 8ab8ce6 c51ef1f a5d3136 d86e879 5edb688 d86e879 a5d3136 0176d04 a5d3136 2d520cd 0b8a3b8 a5d3136 2d520cd a5d3136 2d520cd a5d3136 a68302c 2d520cd 5edb688 2d520cd a43fa79 5edb688 a43fa79 0176d04 a5d3136 8ab8ce6 5edb688 ec9f077 5edb688 ec9f077 8ab8ce6 ec9f077 8ab8ce6 64b3342 8ab8ce6 ec9f077 5edb688 ec9f077 5edb688 8ab8ce6 5edb688 a5d3136 8ab8ce6 a5d3136 2d520cd a5d3136 2d520cd 5edb688 2d520cd 5edb688 d9e2c6a 2d520cd 12c9f43 2d520cd a5d3136 2d520cd 73ac8cf 2d520cd eb4c706 2d520cd d58f6f2 2d520cd a5d3136 0b8a3b8 5edb688 d86e879 a43fa79 0b8a3b8 eb4c706 0b8a3b8 a5d3136 0f7147c 5edb688 a5d3136 2d520cd 5edb688 2d520cd a5d3136 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>CerebrateX - 数据整理</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-slate-50 min-h-screen">
<div class="max-w-4xl mx-auto py-12 px-6">
<h1 class="text-3xl font-bold text-slate-900 mb-2 tracking-tight">📋 数据整理</h1>
<p class="text-sm text-slate-500 mb-8">粘贴生数据 → 格式清洗 + 去重 → DNS验证 → 复制干净列表 → 拿去 CRM/SES 发送</p>
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-8 space-y-6 mb-8">
<h2 class="text-xl font-bold text-slate-800">🚫 退信记录管理</h2>
<p class="text-sm text-slate-500">上传 SES 退信 CSV 或退信 txt,自动存入数据库,下次整理时自动过滤。</p>
<div class="flex flex-wrap gap-3 items-center">
<input type="file" id="bounceFileInput" accept=".txt,.csv,.tsv" multiple class="text-sm text-slate-600 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-slate-100 file:text-slate-700 hover:file:bg-slate-200">
<span id="bounceStatus" class="text-xs text-slate-400">数据库已记录 <span id="bounceCount">0</span> 个退信地址</span>
<button onclick="clearBounceData()" class="text-xs text-red-500 hover:text-red-700 ml-auto"></button>
</div>
</div>
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-8 space-y-6 mb-8">
<h2 class="text-xl font-bold text-slate-800">🔑 Admin Token</h2>
<input type="password" id="adminToken" placeholder="输入 Admin Token(DNS验证/导入退信时使用)" class="w-full px-4 py-3 border border-slate-300 rounded-xl focus:ring-2 focus:ring-blue-500 focus:outline-none text-sm">
</div>
<div class="bg-white rounded-2xl shadow-sm border border-slate-200 p-8 space-y-6">
<div>
<label class="block text-sm font-semibold text-slate-700 mb-2">粘贴生数据</label>
<textarea id="rawInput" rows="12" placeholder="粘贴邮箱地址(支持逗号、空格、分号、换行等任意分隔符)..." oninput="updateRawCount()" class="w-full px-4 py-3 border border-slate-300 rounded-xl focus:ring-2 focus:ring-blue-500 focus:outline-none text-sm font-mono resize-y"></textarea>
<div id="rawCount" class="text-xs text-slate-400 mt-1"></div>
</div>
<div class="flex items-center gap-4">
<button onclick="processData()" id="processBtn" class="bg-blue-600 text-white px-8 py-3 rounded-xl hover:bg-blue-700 shadow-lg font-bold transition active:scale-95">🔍 整理</button>
<div class="flex items-center gap-3">
<button onclick="copyResult()" class="bg-emerald-600 text-white px-8 py-3 rounded-xl hover:bg-emerald-700 shadow-lg font-bold transition active:scale-95 hidden" id="copyBtn">📋 复制结果</button>
<button onclick="verifyEmails()" class="bg-amber-600 text-white px-8 py-3 rounded-xl hover:bg-amber-700 shadow-lg font-bold transition active:scale-95 hidden" id="verifyBtn">🔍 DNS验证</button>
</div>
<span id="processStatus" class="text-sm text-slate-500"></span>
</div>
<div id="progressBar" class="hidden mt-2">
<div class="h-2 bg-slate-200 rounded-full overflow-hidden">
<div id="progressFill" class="h-full bg-blue-500 transition-all duration-300" style="width:0%"></div>
</div>
<div id="progressText" class="text-xs text-slate-400 mt-1"></div>
</div>
<div id="resultArea" class="hidden mt-4 p-4 bg-slate-50 rounded-xl border border-slate-200">
<div class="text-sm font-semibold text-slate-700 mb-2">整理结果:</div>
<div id="resultStats" class="text-xs text-slate-500 mb-3 space-y-1"></div>
<textarea id="resultOutput" rows="10" readonly class="w-full px-4 py-3 border border-slate-300 rounded-xl focus:ring-2 focus:ring-blue-500 focus:outline-none text-sm font-mono resize-y bg-white"></textarea>
</div>
</div>
</div>
<script>
const BOUNCE_KEY = 'data_bounce_list';
const GENERIC_PREFIXES = ['info','admin','webmaster','service','jubao','sales','tougao','support','help','noreply','no-reply','mail','tousu','postmaster','abuse'];
function getBounces() { try { return JSON.parse(localStorage.getItem(BOUNCE_KEY) || '[]'); } catch(e) { return []; } }
function saveBounces(list) { localStorage.setItem(BOUNCE_KEY, JSON.stringify(list)); }
async function updateBounceDbCount() {
const token = document.getElementById('adminToken').value.trim();
if (!token) return;
try { const res = await fetch('/api/crm/bounced_count', { headers: { 'X-Admin-Token': token } }); const data = await res.json(); document.getElementById('bounceCount').textContent = data.count || 0; } catch(e) {}
}
function updateBounceCount() { updateBounceDbCount(); }
function updateRawCount() {
const val = document.getElementById('rawInput').value.trim();
const count = val ? val.split(/[\n\r]+/).filter(l => l.trim()).length : 0;
document.getElementById('rawCount').textContent = `当前 ${count} 行`;
}
updateBounceCount();
document.getElementById('bounceFileInput').addEventListener('change', async function(e) {
const files = e.target.files;
if (!files.length) return;
const token = document.getElementById('adminToken').value.trim();
if (!token) { alert('请先输入 Admin Token'); return; }
let totalAdded = 0;
for (const file of files) {
const text = await file.text();
const lines = text.replace(/^\ufeff/, '').split(/[\n\r]+/).filter(l => l.trim());
const emails = [];
for (const line of lines) {
const cleanLine = line.trim();
if (!cleanLine || cleanLine.startsWith('收信地址')) continue;
const firstCol = cleanLine.split(',')[0].replace(/"/g, '').trim();
if (firstCol && firstCol.includes('@') && !firstCol.includes(' ')) { emails.push(firstCol); continue; }
if (cleanLine.includes('@') && !cleanLine.includes(' ') && !cleanLine.includes(',')) { emails.push(cleanLine); }
}
if (emails.length > 0) {
await fetch('/api/crm/add_bounced', { method: 'POST', headers: { 'X-Admin-Token': token, 'Content-Type': 'application/json' }, body: JSON.stringify({ emails }) });
totalAdded += emails.length;
}
}
if (totalAdded > 0) { alert(`已导入 ${totalAdded} 个退信地址到数据库`); updateBounceDbCount(); }
e.target.value = '';
});
function clearBounceData() {
if (confirm('确定要清空所有退信记录吗?')) { saveBounces([]); updateBounceCount(); document.getElementById('bounceStatus').textContent = '数据库已记录 0 个退信地址'; }
}
async function processData() {
const raw = document.getElementById('rawInput').value;
const bouncesSet = new Set(getBounces());
const btn = document.getElementById('processBtn');
const status = document.getElementById('processStatus');
const progressBar = document.getElementById('progressBar');
const progressFill = document.getElementById('progressFill');
const progressText = document.getElementById('progressText');
if (!raw.trim()) { status.textContent = '请先粘贴邮箱地址'; status.className = 'text-sm text-red-500'; return; }
btn.disabled = true; btn.textContent = '整理中...';
progressBar.classList.remove('hidden'); status.textContent = ''; status.className = 'text-sm text-slate-500';
await sleep(30);
updateProgress(10, '分割行...'); await sleep(20);
const normalized = raw.replace(/[,;,;\s]+/g, '\n');
const lines = normalized.split(/[\n\r]+/).map(l => l.trim()).filter(l => l);
updateProgress(20, `原始 ${lines.length} 行`);
const validFormat = lines.filter(l => l.includes('@') && !l.includes(' ') && !l.includes('*'));
updateProgress(40, `格式过滤完成,剩余 ${validFormat.length}`);
const notGeneric = validFormat.filter(l => { const p = l.split('@')[0].toLowerCase(); return !GENERIC_PREFIXES.includes(p); });
updateProgress(55, `通用邮箱过滤完成,剩余 ${notGeneric.length}`);
const unique = [...new Set(notGeneric)];
updateProgress(70, `去重完成,剩余 ${unique.length}`);
let dbBounces = [];
try {
const token = document.getElementById('adminToken').value.trim();
if (token) {
const res = await fetch('/api/crm/bounced_check', { method: 'POST', headers: { 'X-Admin-Token': token, 'Content-Type': 'application/json' }, body: JSON.stringify({ emails: unique }) });
const data = await res.json();
if (data.bounced) dbBounces = data.bounced;
}
} catch(e) {}
const dbBouncesSet = new Set(dbBounces);
const clean = unique.filter(l => !dbBouncesSet.has(l));
updateProgress(90, `退信过滤完成,剩余 ${clean.length}`);
const stats = [`原始行数:${lines.length} 条`,`格式过滤:去掉 ${lines.length - validFormat.length} 条`,`通用邮箱:去掉 ${validFormat.length - notGeneric.length} 条`,`本批去重:去掉 ${notGeneric.length - unique.length} 条`,`退信过滤:去掉 ${unique.length - clean.length} 条`,`DNS验证前可用:${clean.length} 条`];
document.getElementById('resultOutput').value = clean.join('\n');
document.getElementById('resultStats').innerHTML = stats.map(s => `<div>${s}</div>`).join('');
document.getElementById('resultArea').classList.remove('hidden');
document.getElementById('copyBtn').classList.remove('hidden');
document.getElementById('verifyBtn').classList.remove('hidden');
updateProgress(100, `完成!最终可用 ${clean.length} 条`);
btn.disabled = false; btn.textContent = '🔍 整理';
}
async function verifyEmails() {
const token = document.getElementById('adminToken').value.trim();
if (!token) { document.getElementById('processStatus').textContent = '请先输入 Admin Token'; document.getElementById('processStatus').className = 'text-sm text-red-500'; return; }
const status = document.getElementById('processStatus');
const resultOutput = document.getElementById('resultOutput');
const resultStats = document.getElementById('resultStats');
const verifyBtn = document.getElementById('verifyBtn');
const emails = resultOutput.value.trim();
if (!emails) { status.textContent = '没有可验证的邮箱'; status.className = 'text-sm text-red-500'; return; }
verifyBtn.disabled = true; verifyBtn.textContent = '验证中...';
status.textContent = '正在验证 DNS...'; status.className = 'text-sm text-blue-500';
try {
const res = await fetch('/api/crm/verify_emails', { method: 'POST', headers: { 'X-Admin-Token': token, 'Content-Type': 'application/json' }, body: JSON.stringify({ emails }) });
const data = await res.json();
if (data.success) {
resultOutput.value = data.valid.join('\n');
resultStats.innerHTML += `<div class="text-red-500">DNS验证:过滤 ${data.invalid_count} 个无效域名</div>`;
const finalCount = data.valid.length;
resultStats.innerHTML += `<div><strong>最终可用:${finalCount} 条</strong></div>`;
status.textContent = `DNS验证完成,${data.valid_count} 个有效,${data.invalid_count} 个无效已过滤`;
status.className = 'text-sm text-emerald-600';
} else { status.textContent = '验证失败'; status.className = 'text-sm text-red-500'; }
} catch(e) { status.textContent = '网络错误'; status.className = 'text-sm text-red-500'; }
finally { verifyBtn.disabled = false; verifyBtn.textContent = '🔍 DNS验证'; }
}
function copyResult() {
const bouncesSet = new Set(getBounces());
const raw = document.getElementById('resultOutput').value;
const list = raw.split(/[\n\r]+/).map(l => l.trim()).filter(l => l && l.includes('@'));
const filtered = list.filter(l => !bouncesSet.has(l));
document.getElementById('resultOutput').value = filtered.join('\n');
if (!filtered.length) { document.getElementById('processStatus').textContent = '所有邮箱都在退信记录中'; document.getElementById('processStatus').className = 'text-sm text-red-500'; return; }
navigator.clipboard.writeText(filtered.join('\n')).then(() => { document.getElementById('processStatus').textContent = '已复制到剪贴板,现在可以去 CRM 或 SES 页面粘贴发送'; document.getElementById('processStatus').className = 'text-sm text-emerald-600'; });
}
function updateProgress(pct, text) { document.getElementById('progressFill').style.width = pct + '%'; document.getElementById('progressText').textContent = text; }
function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }
</script>
</body>
</html> |