add viewer

This commit is contained in:
b1ek 2023-03-04 11:39:59 +10:00
parent 8965c64a83
commit 0b5010977f
Signed by: blek
GPG Key ID: 14546221E3595D0C
6 changed files with 36 additions and 3 deletions

View File

@ -10,16 +10,16 @@ const make_id = () => {
}; };
async function get(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) { 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) { async function create(data) {
const id = make_id(); const id = make_id();
await fs.writeFile(path.join(root, id), data); await write(id, data);
return id; return id;
} }

View File

@ -13,6 +13,12 @@ textarea {
textarea:hover { textarea:hover {
box-shadow: 0 2px 4px #20402040; box-shadow: 0 2px 4px #20402040;
} }
textarea:disabled {
color: black;
}
textarea:disabled:hover {
color: rgb(61, 61, 61)
}
.data { .data {
width: 400px; width: 400px;

View File

@ -3,5 +3,6 @@ const router = express.Router();
router.use(require('./main')); router.use(require('./main'));
router.use(require('./upload')); router.use(require('./upload'));
router.use(require('./view'));
module.exports = router; module.exports = router;

17
routes/view.js Normal file
View File

@ -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;

View File

@ -0,0 +1 @@
uwu

8
views/view.pug Normal file
View File

@ -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')