aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts')
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts
index 162b7a1b1..08818dd6c 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/Backend/TemplateMenuAIUtils.ts
@@ -1,13 +1,13 @@
-import { ClientUtils } from "../../../../../../ClientUtils";
-import { Networking } from "../../../../../Network";
-import { gptImageCall, gptAPICall, GPTCallType } from "../../../../../apis/gpt/GPT";
-import { Col } from "../DocCreatorMenu";
-import { TemplateFieldSize, TemplateFieldType } from "../TemplateBackend";
-import { TemplateField, ViewType } from "../TemplateFieldTypes/TemplateField";
-import { Template } from "../Template";
+import { ClientUtils } from '../../../../../../ClientUtils';
+import { Networking } from '../../../../../Network';
+import { gptImageCall, gptAPICall, GPTCallType } from '../../../../../apis/gpt/GPT';
+import { Col } from '../DocCreatorMenu';
+import { TemplateFieldSize, TemplateFieldType } from '../TemplateBackend';
+import { ViewType } from '../TemplateFieldTypes/TemplateField';
+import { Template } from '../Template';
+import { Upload } from '../../../../../../server/SharedMediaTypes';
export class TemplateMenuAIUtils {
-
public static generateGPTImage = async (prompt: string): Promise<string | undefined> => {
try {
const res = await gptImageCall(prompt);
@@ -24,13 +24,10 @@ export class TemplateMenuAIUtils {
public static renderGPTImageCall = async (template: Template, col: Col, fieldNumber: number): Promise<boolean> => {
const generateAndLoadImage = async (id: number, prompt: string) => {
+ const field = template.getFieldByID(id);
const url = await this.generateGPTImage(prompt);
- // eslint-disable-next-line
- var field: TemplateField = template.getFieldByID(id);
-
- field.setContent(url ?? '', ViewType.IMG);
- field = template.getFieldByID(id);
- field.setTitle(col.title);
+ field?.setContent(url ?? '', ViewType.IMG);
+ field?.setTitle(col.title);
};
const fieldContent: string = template.compiledContent;
@@ -81,10 +78,10 @@ export class TemplateMenuAIUtils {
if (res) {
const assignments: { [title: string]: { number: string; content: string } } = JSON.parse(res);
Object.entries(assignments).forEach(([, /* title */ info]) => {
- const field: TemplateField = template.getFieldByID(Number(info.number));
+ const field = template.getFieldByID(Number(info.number));
- field.setContent(info.content ?? '', ViewType.TEXT);
- field.setTitle(col.title);
+ field?.setContent(info.content ?? '', ViewType.TEXT);
+ field?.setTitle(col.title);
});
}
} catch (err) {
@@ -122,5 +119,4 @@ export class TemplateMenuAIUtils {
return template;
};
-
-} \ No newline at end of file
+}