Created
March 30, 2020 21:11
-
-
Save hasparus/c70b93781b0081232e2470aa99f26c18 to your computer and use it in GitHub Desktop.
avatar = facebook || tinygraphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextApiResponse, NextApiRequest } from "next"; | |
import fetch from "isomorphic-unfetch"; | |
export default async function avatar( | |
req: NextApiRequest, | |
res: NextApiResponse | |
) { | |
const { | |
query: { username_slug }, | |
} = req; | |
let userAvatar = | |
"https://www.tinygraphs.com/spaceinvaders/" + | |
`${username_slug}?theme=heatwave&numcolors=4&size=220&fmt=svg`; | |
try { | |
const gravatarResponse = await fetch( | |
`https://unavatar.now.sh/facebook/${username_slug}?json&fallback=false` | |
).then((r) => r.json()); | |
userAvatar = gravatarResponse.url || userAvatar; | |
} catch { | |
// nah, we don't care | |
} | |
res.writeHead(302, { Location: userAvatar }).end(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment