Skip to content

Commit

Permalink
Fix: card cache
Browse files Browse the repository at this point in the history
Philenst committed Jun 16, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 5e45469 commit 5263f06
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/users/card.js
Original file line number Diff line number Diff line change
@@ -9,15 +9,15 @@ export default async function(req, reply){

let user = (await database.awaitQuery(`SELECT * FROM users WHERE username_safe = "${getSafename(username)}" or discord = "${username}"`))[0]
if(!user) return reply.code(404).send({ error: "User not in the system" })
if(cache[user.userid]?.[year]?.card){
if(cache[user.userid]?.[year]?.[mode]?.card){
reply.header("content-type", "image/png")
return reply.send(cache[user.userid][year].card)
return reply.send(cache[user.userid][year][mode].card)
}
const request = await fetch(`http://localhost:${servicePort}/api/users/${username}/card?mode=${mode}&year=${year}`)
if(!request.ok){
return reply.code(request.status).send(await request.json())
}
cache[user.userid][year].card = Buffer.from(await (await request.blob()).arrayBuffer())
cache[user.userid][year][mode].card = Buffer.from(await (await request.blob()).arrayBuffer())
reply.header("content-type", "image/png")
return cache[user.userid][year].card;
return cache[user.userid][year][mode].card;
}

0 comments on commit 5263f06

Please sign in to comment.