feat: Adds documents.export endpoint to return cleaned up Markdown (#1343)
This commit is contained in:
@ -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");
|
||||
|
Reference in New Issue
Block a user