Skip to content

Commit 49b4338

Browse files
committed
fix: More file server wrapping
1 parent bea0179 commit 49b4338

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/back/index.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,8 +1391,10 @@ async function onFileServerRequestRuffle(pathname: string, url: URL, req: http.I
13911391
if (req.method === 'GET' || req.method === 'HEAD') {
13921392
req.on('error', (err) => {
13931393
log.error('Launcher', `Error serving Game file - ${err}`);
1394-
res.writeHead(500);
1395-
res.end();
1394+
if (!res.writableEnded) {
1395+
res.writeHead(500);
1396+
res.end();
1397+
}
13961398
});
13971399
fs.stat(filePath)
13981400
.then((stats) => {
@@ -1446,8 +1448,10 @@ async function onFileServerRequestImages(pathname: string, url: URL, req: http.I
14461448
})
14471449
.on('error', async (err) => {
14481450
log.error('Launcher', `Error writing Game image - ${err}`);
1449-
res.writeHead(500);
1450-
res.end();
1451+
if (!res.writableEnded) {
1452+
res.writeHead(500);
1453+
res.end();
1454+
}
14511455
});
14521456
return;
14531457
}
@@ -1456,8 +1460,10 @@ async function onFileServerRequestImages(pathname: string, url: URL, req: http.I
14561460
} else if (req.method === 'GET' || req.method === 'HEAD') {
14571461
req.on('error', (err) => {
14581462
log.error('Launcher', `Error serving Game image - ${err}`);
1459-
res.writeHead(500);
1460-
res.end();
1463+
if (!res.writableEnded) {
1464+
res.writeHead(500);
1465+
res.end();
1466+
}
14611467
});
14621468
fs.stat(filePath)
14631469
.then((stats) => {
@@ -1481,8 +1487,10 @@ async function onFileServerRequestImages(pathname: string, url: URL, req: http.I
14811487
.catch(async (err) => {
14821488
if (err.code !== 'ENOENT') {
14831489
// Can't read file
1484-
res.writeHead(500);
1485-
res.end();
1490+
if (!res.writableEnded) {
1491+
res.writeHead(500);
1492+
res.end();
1493+
}
14861494
} else {
14871495
// File missing
14881496
if (!state.preferences.onDemandImages) {
@@ -1663,22 +1671,28 @@ async function updateFileServerDownloadQueue() {
16631671
await fs.ensureDir(dirPath);
16641672
} catch {
16651673
log.error('Images', 'Failed to create folder for on-demand image: ' + dirPath);
1666-
item.res.writeHead(500);
1674+
if (!item.res.writableEnded) {
1675+
item.res.writeHead(500);
1676+
}
16671677
return;
16681678
}
16691679
try {
16701680
await fs.promises.writeFile(filePath, imageData, 'binary');
16711681
} catch {
16721682
log.error('Images', 'Failed to save file for on-demand image: ' + filePath);
1673-
item.res.writeHead(500);
1683+
if (!item.res.writableEnded) {
1684+
item.res.writeHead(500);
1685+
}
16741686
return;
16751687
}
16761688

16771689
item.res.writeHead(200);
16781690
item.res.write(imageData);
16791691
})
16801692
.catch((err) => {
1681-
item.res.writeHead(404);
1693+
if (!item.res.writableEnded) {
1694+
item.res.writeHead(400);
1695+
}
16821696
})
16831697
.finally(async () => {
16841698
removeFileServerDownloadItem(item);

0 commit comments

Comments
 (0)