mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
a226889143
* Update task scheduling to use instance method * Delete update_task_schedule.sh * Applied automatic fixes * tsc --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { FileOperationFormat, FileOperationType } from "@shared/types";
|
|
import { FileOperation } from "@server/models";
|
|
import { 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 ImportMarkdownZipTask from "../tasks/ImportMarkdownZipTask";
|
|
import BaseProcessor from "./BaseProcessor";
|
|
|
|
export default class FileOperationCreatedProcessor extends BaseProcessor {
|
|
static applicableEvents: TEvent["name"][] = ["fileOperations.create"];
|
|
|
|
async perform(event: FileOperationEvent) {
|
|
const fileOperation = await FileOperation.findByPk(event.modelId, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
|
|
// map file operation type and format to the appropriate task
|
|
if (fileOperation.type === FileOperationType.Import) {
|
|
switch (fileOperation.format) {
|
|
case FileOperationFormat.MarkdownZip:
|
|
await new ImportMarkdownZipTask().schedule({
|
|
fileOperationId: event.modelId,
|
|
});
|
|
break;
|
|
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:
|
|
}
|
|
}
|
|
}
|
|
}
|