fix stupid xml crap
This commit is contained in:
parent
3c617239e2
commit
16c8cc6cee
@ -12,7 +12,7 @@ const cfgLoader = require(path.join('..', '..', 'config-loader'))(path.join(__di
|
|||||||
|
|
||||||
function encodeSpecial (string) {
|
function encodeSpecial (string) {
|
||||||
let i = string.length
|
let i = string.length
|
||||||
let a = []
|
const a = []
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
var iC = string[i].charCodeAt()
|
var iC = string[i].charCodeAt()
|
||||||
@ -26,16 +26,16 @@ function encodeSpecial (string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function init () {
|
async function init () {
|
||||||
let config = await cfgLoader
|
const config = await cfgLoader
|
||||||
let root = path.resolve(config.root)
|
const root = path.resolve(config.root)
|
||||||
|
|
||||||
await fsp.access(root, fs.constants.F_OK)
|
await fsp.access(root, fs.constants.F_OK)
|
||||||
|
|
||||||
router.get('/:name', async (req, res, next) => {
|
router.get('/:name', async (req, res, next) => {
|
||||||
let name = req.params.name
|
const name = req.params.name
|
||||||
if (name.length > 5) {
|
if (name.length > 5) {
|
||||||
try {
|
try {
|
||||||
let text = await fsp.readFile(path.join(root, 'index.html'))
|
const text = await fsp.readFile(path.join(root, 'index.html'))
|
||||||
res.send(text)
|
res.send(text)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.status(403)
|
res.status(403)
|
||||||
@ -43,9 +43,9 @@ async function init () {
|
|||||||
return res.end()
|
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 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
|
if (!reqRaw && ua && (ua.match(/curl\//i) != null || ua.match(/wget\//i) != null)) reqRaw = true
|
||||||
|
|
||||||
@ -62,22 +62,22 @@ async function init () {
|
|||||||
return res.set('Content-Type', 'text/plain').send(text)
|
return res.set('Content-Type', 'text/plain').send(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
let etext = encodeSpecial(text)
|
const etext = encodeSpecial(text)
|
||||||
let payload =
|
const payload = `
|
||||||
'<?xml version="1.0" encoding="UTF-8"?>' +
|
<!DOCTYPE html>
|
||||||
'<html xmlns="http://www.w3.org/1999/xhtml" class="hljs">' +
|
<html class="hljs">
|
||||||
'<head>' +
|
<head>
|
||||||
'<link rel="stylesheet" href="/assets/css/t.css" />' +
|
<link rel="stylesheet" href="/assets/css/t.css" />
|
||||||
'<link rel="stylesheet" href="/assets/css/t-styles/' + config.style + '.css" />' +
|
<link rel="stylesheet" href="/assets/css/t-styles/${config.style}.css" />
|
||||||
'<script src="/assets/js/highlight.min.js"></script>' +
|
<script src="/assets/js/highlight.min.js"></script>
|
||||||
'</head>' +
|
</head>
|
||||||
'<body>' +
|
<body>
|
||||||
'<pre><code>' + etext + '</code></pre>' +
|
<pre><code>${etext}</code></pre>
|
||||||
'<script>hljs.initHighlightingOnLoad();</script>' +
|
<script>hljs.initHighlightingOnLoad();</script>
|
||||||
'</body>' +
|
</body>
|
||||||
'</html>'
|
</html>
|
||||||
|
`
|
||||||
res.set('Content-Type', 'application/xhtml+xml').send(payload)
|
res.set('Content-Type', 'text/html; charset=UTF-8').send(payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/', (req, res, next) => {
|
router.get('/', (req, res, next) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user