export async function whatsmyname(req) { const { searchParams: sp } = new URL(req.url); const username = sp.get('username'); const mode = sp.get('mode') || 'all'; const rescan = sp.get('rescan') || 'false'; if (!username) { return { error: "missing username", usage: { all: "/whatsmyname?username=archtheslut", exist: "/whatsmyname?username=archtheslut&mode=exist", notexist: "/whatsmyname?username=archtheslut&mode=notexist", rescan: "/whatsmyname?username=archtheslut&rescan=true" } }; } try { const res = await fetch("https://api.whatsmyname.io/discoverprofile", { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ source: username, type: "name", rescan: rescan === 'true' }) }); const data = await res.json(); if (data.error) return { error: data.error }; const results = data.result.map(r => ({ url: r.url, source: r.source, exists: r.isExist, category: r.category })); if (mode === 'exist') { const found = results.filter(r => r.exists); return { username, rescan: rescan === 'true', total: found.length, found }; } if (mode === 'notexist') { const notFound = results.filter(r => !r.exists); return { username, rescan: rescan === 'true', total: notFound.length, not_found: notFound }; } const existCount = results.filter(r => r.exists).length; return { username, rescan: rescan === 'true', total: results.length, exists: existCount, not_exists: results.length - existCount, results }; } catch (err) { return { error: err.message }; } }