Skip to content

Commit

Permalink
fix: fix incorrectly returned images
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Apr 30, 2024
1 parent cf8c5f2 commit 9eb93dc
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions packages/server/utils/directories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,53 @@ export function directoryWalker({
});
}

return fs.readFile(filePath, 'utf8', (err, content) => {
if (err?.code === 'ENOENT' && _htmlRedirect === true) {
return readDirectory(
filePath.replace('index.html', ''),
baseUrl,
(html: Error | string) => {
if (html instanceof Error) {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('404 Not Found');
return;
}

if (isHTML === true) {
html = addCounterMetadata(html, filePath);
return fs.readFile(
filePath,
isHTML === true ? 'utf8' : null,
(err, content) => {
if (err?.code === 'ENOENT' && _htmlRedirect === true) {
return readDirectory(
filePath.replace('index.html', ''),
baseUrl,
(html: Error | string) => {
if (html instanceof Error) {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('404 Not Found');
return;
}

if (isHTML === true) {
html = addCounterMetadata(html, filePath);
}

res.writeHead(200, {
'Content-Type': getContentType('file.html')
});
res.end(html);
}
);
}

res.writeHead(200, {
'Content-Type': getContentType('file.html')
});
res.end(html);
}
);
}
if (err?.code === 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('404 Not Found');
return;
}

if (err?.code === 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end('404 Not Found');
return;
}
if (err) {
res.writeHead(500);
res.end(`Server Error: ${err.code}`);
return;
}

if (err) {
res.writeHead(500);
res.end(`Server Error: ${err.code}`);
return;
}
if (isHTML === true) {
content = addCounterMetadata(content.toString(), filePath);
}

if (isHTML === true) {
content = addCounterMetadata(content, filePath);
res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
}

res.writeHead(200, { 'Content-Type': contentType });
res.end(content, 'utf-8');
});
);
}

export function readDirectory(
Expand Down

0 comments on commit 9eb93dc

Please sign in to comment.