fix avatar serving using readFile instead of stream
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { FastifyInstance } from "fastify";
|
import { FastifyInstance } from "fastify";
|
||||||
import { existsSync, mkdirSync, createReadStream } from "node:fs";
|
import { existsSync, mkdirSync } from "node:fs";
|
||||||
import { unlink, writeFile, realpath } from "node:fs/promises";
|
import { unlink, writeFile, realpath, readFile } from "node:fs/promises";
|
||||||
import { resolve, extname, sep } from "node:path";
|
import { resolve, extname, sep } from "node:path";
|
||||||
import { randomBytes } from "node:crypto";
|
import { randomBytes } from "node:crypto";
|
||||||
import prisma from "../lib/prisma.js";
|
import prisma from "../lib/prisma.js";
|
||||||
@@ -172,11 +172,13 @@ export default async function avatarRoutes(app: FastifyInstance) {
|
|||||||
".png": "image/png", ".webp": "image/webp",
|
".png": "image/png", ".webp": "image/webp",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buf = await readFile(realFile);
|
||||||
reply
|
reply
|
||||||
.header("Content-Type", mimeMap[ext] || "application/octet-stream")
|
.header("Content-Type", mimeMap[ext] || "application/octet-stream")
|
||||||
|
.header("Content-Length", buf.length)
|
||||||
.header("Cache-Control", "public, max-age=3600, stale-while-revalidate=86400")
|
.header("Cache-Control", "public, max-age=3600, stale-while-revalidate=86400")
|
||||||
.header("X-Content-Type-Options", "nosniff")
|
.header("X-Content-Type-Options", "nosniff")
|
||||||
.send(createReadStream(filePath));
|
.send(buf);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user