failed gracefully on invalid chunk index
This commit is contained in:
parent
7f4db0c1dc
commit
c4a3e4e9a7
1 changed files with 7 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue