/** * Blog Article Validation * Two-level validation: Content Similarity + Title Similarity */ // Helper to safely convert ObjectId to string function toStringId(id) { if (!id) { console.warn('[toStringId] Received empty id'); return ''; } if (typeof id === 'string') return id; // Handle Buffer object (MongoDB ObjectId as buffer) if (typeof id === 'object' && id.buffer) { console.log('[toStringId] Converting buffer to hex string'); const bytes = []; for (let i = 0; i < 12; i++) { if (id.buffer[i] !== undefined) { bytes.push(id.buffer[i].toString(16).padStart(2, '0')); } } const hexString = bytes.join(''); console.log('[toStringId] Hex string:', hexString); return hexString; } // Check for other common MongoDB ObjectId representations if (typeof id === 'object') { if (id.$oid) return id.$oid; if (id.id) return id.id; if (id._id) return id._id; } const result = String(id); console.log('[toStringId] Fallback String():', result); return result; } // Get auth token function getAuthToken() { return localStorage.getItem('admin_token'); } // API call helper async function apiCall(endpoint, options = {}) { const token = getAuthToken(); const defaultOptions = { cache: 'no-store', // Force fresh requests - prevent cached 500 errors headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` } }; const response = await fetch(endpoint, { ...defaultOptions, ...options }); if (response.status === 401) { localStorage.removeItem('admin_token'); window.location.href = '/admin/login.html'; throw new Error('Unauthorized'); } return response; } // Load all pending review articles async function loadValidationArticles() { const listDiv = document.getElementById('validation-list'); if (!listDiv) return; listDiv.innerHTML = '
${excerpt}
${post.excerpt}
No content available.
'}