mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
00fb4d1af7
- crypto → node:crypto - fs → node:fs - fs/promises → node:fs/promises - path → node:path - http → node:http - https → node:https - stream → node:stream - buffer → node:buffer - url → node:url - os → node:os - net → node:net - dns → node:dns - events → node:events - readline → node:readline - querystring → node:querystring - util → node:util
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import {
|
|
FileOperationFormat,
|
|
FileOperationType,
|
|
FileOperationState,
|
|
} from "@shared/types";
|
|
import { traceFunction } from "@server/logging/tracing";
|
|
import type { Collection, Team, User } from "@server/models";
|
|
import { FileOperation } from "@server/models";
|
|
import { Buckets } from "@server/models/helpers/AttachmentHelper";
|
|
import { type APIContext } from "@server/types";
|
|
|
|
type Props = {
|
|
collection?: Collection;
|
|
team: Team;
|
|
user: User;
|
|
format?: FileOperationFormat;
|
|
includeAttachments?: boolean;
|
|
includePrivate?: boolean;
|
|
ctx: APIContext;
|
|
};
|
|
|
|
function getKeyForFileOp(
|
|
teamId: string,
|
|
format: FileOperationFormat,
|
|
name: string
|
|
) {
|
|
return `${
|
|
Buckets.uploads
|
|
}/${teamId}/${randomUUID()}/${name}-export.${format.replace(/outline-/, "")}.zip`;
|
|
}
|
|
|
|
async function collectionExporter({
|
|
collection,
|
|
team,
|
|
user,
|
|
format = FileOperationFormat.MarkdownZip,
|
|
includeAttachments = true,
|
|
includePrivate = true,
|
|
ctx,
|
|
}: Props) {
|
|
const collectionId = collection?.id;
|
|
const key = getKeyForFileOp(
|
|
user.teamId,
|
|
format,
|
|
collection?.name || team.name
|
|
);
|
|
const fileOperation = await FileOperation.createWithCtx(ctx, {
|
|
type: FileOperationType.Export,
|
|
state: FileOperationState.Creating,
|
|
format,
|
|
key,
|
|
url: null,
|
|
size: 0,
|
|
collectionId,
|
|
options: {
|
|
includeAttachments,
|
|
includePrivate,
|
|
},
|
|
userId: user.id,
|
|
teamId: user.teamId,
|
|
});
|
|
|
|
fileOperation.user = user;
|
|
|
|
if (collection) {
|
|
fileOperation.collection = collection;
|
|
}
|
|
|
|
return fileOperation;
|
|
}
|
|
|
|
export default traceFunction({
|
|
spanName: "collectionExporter",
|
|
})(collectionExporter);
|