Compare commits
3 Commits
83e72e7ed6
...
8965c64a83
Author | SHA1 | Date |
---|---|---|
b1ek | 8965c64a83 | |
b1ek | 44d6348400 | |
b1ek | 4abe2382ef |
|
@ -0,0 +1,4 @@
|
||||||
|
APP_PORT=8080
|
||||||
|
APP_DEBUG=true
|
||||||
|
|
||||||
|
MAXLEN=5120
|
|
@ -0,0 +1,9 @@
|
||||||
|
# blek! Bin
|
||||||
|
blek! Bin is a minimalist, privacy-respecting alternative to pastebin.
|
||||||
|
|
||||||
|
# Running an instance
|
||||||
|
```bash
|
||||||
|
cp .env.example .env
|
||||||
|
# edit your .env
|
||||||
|
npm run dev/prod
|
||||||
|
```
|
|
@ -0,0 +1,26 @@
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
const root = path.join(process.cwd(), '/usercontent');
|
||||||
|
console.log(root);
|
||||||
|
|
||||||
|
const make_id = () => {
|
||||||
|
return crypto.randomBytes(8).toString('hex');
|
||||||
|
};
|
||||||
|
|
||||||
|
async function get(id) {
|
||||||
|
return fs.readFile(path.join(root, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function write(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);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { get, write, create, make_id };
|
|
@ -1,4 +1,8 @@
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
const bodyparse = require('body-parser');
|
||||||
|
|
||||||
|
router.use(bodyparse.json());
|
||||||
|
router.use(bodyparse.urlencoded({extended: true}));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
|
@ -10,6 +10,7 @@
|
||||||
"author": "b1ek",
|
"author": "b1ek",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"body-parser": "^1.20.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"express-async-handler": "^1.2.0",
|
"express-async-handler": "^1.2.0",
|
||||||
|
|
|
@ -7,6 +7,7 @@ textarea {
|
||||||
border: 1px solid #6c6f6c;
|
border: 1px solid #6c6f6c;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
box-shadow: 0 2px 2px #20402030;
|
box-shadow: 0 2px 2px #20402030;
|
||||||
|
transition: 150ms ease;
|
||||||
padding: 4px 8px
|
padding: 4px 8px
|
||||||
}
|
}
|
||||||
textarea:hover {
|
textarea:hover {
|
||||||
|
@ -16,4 +17,19 @@ textarea:hover {
|
||||||
.data {
|
.data {
|
||||||
width: 400px;
|
width: 400px;
|
||||||
height: 240px
|
height: 240px
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
input[type=submit] {
|
||||||
|
background-color: rgb(236, 221, 200);
|
||||||
|
border: 1px solid #9c9f9c;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-top: 8px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
font-family: monospace;
|
||||||
|
box-shadow: 0 2px 2px #60806020;
|
||||||
|
transition: 150ms ease;
|
||||||
|
}
|
||||||
|
input[type=submit]:hover {
|
||||||
|
box-shadow: 0 2px 4px #60806040;
|
||||||
}
|
}
|
|
@ -2,5 +2,6 @@ const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.use(require('./main'));
|
router.use(require('./main'));
|
||||||
|
router.use(require('./upload'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
|
@ -0,0 +1,16 @@
|
||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
const handler = require('express-async-handler');
|
||||||
|
const content = require('../helpers/content');
|
||||||
|
|
||||||
|
async function upload(req, res) {
|
||||||
|
const data = req.body.text;
|
||||||
|
const id = await content.create(data);
|
||||||
|
res.redirect(
|
||||||
|
'/view?id=' + encodeURIComponent(id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
router.post('/upload', handler(upload));
|
||||||
|
|
||||||
|
module.exports = router;
|
|
@ -0,0 +1,2 @@
|
||||||
|
./*
|
||||||
|
!./.gitignore
|
Loading…
Reference in New Issue