Compare commits

..

3 Commits

Author SHA1 Message Date
b1ek 8965c64a83
add upload functionality 2023-03-04 11:31:07 +10:00
b1ek 44d6348400
button styling 2023-03-04 11:16:47 +10:00
b1ek 4abe2382ef
add example, readme 2023-03-04 11:16:34 +10:00
9 changed files with 79 additions and 0 deletions

4
.env.example Normal file
View File

@ -0,0 +1,4 @@
APP_PORT=8080
APP_DEBUG=true
MAXLEN=5120

9
README.md Normal file
View File

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

26
helpers/content/index.js Normal file
View File

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

View File

@ -1,4 +1,8 @@
const express = require('express');
const router = express.Router();
const bodyparse = require('body-parser');
router.use(bodyparse.json());
router.use(bodyparse.urlencoded({extended: true}));
module.exports = router;

View File

@ -10,6 +10,7 @@
"author": "b1ek",
"license": "MIT",
"dependencies": {
"body-parser": "^1.20.2",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"express-async-handler": "^1.2.0",

View File

@ -7,6 +7,7 @@ textarea {
border: 1px solid #6c6f6c;
border-radius: 4px;
box-shadow: 0 2px 2px #20402030;
transition: 150ms ease;
padding: 4px 8px
}
textarea:hover {
@ -16,4 +17,19 @@ textarea:hover {
.data {
width: 400px;
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;
}

View File

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

16
routes/upload.js Normal file
View File

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

2
usercontent/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
./*
!./.gitignore