VinOS Agent commited on
Commit
01dd31e
·
1 Parent(s): 60d2ef2

SEO Engine V6: Bulk Indexing Dashboard with live status, quota meter, and safe batching

Browse files
Files changed (3) hide show
  1. public/indexer.html +366 -0
  2. server.js +82 -0
  3. skills/google_indexer.js +28 -0
public/indexer.html ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>VinOS — Bulk Indexing Dashboard</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <style>
10
+ body { font-family: 'Inter', sans-serif; background: #050a14; color: #e2e8f0; }
11
+ .glass { background: rgba(255,255,255,0.04); backdrop-filter: blur(20px); border: 1px solid rgba(255,255,255,0.08); }
12
+ .glass-hover:hover { background: rgba(255,255,255,0.07); border-color: rgba(99,102,241,0.4); transition: all 0.2s; }
13
+ .glow { box-shadow: 0 0 30px rgba(99,102,241,0.15); }
14
+ .accent-glow { box-shadow: 0 0 20px rgba(99,102,241,0.4); }
15
+ .console-font { font-family: 'JetBrains Mono', monospace; }
16
+ .quota-bar { background: linear-gradient(90deg, #6366f1, #8b5cf6); transition: width 0.6s ease; }
17
+ .badge-indexed { background: rgba(16,185,129,0.15); color: #34d399; border: 1px solid rgba(16,185,129,0.3); }
18
+ .badge-pending { background: rgba(245,158,11,0.15); color: #fbbf24; border: 1px solid rgba(245,158,11,0.3); }
19
+ .badge-not-indexed { background: rgba(239,68,68,0.15); color: #f87171; border: 1px solid rgba(239,68,68,0.3); }
20
+ .badge-checking { background: rgba(99,102,241,0.15); color: #a5b4fc; border: 1px solid rgba(99,102,241,0.3); }
21
+ .badge-unknown { background: rgba(100,116,139,0.15); color: #94a3b8; border: 1px solid rgba(100,116,139,0.3); }
22
+ .btn-primary { background: linear-gradient(135deg, #6366f1, #8b5cf6); transition: all 0.2s; }
23
+ .btn-primary:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 8px 25px rgba(99,102,241,0.35); }
24
+ .btn-danger { background: linear-gradient(135deg, #ef4444, #dc2626); transition: all 0.2s; }
25
+ .btn-danger:hover { opacity: 0.9; transform: translateY(-1px); }
26
+ .spin { animation: spin 1s linear infinite; }
27
+ @keyframes spin { to { transform: rotate(360deg); } }
28
+ ::-webkit-scrollbar { width: 6px; } ::-webkit-scrollbar-track { background: transparent; } ::-webkit-scrollbar-thumb { background: #334155; border-radius: 3px; }
29
+ .url-row:hover { background: rgba(99,102,241,0.05); }
30
+ .log-success { color: #34d399; } .log-error { color: #f87171; } .log-info { color: #a5b4fc; } .log-warn { color: #fbbf24; }
31
+ </style>
32
+ </head>
33
+ <body class="min-h-screen p-4 md:p-8">
34
+
35
+ <!-- Background Orbs -->
36
+ <div class="fixed top-0 left-0 w-full h-full overflow-hidden pointer-events-none -z-10">
37
+ <div class="absolute top-[-10%] left-[-5%] w-[500px] h-[500px] rounded-full" style="background:radial-gradient(circle, rgba(99,102,241,0.12) 0%, transparent 70%);"></div>
38
+ <div class="absolute bottom-[-10%] right-[-5%] w-[400px] h-[400px] rounded-full" style="background:radial-gradient(circle, rgba(139,92,246,0.1) 0%, transparent 70%);"></div>
39
+ </div>
40
+
41
+ <div class="max-w-6xl mx-auto">
42
+
43
+ <!-- Header -->
44
+ <div class="flex items-center justify-between mb-8">
45
+ <div>
46
+ <h1 class="text-3xl font-bold text-white flex items-center gap-3">
47
+ <span class="text-4xl">🚀</span>
48
+ <span>VinOS <span class="text-indigo-400">Indexing</span> Dashboard</span>
49
+ </h1>
50
+ <p class="text-slate-400 mt-1 text-sm">Agency-Grade Bulk Indexing Command Center</p>
51
+ </div>
52
+ <div class="text-right">
53
+ <div class="text-xs text-slate-500 console-font mb-1">STATUS</div>
54
+ <div id="serverStatus" class="flex items-center gap-2 text-sm font-medium text-emerald-400">
55
+ <div class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></div> Connected
56
+ </div>
57
+ </div>
58
+ </div>
59
+
60
+ <!-- Quota Meter -->
61
+ <div class="glass rounded-2xl p-5 mb-6 glow">
62
+ <div class="flex items-center justify-between mb-3">
63
+ <div>
64
+ <div class="text-sm font-medium text-slate-300">Google Indexing API Quota</div>
65
+ <div class="text-xs text-slate-500 mt-0.5">Resets at midnight UTC · Limit: 200/day</div>
66
+ </div>
67
+ <div class="text-right">
68
+ <div id="quotaText" class="text-2xl font-bold text-white console-font">–/200</div>
69
+ <div id="quotaRemaining" class="text-xs text-slate-400 mt-0.5">Loading...</div>
70
+ </div>
71
+ </div>
72
+ <div class="w-full h-2.5 bg-slate-800 rounded-full overflow-hidden">
73
+ <div id="quotaBar" class="quota-bar h-full rounded-full" style="width:0%"></div>
74
+ </div>
75
+ <div class="flex justify-between text-xs text-slate-600 mt-1.5">
76
+ <span>0</span><span>Safe Zone (100)</span><span>200</span>
77
+ </div>
78
+ </div>
79
+
80
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
81
+
82
+ <!-- LEFT PANEL: URL Manager -->
83
+ <div class="space-y-5">
84
+
85
+ <!-- Site Selector -->
86
+ <div class="glass rounded-2xl p-5">
87
+ <h2 class="text-sm font-semibold text-slate-300 uppercase tracking-wider mb-4 flex items-center gap-2">
88
+ <span>🏢</span> Client Site
89
+ </h2>
90
+ <div class="flex gap-3">
91
+ <select id="siteSelect" class="flex-1 bg-slate-800/60 border border-slate-700 text-white rounded-xl px-4 py-2.5 text-sm focus:outline-none focus:border-indigo-500">
92
+ <option value="">Loading sites...</option>
93
+ </select>
94
+ <button onclick="fetchRecentPosts()" class="btn-primary px-4 py-2.5 rounded-xl text-sm font-medium text-white flex items-center gap-2">
95
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
96
+ Fetch Posts
97
+ </button>
98
+ </div>
99
+ </div>
100
+
101
+ <!-- Recent Posts Checklist -->
102
+ <div class="glass rounded-2xl p-5">
103
+ <div class="flex items-center justify-between mb-4">
104
+ <h2 class="text-sm font-semibold text-slate-300 uppercase tracking-wider flex items-center gap-2">
105
+ <span>📄</span> Recent Posts
106
+ </h2>
107
+ <div class="flex gap-2">
108
+ <button onclick="selectAll()" class="text-xs text-indigo-400 hover:text-indigo-300 px-2 py-1 rounded-lg hover:bg-indigo-500/10 transition">Select All</button>
109
+ <button onclick="selectNone()" class="text-xs text-slate-400 hover:text-slate-300 px-2 py-1 rounded-lg hover:bg-slate-500/10 transition">None</button>
110
+ </div>
111
+ </div>
112
+ <div id="postsList" class="space-y-1.5 max-h-80 overflow-y-auto pr-1">
113
+ <div class="text-slate-500 text-sm text-center py-8">Select a site and click "Fetch Posts"</div>
114
+ </div>
115
+ </div>
116
+
117
+ <!-- Manual URL Entry -->
118
+ <div class="glass rounded-2xl p-5">
119
+ <h2 class="text-sm font-semibold text-slate-300 uppercase tracking-wider mb-3 flex items-center gap-2">
120
+ <span>✏️</span> Manual URL Entry
121
+ </h2>
122
+ <textarea id="manualUrls" rows="5" placeholder="Paste URLs here, one per line...&#10;https://example.com/article-1&#10;https://example.com/article-2" class="w-full bg-slate-800/60 border border-slate-700 text-slate-300 rounded-xl px-4 py-3 text-sm console-font resize-none focus:outline-none focus:border-indigo-500 placeholder-slate-600"></textarea>
123
+ <button onclick="addManualUrls()" class="mt-2 w-full glass glass-hover px-4 py-2 rounded-xl text-sm text-slate-300 font-medium">
124
+ + Add to Queue
125
+ </button>
126
+ </div>
127
+ </div>
128
+
129
+ <!-- RIGHT PANEL: Queue & Console -->
130
+ <div class="space-y-5">
131
+
132
+ <!-- Index Queue -->
133
+ <div class="glass rounded-2xl p-5">
134
+ <div class="flex items-center justify-between mb-4">
135
+ <h2 class="text-sm font-semibold text-slate-300 uppercase tracking-wider flex items-center gap-2">
136
+ <span>📋</span> Index Queue
137
+ <span id="queueCount" class="bg-indigo-500/20 text-indigo-400 text-xs px-2 py-0.5 rounded-full font-normal">0 URLs</span>
138
+ </h2>
139
+ <button onclick="clearQueue()" class="text-xs text-red-400 hover:text-red-300 px-2 py-1 rounded-lg hover:bg-red-500/10 transition">Clear</button>
140
+ </div>
141
+ <div id="queueList" class="space-y-1.5 max-h-56 overflow-y-auto pr-1 mb-4">
142
+ <div class="text-slate-500 text-sm text-center py-6">Queue is empty</div>
143
+ </div>
144
+ <button onclick="startBulkIndex()" id="indexBtn" class="btn-primary w-full py-3 rounded-xl text-white font-semibold text-sm flex items-center justify-center gap-2">
145
+ <span>⚡</span> Safe Bulk Index
146
+ </button>
147
+ </div>
148
+
149
+ <!-- Live Console -->
150
+ <div class="glass rounded-2xl p-5 h-72 flex flex-col">
151
+ <div class="flex items-center justify-between mb-3">
152
+ <h2 class="text-sm font-semibold text-slate-300 uppercase tracking-wider flex items-center gap-2">
153
+ <span>🖥️</span> Live Console
154
+ </h2>
155
+ <button onclick="clearConsole()" class="text-xs text-slate-500 hover:text-slate-400">Clear</button>
156
+ </div>
157
+ <div id="console" class="flex-1 overflow-y-auto console-font text-xs space-y-1 pr-1">
158
+ <div class="log-info">VinOS Indexing Dashboard v6.0 ready.</div>
159
+ <div class="log-info">Quota resets at midnight UTC · Safe delay: 2s between requests.</div>
160
+ </div>
161
+ </div>
162
+
163
+ <!-- Summary Stats -->
164
+ <div class="grid grid-cols-3 gap-3">
165
+ <div class="glass rounded-xl p-3 text-center">
166
+ <div id="statSuccess" class="text-2xl font-bold text-emerald-400 console-font">0</div>
167
+ <div class="text-xs text-slate-500 mt-0.5">Submitted</div>
168
+ </div>
169
+ <div class="glass rounded-xl p-3 text-center">
170
+ <div id="statFailed" class="text-2xl font-bold text-red-400 console-font">0</div>
171
+ <div class="text-xs text-slate-500 mt-0.5">Failed</div>
172
+ </div>
173
+ <div class="glass rounded-xl p-3 text-center">
174
+ <div id="statSkipped" class="text-2xl font-bold text-amber-400 console-font">0</div>
175
+ <div class="text-xs text-slate-500 mt-0.5">Skipped</div>
176
+ </div>
177
+ </div>
178
+
179
+ </div>
180
+ </div>
181
+ </div>
182
+
183
+ <script>
184
+ const queue = new Set();
185
+
186
+ function log(msg, type = 'info') {
187
+ const el = document.createElement('div');
188
+ el.className = `log-${type}`;
189
+ const ts = new Date().toLocaleTimeString();
190
+ el.textContent = `[${ts}] ${msg}`;
191
+ const con = document.getElementById('console');
192
+ con.appendChild(el);
193
+ con.scrollTop = con.scrollHeight;
194
+ }
195
+
196
+ function clearConsole() { const c = document.getElementById('console'); c.innerHTML = ''; log('Console cleared.'); }
197
+
198
+ async function loadQuota() {
199
+ try {
200
+ const r = await fetch('/api/quota').then(r => r.json());
201
+ const pct = (r.used / r.total) * 100;
202
+ document.getElementById('quotaText').textContent = `${r.used}/200`;
203
+ document.getElementById('quotaBar').style.width = `${pct}%`;
204
+ document.getElementById('quotaRemaining').textContent = `${r.remaining} requests remaining today`;
205
+ document.getElementById('quotaBar').style.background = r.used > 150
206
+ ? 'linear-gradient(90deg, #ef4444, #dc2626)'
207
+ : r.used > 100 ? 'linear-gradient(90deg, #f59e0b, #d97706)'
208
+ : 'linear-gradient(90deg, #6366f1, #8b5cf6)';
209
+ } catch(e) { log('Could not load quota', 'warn'); }
210
+ }
211
+
212
+ async function loadSites() {
213
+ const sel = document.getElementById('siteSelect');
214
+ try {
215
+ const r = await fetch('/api/sites').then(r => r.json());
216
+ if (r.success && r.sites.length > 0) {
217
+ sel.innerHTML = r.sites.map(s => `<option value="${s}">${s}</option>`).join('');
218
+ log(`Loaded ${r.sites.length} client site(s): ${r.sites.join(', ')}`, 'success');
219
+ } else {
220
+ sel.innerHTML = '<option value="">No sites in WP_SITES_JSON</option>';
221
+ log('No sites configured in WP_SITES_JSON. Add sites in Hugging Face Secrets.', 'warn');
222
+ }
223
+ } catch(e) { log('Failed to load sites: ' + e.message, 'error'); }
224
+ }
225
+
226
+ function badgeFor(status) {
227
+ const map = { 'INDEXED': ['badge-indexed','🟢 Indexed'], 'PENDING': ['badge-pending','🟡 Pending'], 'NOT_INDEXED': ['badge-not-indexed','🔴 Not Indexed'], 'CHECKING': ['badge-checking','⏳ Checking...'], 'ERROR': ['badge-unknown','⚠ Error'] };
228
+ const [cls, text] = map[status] || ['badge-unknown', '❓ Unknown'];
229
+ return `<span class="${cls} text-xs px-2 py-0.5 rounded-full font-medium">${text}</span>`;
230
+ }
231
+
232
+ async function fetchRecentPosts() {
233
+ const siteId = document.getElementById('siteSelect').value;
234
+ if (!siteId) return log('Please select a site first.', 'warn');
235
+ const listEl = document.getElementById('postsList');
236
+ listEl.innerHTML = '<div class="text-slate-400 text-sm text-center py-4 flex items-center justify-center gap-2"><div class="w-4 h-4 border-2 border-indigo-400 border-t-transparent rounded-full spin"></div> Fetching from WordPress...</div>';
237
+ log(`Fetching recent posts from [${siteId}]...`, 'info');
238
+ try {
239
+ const r = await fetch(`/api/recent-posts?siteId=${encodeURIComponent(siteId)}`).then(r => r.json());
240
+ if (!r.success) { listEl.innerHTML = `<div class="text-red-400 text-sm p-3">${r.error}</div>`; log('Error: ' + r.error, 'error'); return; }
241
+ if (r.posts.length === 0) { listEl.innerHTML = '<div class="text-slate-500 text-sm text-center py-6">No posts found</div>'; return; }
242
+
243
+ log(`Found ${r.posts.length} posts. Checking index status...`, 'success');
244
+ listEl.innerHTML = r.posts.map((p, i) => `
245
+ <div class="url-row flex items-center gap-3 p-2 rounded-lg cursor-pointer transition" onclick="togglePost(${i})" data-url="${p.url}">
246
+ <input type="checkbox" id="post_${i}" class="w-4 h-4 accent-indigo-500 flex-shrink-0" onclick="event.stopPropagation(); syncCheckbox(${i})">
247
+ <div class="flex-1 min-w-0">
248
+ <div class="text-sm text-slate-300 truncate">${p.title}</div>
249
+ <div class="text-xs text-slate-500 console-font truncate">${p.url}</div>
250
+ </div>
251
+ <div id="status_${i}" class="flex-shrink-0">${badgeFor('CHECKING')}</div>
252
+ </div>
253
+ `).join('');
254
+
255
+ // Fire off status checks
256
+ r.posts.forEach(async (p, i) => {
257
+ try {
258
+ const s = await fetch(`/api/index-status?url=${encodeURIComponent(p.url)}`).then(r => r.json());
259
+ const el = document.getElementById(`status_${i}`);
260
+ if (el) el.innerHTML = badgeFor(s.status || 'UNKNOWN');
261
+ } catch(e) { const el = document.getElementById(`status_${i}`); if(el) el.innerHTML = badgeFor('ERROR'); }
262
+ });
263
+
264
+ } catch(e) { listEl.innerHTML = `<div class="text-red-400 text-sm p-3">${e.message}</div>`; log(e.message, 'error'); }
265
+ }
266
+
267
+ function togglePost(i) {
268
+ const cb = document.getElementById(`post_${i}`);
269
+ cb.checked = !cb.checked;
270
+ syncCheckbox(i);
271
+ }
272
+
273
+ function syncCheckbox(i) {
274
+ const cb = document.getElementById(`post_${i}`);
275
+ const row = cb.closest('.url-row');
276
+ const url = row.dataset.url;
277
+ if (cb.checked) queue.add(url); else queue.delete(url);
278
+ renderQueue();
279
+ }
280
+
281
+ function selectAll() {
282
+ document.querySelectorAll('.url-row').forEach((row, i) => {
283
+ const cb = document.getElementById(`post_${i}`);
284
+ if (cb) { cb.checked = true; queue.add(row.dataset.url); }
285
+ });
286
+ renderQueue();
287
+ }
288
+
289
+ function selectNone() {
290
+ document.querySelectorAll('.url-row').forEach((row, i) => {
291
+ const cb = document.getElementById(`post_${i}`);
292
+ if (cb) { cb.checked = false; queue.delete(row.dataset.url); }
293
+ });
294
+ renderQueue();
295
+ }
296
+
297
+ function addManualUrls() {
298
+ const raw = document.getElementById('manualUrls').value;
299
+ const urls = raw.split('\n').map(u => u.trim()).filter(u => u.startsWith('http'));
300
+ urls.forEach(u => queue.add(u));
301
+ document.getElementById('manualUrls').value = '';
302
+ log(`Added ${urls.length} URL(s) from manual entry.`, 'info');
303
+ renderQueue();
304
+ }
305
+
306
+ function clearQueue() { queue.clear(); renderQueue(); log('Queue cleared.', 'warn'); }
307
+
308
+ function renderQueue() {
309
+ const el = document.getElementById('queueList');
310
+ document.getElementById('queueCount').textContent = `${queue.size} URLs`;
311
+ if (queue.size === 0) { el.innerHTML = '<div class="text-slate-500 text-sm text-center py-6">Queue is empty</div>'; return; }
312
+ el.innerHTML = [...queue].map(url => `
313
+ <div class="flex items-center gap-2 p-2 rounded-lg glass-hover group">
314
+ <div class="flex-1 min-w-0 text-xs console-font text-slate-400 truncate">${url}</div>
315
+ <button onclick="queue.delete('${url}'); renderQueue();" class="flex-shrink-0 text-slate-600 hover:text-red-400 opacity-0 group-hover:opacity-100 transition">✕</button>
316
+ </div>
317
+ `).join('');
318
+ }
319
+
320
+ async function startBulkIndex() {
321
+ if (queue.size === 0) { log('Queue is empty. Add URLs first.', 'warn'); return; }
322
+ const btn = document.getElementById('indexBtn');
323
+ btn.disabled = true;
324
+ btn.innerHTML = '<div class="w-4 h-4 border-2 border-white border-t-transparent rounded-full spin"></div> Indexing...';
325
+
326
+ const urls = [...queue];
327
+ log(`🚀 Starting bulk indexing of ${urls.length} URLs (2s delay between requests)...`, 'info');
328
+ document.getElementById('statSuccess').textContent = '0';
329
+ document.getElementById('statFailed').textContent = '0';
330
+ document.getElementById('statSkipped').textContent = '0';
331
+
332
+ try {
333
+ const r = await fetch('/api/bulk-index', {
334
+ method: 'POST',
335
+ headers: { 'Content-Type': 'application/json' },
336
+ body: JSON.stringify({ urls })
337
+ }).then(r => r.json());
338
+
339
+ let success = 0, failed = 0;
340
+ r.results.forEach(res => {
341
+ if (res.success) { success++; log(`✅ Submitted: ${res.url}`, 'success'); }
342
+ else { failed++; log(`❌ Failed: ${res.url} — ${res.error}`, 'error'); }
343
+ });
344
+
345
+ if (r.skipped > 0) { log(`⚠️ ${r.skipped} URL(s) skipped — daily quota reached (200/day).`, 'warn'); }
346
+
347
+ document.getElementById('statSuccess').textContent = success;
348
+ document.getElementById('statFailed').textContent = failed;
349
+ document.getElementById('statSkipped').textContent = r.skipped || 0;
350
+ log(`Finished. Quota now at ${r.quotaUsed}/200.`, 'info');
351
+ loadQuota();
352
+ if (r.processed === urls.length) queue.clear();
353
+ renderQueue();
354
+ } catch(e) { log('Request failed: ' + e.message, 'error'); }
355
+
356
+ btn.disabled = false;
357
+ btn.innerHTML = '<span>⚡</span> Safe Bulk Index';
358
+ }
359
+
360
+ // Init
361
+ loadSites();
362
+ loadQuota();
363
+ setInterval(loadQuota, 60000); // refresh quota every minute
364
+ </script>
365
+ </body>
366
+ </html>
server.js CHANGED
@@ -50,6 +50,88 @@ app.use(cors());
50
  app.use(express.json());
51
  app.use(express.static(path.join(__dirname, 'public')));
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  // API Routes
54
  app.get('/api/profile', (req, res) => {
55
  const db = memory.readDB();
 
50
  app.use(express.json());
51
  app.use(express.static(path.join(__dirname, 'public')));
52
 
53
+ // ============================================
54
+ // BULK INDEXING DASHBOARD API
55
+ // ============================================
56
+ app.get('/indexer', (req, res) => {
57
+ res.sendFile(path.join(__dirname, 'public', 'indexer.html'));
58
+ });
59
+
60
+ app.get('/api/sites', (req, res) => {
61
+ try {
62
+ const sites = JSON.parse(process.env.WP_SITES_JSON || '{}');
63
+ res.json({ success: true, sites: Object.keys(sites) });
64
+ } catch (e) {
65
+ res.json({ success: false, error: 'WP_SITES_JSON not configured' });
66
+ }
67
+ });
68
+
69
+ app.get('/api/recent-posts', async (req, res) => {
70
+ const { siteId } = req.query;
71
+ try {
72
+ const sites = JSON.parse(process.env.WP_SITES_JSON || '{}');
73
+ const site = sites[siteId];
74
+ if (!site) return res.json({ success: false, error: 'Unknown siteId' });
75
+
76
+ const authBuffer = Buffer.from(`${site.user}:${site.pass}`).toString('base64');
77
+ const axios = require('axios');
78
+ const response = await axios.get(`${site.url}/wp-json/wp/v2/posts?per_page=20&orderby=date&order=desc&_fields=link,title,date,status`, {
79
+ headers: { 'Authorization': `Basic ${authBuffer}` }
80
+ });
81
+ const posts = response.data.map(p => ({ url: p.link, title: p.title.rendered, date: p.date }));
82
+ res.json({ success: true, posts });
83
+ } catch (e) {
84
+ res.json({ success: false, error: e.message });
85
+ }
86
+ });
87
+
88
+ app.get('/api/index-status', async (req, res) => {
89
+ const { url } = req.query;
90
+ try {
91
+ const result = await googleIndexer.getStatus(url);
92
+ res.json(result);
93
+ } catch (e) {
94
+ res.json({ success: false, status: 'UNKNOWN', error: e.message });
95
+ }
96
+ });
97
+
98
+ const DAILY_QUOTA = 200;
99
+ const QUOTA_DELAY_MS = 2000;
100
+ let todayQuotaDate = new Date().toDateString();
101
+ let todayQuotaUsed = 0;
102
+
103
+ app.post('/api/bulk-index', async (req, res) => {
104
+ const { urls } = req.body;
105
+ if (!urls || !Array.isArray(urls)) return res.json({ success: false, error: 'Invalid payload' });
106
+
107
+ // Reset quota counter on new day
108
+ if (new Date().toDateString() !== todayQuotaDate) {
109
+ todayQuotaDate = new Date().toDateString();
110
+ todayQuotaUsed = 0;
111
+ }
112
+
113
+ const remaining = DAILY_QUOTA - todayQuotaUsed;
114
+ const toProcess = urls.slice(0, remaining);
115
+ const skipped = urls.length - toProcess.length;
116
+
117
+ const results = [];
118
+ for (const url of toProcess) {
119
+ const r = await googleIndexer.submitUrl(url);
120
+ todayQuotaUsed++;
121
+ results.push({ url, success: r.success, error: r.error || null });
122
+ await new Promise(resolve => setTimeout(resolve, QUOTA_DELAY_MS));
123
+ }
124
+
125
+ res.json({ success: true, processed: toProcess.length, skipped, quotaUsed: todayQuotaUsed, results });
126
+ });
127
+
128
+ app.get('/api/quota', (req, res) => {
129
+ if (new Date().toDateString() !== todayQuotaDate) { todayQuotaDate = new Date().toDateString(); todayQuotaUsed = 0; }
130
+ res.json({ used: todayQuotaUsed, total: DAILY_QUOTA, remaining: DAILY_QUOTA - todayQuotaUsed });
131
+ });
132
+ // ============================================
133
+ app.use(express.static(path.join(__dirname, 'public')));
134
+
135
  // API Routes
136
  app.get('/api/profile', (req, res) => {
137
  const db = memory.readDB();
skills/google_indexer.js CHANGED
@@ -64,6 +64,34 @@ class GoogleIndexer {
64
  }
65
  return { success: true, results };
66
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  }
68
 
69
  module.exports = new GoogleIndexer();
 
64
  }
65
  return { success: true, results };
66
  }
67
+
68
+ /**
69
+ * Get the indexing status / metadata of a URL
70
+ */
71
+ async getStatus(url) {
72
+ console.log(`[Google Indexer] Checking status for: ${url}`);
73
+ try {
74
+ const authClient = await this.getAuthClient();
75
+ const indexing = google.indexing({ version: 'v3', auth: authClient });
76
+
77
+ const res = await indexing.urlNotifications.getMetadata({ url });
78
+ const latestUpdate = res.data.latestUpdate;
79
+
80
+ const isIndexed = latestUpdate && latestUpdate.type === 'URL_UPDATED';
81
+ return {
82
+ success: true,
83
+ url,
84
+ status: isIndexed ? 'INDEXED' : 'PENDING',
85
+ lastNotified: latestUpdate?.notifyTime || null
86
+ };
87
+ } catch (error) {
88
+ // 404 means Google has no record of this URL
89
+ if (error?.response?.status === 404 || error?.code === 404) {
90
+ return { success: true, url, status: 'NOT_INDEXED', lastNotified: null };
91
+ }
92
+ return { success: false, url, status: 'ERROR', error: error.message };
93
+ }
94
+ }
95
  }
96
 
97
  module.exports = new GoogleIndexer();