mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
* chore: Refactor Markdown importer to use new import pipeline --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { FileOperationFormat, FileOperationType } from "@shared/types";
|
|
import { FileOperation } from "@server/models";
|
|
import type { Event as TEvent, FileOperationEvent } from "@server/types";
|
|
import ExportHTMLZipTask from "../tasks/ExportHTMLZipTask";
|
|
import ExportJSONTask from "../tasks/ExportJSONTask";
|
|
import ExportMarkdownZipTask from "../tasks/ExportMarkdownZipTask";
|
|
import ImportJSONTask from "../tasks/ImportJSONTask";
|
|
import BaseProcessor from "./BaseProcessor";
|
|
|
|
export default class FileOperationCreatedProcessor extends BaseProcessor {
|
|
static applicableEvents: TEvent["name"][] = ["fileOperations.create"];
|
|
|
|
async perform(event: FileOperationEvent) {
|
|
const fileOperation = await FileOperation.unscoped().findByPk(
|
|
event.modelId,
|
|
{
|
|
rejectOnEmpty: true,
|
|
}
|
|
);
|
|
|
|
// map file operation type and format to the appropriate task. Markdown
|
|
// zip imports flow through the API-import pipeline (`imports.create` →
|
|
// MarkdownAPIImportTask) and never reach this dispatcher.
|
|
if (fileOperation.type === FileOperationType.Import) {
|
|
switch (fileOperation.format) {
|
|
case FileOperationFormat.JSON:
|
|
await new ImportJSONTask().schedule({
|
|
fileOperationId: event.modelId,
|
|
});
|
|
break;
|
|
default:
|
|
}
|
|
}
|
|
|
|
if (fileOperation.type === FileOperationType.Export) {
|
|
switch (fileOperation.format) {
|
|
case FileOperationFormat.HTMLZip:
|
|
await new ExportHTMLZipTask().schedule({
|
|
fileOperationId: event.modelId,
|
|
});
|
|
break;
|
|
case FileOperationFormat.MarkdownZip:
|
|
await new ExportMarkdownZipTask().schedule({
|
|
fileOperationId: event.modelId,
|
|
});
|
|
break;
|
|
case FileOperationFormat.JSON:
|
|
await new ExportJSONTask().schedule({
|
|
fileOperationId: event.modelId,
|
|
});
|
|
break;
|
|
default:
|
|
}
|
|
}
|
|
}
|
|
}
|