failed gracefully on invalid chunk index

This commit is contained in:
DecDuck
2024-10-23 12:36:09 +11:00
parent 7f4db0c1dc
commit c4a3e4e9a7

View File

@ -49,6 +49,13 @@ export default defineEventHandler(async (h3) => {
const start = chunkIndex * chunkSize;
const end = Math.min((chunkIndex + 1) * chunkSize, gameFileStats.size);
if (start >= end)
throw createError({
statusCode: 400,
statusMessage: "Invalid chunk index",
});
const gameReadStream = fs.createReadStream(gameFile, { start, end });
return sendStream(h3, gameReadStream);