Skip to content

Commit

Permalink
Fix 0 byte sharepic
Browse files Browse the repository at this point in the history
  • Loading branch information
floscher committed May 9, 2023
1 parent a47d21a commit ddeef80
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/src/routes/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const router: Router = express.Router();

let cachedSharepic: { url: string; bytes: Uint8Array } | undefined = undefined;
router.get("/github-sharepic", async (req, res) => {
const timestamp = Math.floor(Date.now() / 3600000);
const timestamp = Math.floor(Date.now() / 3600000); // round down to the hour
const url = `https://opengraph.githubassets.com/${timestamp}/${AppSettings.GITHUB_REPOSITORY_SLUG}`;
if (cachedSharepic && cachedSharepic.url === url) {
if (req.header("If-None-Match") === `${timestamp}`) {
Expand All @@ -30,7 +30,7 @@ router.get("/github-sharepic", async (req, res) => {
}
} else {
const sendCachedBytesOrNotFound = () => {
if (cachedSharepic) {
if (cachedSharepic && cachedSharepic.bytes.length > 0) {
res
.status(200)
.header("ETag", `${timestamp}`)
Expand Down

0 comments on commit ddeef80

Please sign in to comment.