mirror of
https://github.com/doocs/cose.git
synced 2026-08-28 23:02:10 +08:00
chore: update comment
This commit is contained in:
@@ -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: <img data-uid="..." src="https://s2.51cto.com/oss/...">
|
||||
// Skip default placeholder (noavatar)
|
||||
// Extract avatar from publish page nav
|
||||
const avatarMatch = publishHtml.match(/<img[^>]*data-uid=["']\d+["'][^>]*src=["'](https?:\/\/[^"']+)["']/i) ||
|
||||
publishHtml.match(/<img[^>]*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(/<title>([^<]+?)的博客/)
|
||||
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/')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user