-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathindex.ts
More file actions
57 lines (48 loc) · 2.23 KB
/
Copy pathindex.ts
File metadata and controls
57 lines (48 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { ContextPlugin } from "@webiny/api";
import type { FileManagerContext } from "~/types.js";
import { FileManagerContextSetup } from "./FileManagerContextSetup.js";
import type { AssetDeliveryParams } from "./delivery/setupAssetDelivery.js";
import { setupAssetDelivery } from "./delivery/setupAssetDelivery.js";
import { createGraphQLSchemaPlugin } from "./graphql/index.js";
import { applyThreatScanning } from "./enterprise/applyThreatScanning.js";
import type { FileManagerConfig } from "./createFileManager/types.js";
import { FileManagerFeature } from "~/features/FileManagerFeature.js";
import { createFileTaggingTask } from "./tasks/createFileTaggingTask.js";
export * from "./modelModifier/CmsModelModifier.js";
export * from "./plugins/index.js";
export * from "./delivery/index.js";
export const createFileManagerContext = ({
storageOperations
}: Pick<FileManagerConfig, "storageOperations">) => {
const fmContextPlugin = new ContextPlugin<FileManagerContext>(async context => {
const fmContext = new FileManagerContextSetup(context);
context.fileManager = await fmContext.setupContext(storageOperations);
if (context.wcp.canUseFileManagerThreatDetection()) {
context.fileManager = applyThreatScanning(context.fileManager);
}
FileManagerFeature.register(context.container);
});
fmContextPlugin.name = "file-manager.createContext";
if (process.env.WEBINY_API_AI_IMAGE_TAGGING === "true") {
// Trigger background task
const aiImageTaggingPlugin = new ContextPlugin<FileManagerContext>(context => {
context.fileManager.onFileAfterCreate.subscribe(({ file }) => {
context.tasks.trigger({
definition: "fmAiImageTagging",
input: {
file: file
},
name: "AI Image Tagging Task"
});
});
});
return [fmContextPlugin, createFileTaggingTask(), aiImageTaggingPlugin];
}
return [fmContextPlugin];
};
export const createFileManagerGraphQL = () => {
return createGraphQLSchemaPlugin();
};
export const createAssetDelivery = (config: AssetDeliveryParams) => {
return setupAssetDelivery(config);
};