Browse Source

add multipart/article-handler to /create

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

+ 20
- 7
routes/createRouter.js View File

@@ -3,22 +3,35 @@ import express from 'express';
const createRouter = express.Router();

createRouter.post('/', (req, res) => {
const { text } = req.body;
let { category, h } = req.body;
const { text, title } = req.body;
let { tags, h } = req.body;
// TODO: expand to handle optional titles and arrayOfTags (see react-micropub-clinet)
if (!text || text === '' || typeof text !== 'string') {
return res.status(400).json({ error: 'Invalid or missing text.', url: null });
}
if (!category) {
category = 'micro.blog';
}
if (!h) {
h = 'entry';
}
if (!tags) {
tags = ['micro.blog'];
}
if (title === '' && h === 'entry') {
return req.app.locals.mp
.create({ h, content: text, category: tags }, 'form') // TODO: test categories/tags
.then(url => res.json({ error: null, url }))
.catch(() => res.status(400).json({ error: 'micropub-helper failed; form', url: null }));
}
console.log("hey! we're ready to post a 'multipart'");
return req.app.locals.mp
.create({ h, content: text, category }, 'form')
.create({
h,
'p-name': title,
content: text,
category: tags,
},
'multipart')
.then(url => res.json({ error: null, url }))
.catch(() => res.status(400).json({ error: 'micropub-helper failed', url: null }));
.catch(() => res.status(400).json({ error: 'micropub-helper failed; multipart', url: null }));
});

export default createRouter;

Loading…
Cancel
Save