Files
outline/server/commands/collectionExporter.ts
Tom Moor 00fb4d1af7 chore: Update node style imports (#11277)
- 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
2026-01-26 20:51:50 -05:00

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);