add viewer
This commit is contained in:
parent
8965c64a83
commit
0b5010977f
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -3,5 +3,6 @@ const router = express.Router();
|
|||
|
||||
router.use(require('./main'));
|
||||
router.use(require('./upload'));
|
||||
router.use(require('./view'));
|
||||
|
||||
module.exports = router;
|
|
@ -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;
|
|
@ -0,0 +1 @@
|
|||
uwu
|
|
@ -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')
|
Loading…
Reference in New Issue