diff --git a/packages/detection/src/platforms/cto51.js b/packages/detection/src/platforms/cto51.js index 781c097..d32c2fd 100644 --- a/packages/detection/src/platforms/cto51.js +++ b/packages/detection/src/platforms/cto51.js @@ -6,20 +6,16 @@ import { convertAvatarToBase64 } from '../utils.js' * 1. Fetch publish page (authenticated) — if it contains blog user ID, user is logged in * 2. Extract avatar from publish page * 3. Fetch user profile page (public) to extract username from title - * - * Note: Cookie-based login check (_identity) is unreliable because different - * login flows may not set _identity. Instead we use the publish page response - * as the definitive login indicator. */ export async function detectCTO51User() { try { - console.log('[COSE] 51CTO Detection: Fetching publish page') + console.log('[COSE] 51CTO Detection: Starting') let username = '' let avatar = '' let blogUserId = '' - // Fetch publish page (requires auth, cookies are sent correctly) + // Fetch publish page (requires auth) const publishResp = await fetch('https://blog.51cto.com/blogger/publish', { method: 'GET', credentials: 'include', @@ -28,18 +24,16 @@ export async function detectCTO51User() { }) const publishHtml = await publishResp.text() - // Extract blog user ID from profile link: href="https://blog.51cto.com/15736437" + // Extract blog user ID from profile link const blogIdMatch = publishHtml.match(/blog\.51cto\.com\/(\d{5,})/) if (!blogIdMatch) { - // No blog user ID means not logged in (redirected to login page) console.log('[COSE] 51CTO: Not logged in (no blog user ID in publish page)') return { loggedIn: false } } blogUserId = blogIdMatch[1] console.log(`[COSE] 51CTO blog user ID: ${blogUserId}`) - // Extract avatar from publish page nav: - // Skip default placeholder (noavatar) + // Extract avatar from publish page nav const avatarMatch = publishHtml.match(/]*data-uid=["']\d+["'][^>]*src=["'](https?:\/\/[^"']+)["']/i) || publishHtml.match(/]*src=["'](https:\/\/s[0-9]*\.51cto\.com\/oss\/[^"']+)["'][^>]*data-uid/i) if (avatarMatch && !avatarMatch[1].includes('noavatar')) { @@ -53,8 +47,6 @@ export async function detectCTO51User() { headers: { 'Accept': 'text/html' }, }) const profileHtml = await profileResp.text() - - // Extract username from page title: "xxxxx的博客_..." const nickMatch = profileHtml.match(/([^<]+?)的博客/) if (nickMatch) { username = nickMatch[1].trim() @@ -65,7 +57,6 @@ export async function detectCTO51User() { console.log(`[COSE] 51CTO user info: ${username}, avatar: ${avatar ? 'found' : 'not found'}`) - // Convert 51cto.com avatar to base64 data URL to bypass CORS/ORB if (avatar && avatar.includes('51cto.com')) { avatar = await convertAvatarToBase64(avatar, 'https://blog.51cto.com/') }