2023-03-04 02:31:07 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const handler = require('express-async-handler');
|
|
|
|
const content = require('../helpers/content');
|
|
|
|
|
2023-03-04 06:00:53 +01:00
|
|
|
const { MAXFILES } = process.env;
|
|
|
|
|
2023-03-04 02:31:07 +01:00
|
|
|
async function upload(req, res) {
|
2023-03-04 06:00:53 +01:00
|
|
|
|
|
|
|
if (content.submitted() >= MAXFILES) {
|
|
|
|
res.status(405).send('Not allowed');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-04 02:31:07 +01:00
|
|
|
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;
|