Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/api-file-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@webiny/api": "0.0.0",
"@webiny/api-core": "0.0.0",
"@webiny/api-headless-cms": "0.0.0",
"@webiny/api-websockets": "0.0.0",
"@webiny/aws-sdk": "0.0.0",
"@webiny/build-tools": "0.0.0",
"@webiny/error": "0.0.0",
Expand Down
28 changes: 24 additions & 4 deletions packages/api-file-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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";
Expand All @@ -15,7 +16,7 @@ export * from "./delivery/index.js";
export const createFileManagerContext = ({
storageOperations
}: Pick<FileManagerConfig, "storageOperations">) => {
const plugin = new ContextPlugin<FileManagerContext>(async context => {
const fmContextPlugin = new ContextPlugin<FileManagerContext>(async context => {
const fmContext = new FileManagerContextSetup(context);
context.fileManager = await fmContext.setupContext(storageOperations);

Expand All @@ -26,9 +27,28 @@ export const createFileManagerContext = ({
FileManagerFeature.register(context.container);
});

plugin.name = "file-manager.createContext";

return plugin;
fmContextPlugin.name = "file-manager.createContext";

return [
// Main context plugin
fmContextPlugin,

// Background task
createFileTaggingTask(),

// Trigger background task
new ContextPlugin<FileManagerContext>(context => {
context.fileManager.onFileAfterCreate.subscribe(({ file }) => {
context.tasks.trigger({
definition: "fmAiImageTagging",
input: {
file: file
},
name: "AI Image Tagging Task"
});
});
})
];
};

export const createFileManagerGraphQL = () => {
Expand Down
28 changes: 28 additions & 0 deletions packages/api-file-manager/src/tasks/createFileTaggingTask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createTaskDefinition } from "@webiny/tasks";
import type { FileManagerContext } from "~/types.js";
import { Context as WebsocketsContext } from "@webiny/api-websockets";

export const createFileTaggingTask = () => {
return createTaskDefinition<FileManagerContext & WebsocketsContext>({
id: "fmAiImageTagging",
title: "File Upload Background task",
isPrivate: true,
async run(params) {
const { input, response, context } = params;

// TODO: Get tag information from AI

// TODO: Update File Tags
await context.fileManager.updateFile(input.fileId, {
// tags: ["tag1", "tag2", "tag3"]
});

// TODO: send message to WebSocket

return response.done(
"successfully ran the fmAiImageTagging background task",
input.fileId
);
}
});
};
3 changes: 3 additions & 0 deletions packages/api-file-manager/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{ "path": "../api/tsconfig.build.json" },
{ "path": "../api-core/tsconfig.build.json" },
{ "path": "../api-headless-cms/tsconfig.build.json" },
{ "path": "../api-websockets/tsconfig.build.json" },
{ "path": "../aws-sdk/tsconfig.build.json" },
{ "path": "../error/tsconfig.build.json" },
{ "path": "../feature/tsconfig.build.json" },
Expand Down Expand Up @@ -154,6 +155,8 @@
"@webiny/api-core": ["../api-core/src"],
"@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"],
"@webiny/api-headless-cms": ["../api-headless-cms/src"],
"@webiny/api-websockets/*": ["../api-websockets/src/*"],
"@webiny/api-websockets": ["../api-websockets/src"],
"@webiny/aws-sdk/*": ["../aws-sdk/src/*"],
"@webiny/aws-sdk": ["../aws-sdk/src"],
"@webiny/error/*": ["../error/src/*"],
Expand Down
3 changes: 3 additions & 0 deletions packages/api-file-manager/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{ "path": "../api" },
{ "path": "../api-core" },
{ "path": "../api-headless-cms" },
{ "path": "../api-websockets" },
{ "path": "../aws-sdk" },
{ "path": "../error" },
{ "path": "../feature" },
Expand Down Expand Up @@ -154,6 +155,8 @@
"@webiny/api-core": ["../api-core/src"],
"@webiny/api-headless-cms/*": ["../api-headless-cms/src/*"],
"@webiny/api-headless-cms": ["../api-headless-cms/src"],
"@webiny/api-websockets/*": ["../api-websockets/src/*"],
"@webiny/api-websockets": ["../api-websockets/src"],
"@webiny/aws-sdk/*": ["../aws-sdk/src/*"],
"@webiny/aws-sdk": ["../aws-sdk/src"],
"@webiny/error/*": ["../error/src/*"],
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14109,6 +14109,7 @@ __metadata:
"@webiny/api": "npm:0.0.0"
"@webiny/api-core": "npm:0.0.0"
"@webiny/api-headless-cms": "npm:0.0.0"
"@webiny/api-websockets": "npm:0.0.0"
"@webiny/aws-sdk": "npm:0.0.0"
"@webiny/build-tools": "npm:0.0.0"
"@webiny/error": "npm:0.0.0"
Expand Down
Loading