diff --git a/.eslintrc.yaml b/.eslintrc.yaml deleted file mode 100644 index 2b32b24..0000000 --- a/.eslintrc.yaml +++ /dev/null @@ -1,10 +0,0 @@ -env: - es6: true - node: true -extends: 'eslint:recommended' -parserOptions: - ecmaVersion: 2018 - sourceType: module -rules: - no-console: off - prefer-const: error diff --git a/.prettierrc.yaml b/.prettierrc.yaml deleted file mode 100644 index f1410ca..0000000 --- a/.prettierrc.yaml +++ /dev/null @@ -1,3 +0,0 @@ -useTabs: true -singleQuote: true -trailingComma: all diff --git a/sfs.js b/sfs.js index 02d59a7..dbfea3b 100644 --- a/sfs.js +++ b/sfs.js @@ -9,11 +9,8 @@ const util = require('util'); const readdir = util.promisify(fs.readdir); const stat = util.promisify(fs.stat); -const sendError = (res, code, message, headers) => { - res.writeHead(code, { - 'content-type': 'text/html; charset=utf-8', - ...headers, - }); +const send_error = (res, code, message) => { + res.writeHead(code, { 'content-type': 'text/html; charset=utf-8' }); res.end(`
@@ -26,7 +23,7 @@ const sendError = (res, code, message, headers) => { }; const prefixes = ' KMGT'; -const humanizeSize = size => { +const humanize_size = size => { let t = 0; while (size >= 1024) { size /= 1024; @@ -47,14 +44,14 @@ http .createServer(async (req, res) => { const path = '.' + decodeURIComponent(req.url); if (!path.startsWith('./') || path.includes('/..') || path.includes('\\')) { - sendError(res, 403, 'Forbidden'); + send_error(res, 403, 'Forbidden'); return; } let stats; try { stats = await stat(path); } catch (e) { - sendError(res, 404, 'Not Found'); + send_error(res, 404, 'Not Found'); return; } if (stats.isFile()) { @@ -85,7 +82,7 @@ http }); } fs.createReadStream(path, range) - .on('error', () => sendError(res, 500, 'Internal Server Error')) + .on('error', () => send_error(res, 500, 'Internal Server Error')) .pipe(res); return; } @@ -95,15 +92,11 @@ http res.end(); return; } - const dir = (await Promise.all( - (await readdir(path)).map(async file => [ - file, - await stat(path + file), - file.replace(/\d+/g, _ => '1'.repeat(_.length - 1) + '0' + _), - ]), - )).sort( - (a, b) => +a[1].isFile() - +b[1].isFile() || a[2].localeCompare(b[2]), - ); + const dir = (await Promise.all((await readdir(path)).map(async file => [ + file, + await stat(path + file), + file.replace(/\d+/g, _ => '1'.repeat(_.length - 1) + '0' + _), + ]))).sort((a, b) => +a[1].isFile() - +b[1].isFile() || a[2].localeCompare(b[2])); if (path !== './') { dir.unshift(['..', { isFile: () => false, isDirectory: () => true }]); } @@ -115,21 +108,18 @@ http