// functions/user/@[username].js export async function onRequest(context) { const { request, params, env } = context; const userAgent = request.headers.get('User-Agent') || ''; const isBot = /discordbot|twitterbot|facebookexternalhit|bingbot|googlebot|slurp|whatsapp|pinterest|slackbot/i.test( userAgent ); const username = params.username; if (isBot && username) { try { const POCKETBASE_URL = 'https://data.samidy.xyz'; const filter = `username="${username}"`; const profileUrl = `${POCKETBASE_URL}/api/collections/DB_users/records?filter=${encodeURIComponent(filter)}&fields=username,display_name,avatar_url,banner,about,status`; const response = await fetch(profileUrl); if (!response.ok) throw new Error(`PocketBase error: ${response.status}`); const data = await response.json(); const profile = data.items && data.items.length > 0 ? data.items[0] : null; if (profile) { const displayName = profile.display_name || profile.username; const title = `${displayName} (@${profile.username})`; let description = profile.about || `View ${displayName}'s profile on Monochrome.`; if (profile.status) { try { const statusObj = JSON.parse(profile.status); description = `Listening to: ${statusObj.text}\n\n${description}`; } catch { description = `Listening to: ${profile.status}\n\n${description}`; } } const imageUrl = profile.avatar_url || 'https://monochrome.tf/assets/appicon.png'; const bannerUrl = profile.banner || ''; const pageUrl = new URL(request.url).href; const metaHtml = `
${description}