feat: Bulk HTML export (#4620)

* wip

* Working bulk html export

* Refactor

* test

* test
This commit is contained in:
Tom Moor
2022-12-30 17:42:20 +00:00
committed by GitHub
parent 1b8dd9399c
commit f3469d25fe
32 changed files with 485 additions and 258 deletions

View File

@@ -1,7 +1,7 @@
import { Transaction } from "sequelize";
import { v4 as uuidv4 } from "uuid";
import { Attachment, Event, User } from "@server/models";
import { uploadToS3FromBuffer } from "@server/utils/s3";
import { uploadToS3 } from "@server/utils/s3";
export default async function attachmentCreator({
id,
@@ -24,7 +24,13 @@ export default async function attachmentCreator({
}) {
const key = `uploads/${user.id}/${uuidv4()}/${name}`;
const acl = process.env.AWS_S3_ACL || "private";
const url = await uploadToS3FromBuffer(buffer, type, key, acl);
const url = await uploadToS3({
body: buffer,
contentType: type,
contentLength: buffer.length,
key,
acl,
});
const attachment = await Attachment.create(
{
id,

View File

@@ -1,33 +1,37 @@
import { Transaction } from "sequelize";
import { APM } from "@server/logging/tracing";
import { Collection, Event, Team, User, FileOperation } from "@server/models";
import {
FileOperationFormat,
FileOperationType,
FileOperationState,
FileOperationFormat,
} from "@server/models/FileOperation";
} from "@shared/types";
import { APM } from "@server/logging/tracing";
import { Collection, Event, Team, User, FileOperation } from "@server/models";
import { getAWSKeyForFileOp } from "@server/utils/s3";
type Props = {
collection?: Collection;
team: Team;
user: User;
format?: FileOperationFormat;
ip: string;
transaction: Transaction;
};
async function collectionExporter({
collection,
team,
user,
format = FileOperationFormat.MarkdownZip,
ip,
transaction,
}: {
collection?: Collection;
team: Team;
user: User;
ip: string;
transaction: Transaction;
}) {
}: Props) {
const collectionId = collection?.id;
const key = getAWSKeyForFileOp(user.teamId, collection?.name || team.name);
const fileOperation = await FileOperation.create(
{
type: FileOperationType.Export,
state: FileOperationState.Creating,
format: FileOperationFormat.MarkdownZip,
format,
key,
url: null,
size: 0,
@@ -49,7 +53,8 @@ async function collectionExporter({
collectionId,
ip,
data: {
type: FileOperationType.Import,
type: FileOperationType.Export,
format,
},
},
{