Browse Source

destructure formdada and post to micropub

master
Rich Brown 1 year ago
parent
commit
7b3467bc71
1 changed files with 14 additions and 2 deletions
  1. +14
    -2
      routes/createRouter.js

+ 14
- 2
routes/createRouter.js View File

@@ -8,8 +8,20 @@ const upload = multer({ storage });
const createRouter = express.Router();

createRouter.post('/form', upload.single('file'), (req, res) => {
console.log(req.body, req.file);
res.status(451).json({ error: 'hello.', url: null });
const { file, body: { title, body, arrayOfTags } } = req.body;
return req.app.locals.mp
.create(
{
h: 'entry',
name: title, // i thought MF syntax was 'p-name' but voxpelli's formattr turns NAME to TITLE
content: body,
category: arrayOfTags,
photo: file,
},
'multipart',
)
.then(url => res.json({ error: null, url }))
.catch(() => res.status(400).json({ error: 'micropub-helper failed; multipart', url: null }));
});

createRouter.post('/', (req, res) => {


Loading…
Cancel
Save