diff --git a/helpers/content/index.js b/helpers/content/index.js index 02f1fff..1a60846 100644 --- a/helpers/content/index.js +++ b/helpers/content/index.js @@ -10,16 +10,16 @@ const make_id = () => { }; async function get(id) { - return fs.readFile(path.join(root, id)); + return fs.readFileSync(path.join(root, id)).toString(); } async function write(fname, data) { - return fs.writeFile(path.join(root, fname), data); + return fs.writeFile(path.join(root, fname), data, () => {}); } async function create(data) { const id = make_id(); - await fs.writeFile(path.join(root, id), data); + await write(id, data); return id; } diff --git a/public/static/main.css b/public/static/main.css index 4e0d271..6efc125 100644 --- a/public/static/main.css +++ b/public/static/main.css @@ -13,6 +13,12 @@ textarea { textarea:hover { box-shadow: 0 2px 4px #20402040; } +textarea:disabled { + color: black; +} +textarea:disabled:hover { + color: rgb(61, 61, 61) +} .data { width: 400px; diff --git a/routes/index.js b/routes/index.js index 7720a2d..cd5f10a 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,5 +3,6 @@ const router = express.Router(); router.use(require('./main')); router.use(require('./upload')); +router.use(require('./view')); module.exports = router; \ No newline at end of file diff --git a/routes/view.js b/routes/view.js new file mode 100644 index 0000000..d605781 --- /dev/null +++ b/routes/view.js @@ -0,0 +1,17 @@ +const express = require('express'); +const router = express.Router(); +const handler = require('express-async-handler'); +const content = require('../helpers/content'); + +async function view(req, res) { + const data = await content.get(req.query.id); + if (req.query.raw) { + res.send(data); + return; + } + res.render('view', {data, id: req.query.id}); +} + +router.get('/view', handler(view)); + +module.exports = router; \ No newline at end of file diff --git a/usercontent/59682bb1b59f86d9 b/usercontent/59682bb1b59f86d9 new file mode 100644 index 0000000..ea844c1 --- /dev/null +++ b/usercontent/59682bb1b59f86d9 @@ -0,0 +1 @@ +uwu \ No newline at end of file diff --git a/views/view.pug b/views/view.pug new file mode 100644 index 0000000..53ed2e5 --- /dev/null +++ b/views/view.pug @@ -0,0 +1,8 @@ +extends template/main.pug + +block content + p(align='center') + textarea(class='data' disabled)=data + br + a(href='/view?id=' + id + '&raw=true ') + input(type='submit' value='Raw text') \ No newline at end of file