aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/DocumentView.tsx4
-rw-r--r--src/client/views/smartdraw/DrawingFillHandler.tsx28
-rw-r--r--src/server/ApiManagers/FireflyManager.ts22
3 files changed, 29 insertions, 25 deletions
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index e37658ca5..bc3f27124 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -1110,10 +1110,10 @@ export class DocumentView extends DocComponent<DocumentViewProps>() {
* @param doc Doc to snapshot
* @returns promise of icon ImageField
*/
- public static GetDocImage(doc: Doc) {
+ public static GetDocImage(doc?: Doc) {
return DocumentView.getDocumentView(doc)
?.ComponentView?.updateIcon?.()
- .then(() => ImageCast(doc?.icon, ImageCast(doc[Doc.LayoutFieldKey(doc)])));
+ .then(() => ImageCast(doc!.icon, ImageCast(doc![Doc.LayoutFieldKey(doc!)])));
}
public get displayName() { return 'DocumentView(' + (this.Document?.title??"") + ')'; } // prettier-ignore
diff --git a/src/client/views/smartdraw/DrawingFillHandler.tsx b/src/client/views/smartdraw/DrawingFillHandler.tsx
index 16ac2b79e..d0a840883 100644
--- a/src/client/views/smartdraw/DrawingFillHandler.tsx
+++ b/src/client/views/smartdraw/DrawingFillHandler.tsx
@@ -1,7 +1,7 @@
import { imageUrlToBase64 } from '../../../ClientUtils';
import { Doc, StrListCast } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
-import { DocCast, ImageCast, NumCast } from '../../../fields/Types';
+import { DocCast, ImageCast } from '../../../fields/Types';
import { ImageField } from '../../../fields/URLField';
import { Upload } from '../../../server/SharedMediaTypes';
import { gptDescribeImage } from '../../apis/gpt/GPT';
@@ -48,20 +48,22 @@ export class DrawingFillHandler {
.then(gptDescribeImage)
.then((prompt, newPrompt = user_prompt || prompt) =>
Networking.PostToServer('/queryFireflyImageFromStructure', { prompt: `${newPrompt}`, width: dims.width, height: dims.height, structure: structureUrl, strength, presets: styles, styleUrl })
- .then((info: Upload.ImageInformation) => {
+ .then((infos: Upload.ImageInformation[]) => {
const genratedDocs = DocCast(drawing.ai_firefly_generatedDocs) ?? Docs.Create.MasonryDocument([], { _width: 400, _height: 400 });
drawing[DocData].ai_firefly_generatedDocs = genratedDocs;
- Doc.AddDocToList(
- genratedDocs,
- undefined,
- Docs.Create.ImageDocument(info.accessPaths.agnostic.client, {
- ai: 'firefly',
- title: newPrompt,
- ai_firefly_prompt: newPrompt,
- _width: 500,
- data_nativeWidth: info.nativeWidth,
- data_nativeHeight: info.nativeHeight,
- })
+ infos.map(info =>
+ Doc.AddDocToList(
+ genratedDocs,
+ undefined,
+ Docs.Create.ImageDocument(info.accessPaths.agnostic.client, {
+ ai: 'firefly',
+ title: newPrompt,
+ ai_firefly_prompt: newPrompt,
+ _width: 500,
+ data_nativeWidth: info.nativeWidth,
+ data_nativeHeight: info.nativeHeight,
+ })
+ )
);
if (!DocumentView.getFirstDocumentView(genratedDocs)) DocumentViewInternal.addDocTabFunc(genratedDocs, OpenWhere.addRight);
})
diff --git a/src/server/ApiManagers/FireflyManager.ts b/src/server/ApiManagers/FireflyManager.ts
index f49cf4132..160a94d40 100644
--- a/src/server/ApiManagers/FireflyManager.ts
+++ b/src/server/ApiManagers/FireflyManager.ts
@@ -36,8 +36,9 @@ export default class FireflyManager extends ApiManager {
],
body: JSON.stringify({
prompt,
- // detailLevel: 'preview',
- // modelVersion: 'image3_fast',
+ numVariations: 4,
+ detailLevel: 'preview',
+ modelVersion: 'image3_fast',
size: { width, height },
structure: !structureUrl
? undefined
@@ -61,7 +62,7 @@ export default class FireflyManager extends ApiManager {
.then(response2 => response2.json().then(json =>
{
if (json.outputs?.length)
- return JSON.stringify((json.outputs?.[0] as { image: { url: string } } ?? {})?.image);
+ return (json.outputs as {image: {url:string }}[]).map(output => output.image);
throw new Error(JSON.stringify(json));
})
)
@@ -306,13 +307,14 @@ export default class FireflyManager extends ApiManager {
})
.then(uploads =>
this.generateImageFromStructure(req.body.prompt, req.body.width, req.body.height, uploads.structureUrl, req.body.strength, req.body.presets, uploads.styleUrl)
- .then(fire =>
- DashUploadUtils.UploadImage(JSON.parse(fire ?? '').url).then(info => {
- if (info instanceof Error) _invalid(res, info.message);
- else _success(res, info);
- resolver();
- })
- )
+ .then(images => {
+ Promise.all((images ?? [new Error('no images were generated')]).map(fire => (fire instanceof Error ? fire : DashUploadUtils.UploadImage(fire.url))))
+ .then(dashImages => {
+ if (dashImages.every(img => img instanceof Error)) _invalid(res, dashImages[0]!.message);
+ else _success(res, JSON.stringify(dashImages.filter(img => !(img instanceof Error))));
+ })
+ .then(resolver);
+ })
.catch(e => {
_invalid(res, e.message);
resolver();