diff --git a/applications/highlight-termbin/index.js b/applications/highlight-termbin/index.js index 34fa19a..2414ddb 100644 --- a/applications/highlight-termbin/index.js +++ b/applications/highlight-termbin/index.js @@ -10,6 +10,21 @@ const cfgLoader = require(path.join('..', '..', 'config-loader'))(path.join(__di index: 'index.html' }) +function encodeSpecial (string) { + let i = string.length + let a = [] + + while (i--) { + var iC = string[i].charCodeAt() + if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) { + a[i] = '' + iC + ';' + } else { + a[i] = string[i] + } + } + return a.join('') +} + async function init () { let config = await cfgLoader let root = path.resolve(config.root) @@ -47,7 +62,7 @@ async function init () { return res.set('Content-Type', 'text/plain').send(text) } - let etext = text.replace(/&/g,'&').replace(//g,'>') + let etext = encodeSpecial(text) let payload = '' + '' + diff --git a/applications/tempfiles/index.js b/applications/tempfiles/index.js index 6d39ff7..a6716ea 100644 --- a/applications/tempfiles/index.js +++ b/applications/tempfiles/index.js @@ -70,25 +70,6 @@ async function init () { await clearDatabase(config, dbPromise) - // Serve a file or a hash - // Files should be served from an external web server (such as nginx) whenever possible. - router.get('/:hash', async (req, res, next) => { - if (!req.params.hash) return res.status(400).send('Invalid request') - - let db = await dbPromise - let file = await db.get('SELECT * FROM File WHERE path = ?', req.params.hash) - let translation = await db.get('SELECT * FROM Translation WHERE translation = ?', req.params.hash) - if (!file && !translation) return res.status(404).end() - - res.header('Cache-Control', 'max-age=' + 7 * 24 * 60 * 60 * 1000) - - if (translation) { - return res.redirect(config.gateway + '/ipfs/' + translation.file_hash) - } - - res.sendFile(path.join(root, file.path)) - }) - // Upload a file or publish a hash router.post('/publish', async (req, res, next) => { let ip = req.ip @@ -160,13 +141,18 @@ async function init () { res.send(uploadedFiles.join('\n')) }) + router.get('/shorten', async (req, res) => { + res.send('