diff --git a/applications/highlight-termbin/index.js b/applications/highlight-termbin/index.js index 2414ddb..fb39781 100644 --- a/applications/highlight-termbin/index.js +++ b/applications/highlight-termbin/index.js @@ -10,15 +10,15 @@ const cfgLoader = require(path.join('..', '..', 'config-loader'))(path.join(__di index: 'index.html' }) -function encodeSpecial (string) { +function encodeSpecial (string) { let i = string.length - let a = [] + const a = [] - while (i--) { + while (i--) { var iC = string[i].charCodeAt() - if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) { + if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) { a[i] = '&#' + iC + ';' - } else { + } else { a[i] = string[i] } } @@ -26,16 +26,16 @@ function encodeSpecial (string) { } async function init () { - let config = await cfgLoader - let root = path.resolve(config.root) + const config = await cfgLoader + const root = path.resolve(config.root) await fsp.access(root, fs.constants.F_OK) router.get('/:name', async (req, res, next) => { - let name = req.params.name + const name = req.params.name if (name.length > 5) { try { - let text = await fsp.readFile(path.join(root, 'index.html')) + const text = await fsp.readFile(path.join(root, 'index.html')) res.send(text) } catch (e) { res.status(403) @@ -43,15 +43,15 @@ async function init () { return res.end() } - let fichePath = path.join(root, name, 'index.txt') + const fichePath = path.join(root, name, 'index.txt') + const ua = req.get('User-Agent') let reqRaw = req.query.raw != null - let ua = req.get('User-Agent') if (!reqRaw && ua && (ua.match(/curl\//i) != null || ua.match(/wget\//i) != null)) reqRaw = true - let text + let text try { - text = await fsp.readFile(fichePath, {encoding: 'utf8'}) + text = await fsp.readFile(fichePath, { encoding: 'utf8' }) } catch (e) { return res.status(404).end() } @@ -62,22 +62,22 @@ async function init () { return res.set('Content-Type', 'text/plain').send(text) } - let etext = encodeSpecial(text) - let payload = - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '
' + etext + '
' + - '' + - '' + - '' - - res.set('Content-Type', 'application/xhtml+xml').send(payload) + const etext = encodeSpecial(text) + const payload = ` + + + + + + + + +
${etext}
+ + + + ` + res.set('Content-Type', 'text/html; charset=UTF-8').send(payload) }) router.get('/', (req, res, next) => {