aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-01-16 18:03:03 -0500
committerbobzel <zzzman@gmail.com>2025-01-16 18:03:03 -0500
commitfdc8741187489963353938072f05051b8986c400 (patch)
treed74f28a78a9c1cf29509e00ef03f421ea3ce0d1c /src
parentb0903079ab0abbc65e927d70ee0f6bb593865869 (diff)
fixes for stlye refs in firefly generate
Diffstat (limited to 'src')
-rw-r--r--src/client/views/smartdraw/DrawingFillHandler.tsx50
1 files changed, 25 insertions, 25 deletions
diff --git a/src/client/views/smartdraw/DrawingFillHandler.tsx b/src/client/views/smartdraw/DrawingFillHandler.tsx
index 6f2d1cbe6..16ac2b79e 100644
--- a/src/client/views/smartdraw/DrawingFillHandler.tsx
+++ b/src/client/views/smartdraw/DrawingFillHandler.tsx
@@ -1,7 +1,8 @@
import { imageUrlToBase64 } from '../../../ClientUtils';
-import { Doc } from '../../../fields/Doc';
+import { Doc, StrListCast } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
import { DocCast, ImageCast, NumCast } from '../../../fields/Types';
+import { ImageField } from '../../../fields/URLField';
import { Upload } from '../../../server/SharedMediaTypes';
import { gptDescribeImage } from '../../apis/gpt/GPT';
import { Docs } from '../../documents/Documents';
@@ -14,23 +15,19 @@ const DashDropboxId = '2m86iveqdr9vzsa';
export class DrawingFillHandler {
static drawingToImage = async (drawing: Doc, strength: number, user_prompt: string, styleDoc?: Doc) => {
const docData = drawing[DocData];
- const tags: string[] = ((docData?.tags as unknown as string[]) ?? []).map(tag => tag.slice(1)) ?? [];
+ const tags = StrListCast(docData.tags).map(tag => tag.slice(1));
const styles = tags.filter(tag => FireflyStylePresets.has(tag));
- const styleDocs = styleDoc
- ? [styleDoc]
+ const styleDocs = !Doc.Links(drawing).length
+ ? styleDoc && !tags.length
+ ? [styleDoc]
+ : []
: Doc.Links(drawing)
.map(link => Doc.getOppositeAnchor(link, drawing))
.map(anchor => anchor && DocCast(anchor.embedContainer));
- const styleRef = styleDocs.filter(doc => doc !== undefined && doc.type === 'image').lastElement();
- let styleUrl: string | undefined;
- if (styleRef) {
- const styleImg = await DocumentView.GetDocImage(styleRef);
- if (styleImg) {
- const { href } = ImageCast(styleImg).url;
- const hrefParts = href.split('.');
- styleUrl = `${hrefParts.slice(0, -1).join('.')}_o.${hrefParts.lastElement()}`;
- }
- }
+ const styleUrl = await DocumentView.GetDocImage(styleDocs.filter(doc => doc?.data instanceof ImageField).lastElement())?.then(styleImg => {
+ const hrefParts = ImageCast(styleImg).url.href.split('.');
+ return `${hrefParts.slice(0, -1).join('.')}_o.${hrefParts.lastElement()}`;
+ });
DocumentView.GetDocImage(drawing)?.then(imageField => {
if (imageField) {
const aspectRatio = (drawing.width as number) / (drawing.height as number);
@@ -52,17 +49,20 @@ export class DrawingFillHandler {
.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) => {
- const img = 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,
- });
- const genratedDocs = drawing.generatedDocs ? DocCast(drawing.generatedDocs) : Docs.Create.MasonryDocument([], { _width: 400, _height: 400, x: NumCast(drawing.x) + NumCast(drawing.width), y: NumCast(drawing.y) });
- drawing[DocData].generatedDocs = genratedDocs;
- Doc.AddDocToList(genratedDocs, undefined, img);
+ 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,
+ })
+ );
if (!DocumentView.getFirstDocumentView(genratedDocs)) DocumentViewInternal.addDocTabFunc(genratedDocs, OpenWhere.addRight);
})
.catch(e => {