From 62f1dba7653ff19ee1d38f0b79592afb052c58b4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 27 May 2024 16:25:37 -0300 Subject: write: live-dev-server: factor out getContentType --- src/write/build-modes/live-dev-server.js | 65 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'src/write/build-modes') diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js index 389f5f4c..0f8f7607 100644 --- a/src/write/build-modes/live-dev-server.js +++ b/src/write/build-modes/live-dev-server.js @@ -91,6 +91,38 @@ export function getCLIOptions() { }; } +const getContentType = extname => ({ + // BRB covering all my bases + 'aac': 'audio/aac', + 'bmp': 'image/bmp', + 'css': 'text/css', + 'csv': 'text/csv', + 'gif': 'image/gif', + 'ico': 'image/vnd.microsoft.icon', + 'jpg': 'image/jpeg', + 'jpeg': 'image/jpeg', + 'js': 'text/javascript', + 'mjs': 'text/javascript', + 'mp3': 'audio/mpeg', + 'mp4': 'video/mp4', + 'oga': 'audio/ogg', + 'ogg': 'audio/ogg', + 'ogv': 'video/ogg', + 'opus': 'audio/opus', + 'png': 'image/png', + 'pdf': 'application/pdf', + 'svg': 'image/svg+xml', + 'ttf': 'font/ttf', + 'txt': 'text/plain', + 'wav': 'audio/wav', + 'weba': 'audio/webm', + 'webm': 'video/webm', + 'woff': 'font/woff', + 'woff2': 'font/woff2', + 'xml': 'application/xml', + 'zip': 'application/zip', +})[extname]; + export async function go({ cliOptions, @@ -266,38 +298,7 @@ export async function go({ } const extname = path.extname(safePath).slice(1).toLowerCase(); - - const contentType = { - // BRB covering all my bases - 'aac': 'audio/aac', - 'bmp': 'image/bmp', - 'css': 'text/css', - 'csv': 'text/csv', - 'gif': 'image/gif', - 'ico': 'image/vnd.microsoft.icon', - 'jpg': 'image/jpeg', - 'jpeg': 'image/jpeg', - 'js': 'text/javascript', - 'mjs': 'text/javascript', - 'mp3': 'audio/mpeg', - 'mp4': 'video/mp4', - 'oga': 'audio/ogg', - 'ogg': 'audio/ogg', - 'ogv': 'video/ogg', - 'opus': 'audio/opus', - 'png': 'image/png', - 'pdf': 'application/pdf', - 'svg': 'image/svg+xml', - 'ttf': 'font/ttf', - 'txt': 'text/plain', - 'wav': 'audio/wav', - 'weba': 'audio/webm', - 'webm': 'video/webm', - 'woff': 'font/woff', - 'woff2': 'font/woff2', - 'xml': 'application/xml', - 'zip': 'application/zip', - }[extname]; + const contentType = getContentType(extname); let fd, size; try { -- cgit 1.3.0-6-gf8a5