Profile avatar için cache eklendi

This commit is contained in:
2025-12-04 21:32:55 +03:00
parent bbc245ced1
commit 0f181833e5

View File

@@ -232,8 +232,17 @@ app.get("/api/profile/avatar", requireAuth, (req, res) => {
if (!fs.existsSync(AVATAR_PATH)) {
return res.status(404).json({ error: "Avatar bulunamadı" });
}
const stat = fs.statSync(AVATAR_PATH);
const etag = `W/"${stat.size}-${stat.mtimeMs}"`;
if (req.headers["if-none-match"] === etag) {
return res.status(304).end();
}
res.setHeader("Content-Type", "image/png");
res.setHeader("Cache-Control", "no-store");
res.setHeader("Cache-Control", "public, max-age=2592000, stale-while-revalidate=86400");
res.setHeader("ETag", etag);
res.setHeader("Last-Modified", stat.mtime.toUTCString());
fs.createReadStream(AVATAR_PATH).pipe(res);
});