This commit is contained in:
Tom Moor
2020-12-17 21:19:31 -08:00
parent 5012104a10
commit b98e4bb1ff
5 changed files with 171 additions and 9 deletions

View File

@ -2,6 +2,7 @@
import Router from "koa-router";
import Sequelize from "sequelize";
import { subtractDate } from "../../shared/utils/date";
import documentBatchImporter from "../commands/documentBatchImporter";
import documentCreator from "../commands/documentCreator";
import documentImporter from "../commands/documentImporter";
import documentMover from "../commands/documentMover";
@ -1105,13 +1106,38 @@ router.post("documents.unpublish", auth(), async (ctx) => {
};
});
router.post("documents.batchImport", auth(), async (ctx) => {
const { type } = ctx.body;
ctx.assertIn(type, ["outline"], "type must be one of 'outline'");
if (!ctx.is("multipart/form-data")) {
throw new InvalidRequestError("Request type must be multipart/form-data");
}
const file: any = Object.values(ctx.request.files)[0];
ctx.assertPresent(file, "file is required");
if (file.type !== "application/zip") {
throw new InvalidRequestError("File type must be a zip");
}
const user = ctx.state.user;
authorize(user, "batchImport", Document);
await documentBatchImporter({
file,
user,
type,
ip: ctx.request.ip,
});
ctx.body = {
success: true,
};
});
router.post("documents.import", auth(), async (ctx) => {
const {
publish,
collectionId,
parentDocumentId,
index,
} = ctx.body;
const { publish, collectionId, parentDocumentId, index } = ctx.body;
if (!ctx.is("multipart/form-data")) {
throw new InvalidRequestError("Request type must be multipart/form-data");