feat: Adds documents.export endpoint to return cleaned up Markdown (#1343)

This commit is contained in:
Tom Moor
2020-07-13 18:23:15 -07:00
committed by GitHub
parent bfea742650
commit b51d818db3
2 changed files with 204 additions and 5 deletions

View File

@ -366,11 +366,7 @@ router.post("documents.drafts", auth(), pagination(), async ctx => {
};
});
router.post("documents.info", auth({ required: false }), async ctx => {
const { id, shareId } = ctx.body;
ctx.assertPresent(id || shareId, "id or shareId is required");
const user = ctx.state.user;
async function loadDocument({ id, shareId, user }) {
let document;
if (shareId) {
@ -404,6 +400,15 @@ router.post("documents.info", auth({ required: false }), async ctx => {
authorize(user, "read", document);
}
return document;
}
router.post("documents.info", auth({ required: false }), async ctx => {
const { id, shareId } = ctx.body;
ctx.assertPresent(id || shareId, "id or shareId is required");
const user = ctx.state.user;
const document = await loadDocument({ id, shareId, user });
const isPublic = cannot(user, "read", document);
ctx.body = {
@ -412,6 +417,18 @@ router.post("documents.info", auth({ required: false }), async ctx => {
};
});
router.post("documents.export", auth({ required: false }), async ctx => {
const { id, shareId } = ctx.body;
ctx.assertPresent(id || shareId, "id or shareId is required");
const user = ctx.state.user;
const document = await loadDocument({ id, shareId, user });
ctx.body = {
data: document.toMarkdown(),
};
});
router.post("documents.restore", auth(), async ctx => {
const { id, revisionId } = ctx.body;
ctx.assertPresent(id, "id is required");