Open FunctionalMetatable opened 3 years ago
Less requests to scratch's servers.
// [..] const userIds = db.get("userIds") // [..] app.get("/api/user/:user/picture", async (req, res) => { let user = await userIds.findOne({ name: { $regex: new RegExp(`^${req.params.user}$`) } }) if (!user) { let res = await fetch(`https://api.scratch.mit.edu/users/${req.params.user}/`) let { id, username } = await res.json() user = await userIds.insert({ id, name: username }) } res.redirect(301, `https://cdn2.scratch.mit.edu/get_image/user/${user.id}_500x500.png?my-ocular`) })
this is a good idea.. but it'll break if someone changes their username. i will implement caching on the endpoint though
Less requests to scratch's servers.