Skip to content

Commit

Permalink
Merge pull request #1 from RooRay/5a2cb55c
Browse files Browse the repository at this point in the history
Make text files also display in the browser first
  • Loading branch information
RooRay authored May 24, 2024
2 parents a9ab104 + 68071f4 commit d869b64
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export async function handleFile(event) {
event.waitUntil(cache.put(event.request, response.clone()));
}

// If the file is an image, instruct the browser to display it in the browser.
if (contentType.startsWith('image/')) {
// If the file is an image or a text file, instruct the browser to display it in the browser.
if (contentType.startsWith('image/') || contentType === 'text/plain') {
const disposition = `inline; filename="${url.pathname.split('/').pop()}"`;
response.headers.set('Content-Disposition', disposition);
}
Expand All @@ -40,7 +40,9 @@ function getContentTypeFromExtension(pathname) {
return 'image/jpeg';
case 'png':
return 'image/png';
// Add more cases for other image formats if needed.
case 'txt':
return 'text/plain';
// Add more cases for other formats if needed.
default:
return 'application/octet-stream'; // Fallback content type.
}
Expand Down

0 comments on commit d869b64

Please sign in to comment.