Skip to content

Commit a7cb55a

Browse files
committed
fix: update PluginOptions interface to make fillFieldsFromImages and generateImages optional
1 parent 5fda99a commit a7cb55a

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

index.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Handlebars from 'handlebars';
77

88
export default class BulkAiFlowPlugin extends AdminForthPlugin {
99
options: PluginOptions;
10+
uploadPlugin: AdminForthPlugin;
1011

1112
constructor(options: PluginOptions) {
1213
super(options, import.meta.url);
@@ -48,8 +49,37 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
4849
}
4950
}
5051

52+
53+
// if (this.options.generateImages) {
54+
// const resource = adminforth.config.resources.find(r => r.resourceId === this.options.generateImages!.attachmentResource);
55+
// if (!resource) {
56+
// throw new Error(`Resource '${this.options.generateImages!.attachmentResource}' not found`);
57+
// }
58+
// this.attachmentResource = resource;
59+
// const field = resource.columns.find(c => c.name === this.options.generateImages!.attachmentFieldName);
60+
// if (!field) {
61+
// throw new Error(`Field '${this.options.generateImages!.attachmentFieldName}' not found in resource '${this.options.generateImages!.attachmentResource}'`);
62+
// }
63+
// const plugin = adminforth.activatedPlugins.find(p =>
64+
// p.resourceConfig!.resourceId === this.options.attachments!.attachmentResource &&
65+
// p.pluginOptions.pathColumnName === this.options.attachments!.attachmentFieldName
66+
// );
67+
// if (!plugin) {
68+
// throw new Error(`Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' not found in resource '${this.options.attachments!.attachmentResource}', please check if Upload Plugin is installed on the field ${this.options.attachments!.attachmentFieldName}`);
69+
// }
70+
71+
// if (!plugin.pluginOptions.storageAdapter.objectCanBeAccesedPublicly()) {
72+
// throw new Error(`Upload Plugin for attachment field '${this.options.attachments!.attachmentFieldName}' in resource '${this.options.attachments!.attachmentResource}'
73+
// uses adapter which is not configured to store objects in public way, so it will produce only signed private URLs which can not be used in HTML text of blog posts.
74+
// Please configure adapter in such way that it will store objects publicly (e.g. for S3 use 'public-read' ACL).
75+
// `);
76+
// }
77+
// this.uploadPlugin = plugin;
78+
// }
79+
80+
5181
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
52-
console.log('Primary Key Column:', primaryKeyColumn);
82+
//console.log('Primary Key Column:', primaryKeyColumn);
5383

5484
const pageInjection = {
5585
file: this.componentPath('visionAction.vue'),
@@ -90,7 +120,8 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
90120
const selectedIds = body.selectedIds || [];
91121
const tasks = selectedIds.map(async (ID) => {
92122
// Fetch the record using the provided ID
93-
const record = await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ('id', ID)] );
123+
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
124+
const record = await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ(primaryKeyColumn.name, ID)] );
94125

95126
//recieve image URLs to analyze
96127
const attachmentFiles = await this.options.attachFiles({ record: record });
@@ -131,8 +162,9 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
131162
path: `/plugin/${this.pluginInstanceId}/get_records`,
132163
handler: async ( body ) => {
133164
let records = [];
165+
const primaryKeyColumn = this.resourceConfig.columns.find((col) => col.primaryKey);
134166
for( const record of body.body.record ) {
135-
records.push(await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ('id', record)] ));
167+
records.push(await this.adminforth.resource(this.resourceConfig.resourceId).get( [Filters.EQ(primaryKeyColumn.name, record)] ));
136168
records[records.length - 1]._label = this.resourceConfig.recordLabel(records[records.length - 1]);
137169
}
138170
return {

types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { ImageVisionAdapter, AdminUser, IAdminForth, StorageAdapter } from "admi
44
export interface PluginOptions {
55
actionName: string,
66
visionAdapter: ImageVisionAdapter,
7-
fillFieldsFromImages: Record<string, string>,
7+
fillFieldsFromImages?: Record<string, string>, // can analyze what is on image and fill fields, typical tasks "find dominant color", "describe what is on image", "clasify to one enum item, e.g. what is on image dog/cat/plant"
8+
generateImages?: Record<string, string>, // can generate from images or just from another fields, e.g. "remove text from images", "improve image quality", "turn image into ghibli style"
89
attachFiles?: ({ record }: {
910
record: any,
1011
}) => string[] | Promise<string[]>,

0 commit comments

Comments
 (0)