bin/routes/upload.js

24 lines
562 B
JavaScript

const express = require('express');
const router = express.Router();
const handler = require('express-async-handler');
const content = require('../helpers/content');
const { MAXFILES } = process.env;
async function upload(req, res) {
if (content.submitted() >= MAXFILES) {
res.status(405).send('Not allowed');
return;
}
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;