From 103ac29db1f573a78bd5b7753558b9a0691df2b4 Mon Sep 17 00:00:00 2001 From: KroshSputnik <135224011+KroshSputnik@users.noreply.github.com> Date: Wed, 29 Jan 2025 21:27:12 +1100 Subject: [PATCH 01/12] Added new feature to simplify file size. I added a new option to enable to show the files in B, MB, GB, TB, PB. Not sure if I need to divide the size by 1024 or 1000. Feedback will be appreciated. --- index.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index e95390e..e5df122 100644 --- a/index.js +++ b/index.js @@ -97,6 +97,7 @@ function serveIndex(root, options) { var stylesheet = opts.stylesheet || defaultStylesheet; var template = opts.template || defaultTemplate; var view = opts.view || 'tiles'; + var simplifyFileSize = opts.simplifyFileSize; return function (req, res, next) { if (req.method !== 'GET' && req.method !== 'HEAD') { @@ -164,7 +165,7 @@ function serveIndex(root, options) { // not acceptable if (!type) return next(createError(406)); - serveIndex[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template, stylesheet); + serveIndex[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template, stylesheet, simplifyFileSize); }); }); }; @@ -174,7 +175,7 @@ function serveIndex(root, options) { * Respond with text/html. */ -serveIndex.html = function _html(req, res, files, next, dir, showUp, icons, path, view, template, stylesheet) { +serveIndex.html = function _html(req, res, files, next, dir, showUp, icons, path, view, template, stylesheet, simplifyFileSize) { var render = typeof template !== 'function' ? createHtmlRender(template) : template @@ -201,7 +202,8 @@ serveIndex.html = function _html(req, res, files, next, dir, showUp, icons, path fileList: fileList, path: path, style: style, - viewName: view + viewName: view, + simplifyFileSize:Boolean(simplifyFileSize) }; // render html @@ -260,7 +262,7 @@ serveIndex.plain = function _plain (req, res, files, next, dir, showUp, icons, p * @private */ -function createHtmlFileList(files, dir, useIcons, view) { +function createHtmlFileList(files, dir, useIcons, view, simplifyFileSize) { var html = '