aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-04-23 15:29:26 -0400
committerbobzel <zzzman@gmail.com>2025-04-23 15:29:26 -0400
commit0d758430301d934a465ea090abf41f4a596a146c (patch)
tree5104210ee6e3014f2b086da92643f5222b3cf4a2
parent6be2ce925e3a0ba1e88e568ddbc57e3a272e6ff0 (diff)
fixed outpainting to get authorization for dropbox
-rw-r--r--src/client/documents/Documents.ts63
-rw-r--r--src/client/views/nodes/ImageBox.tsx55
-rw-r--r--src/client/views/smartdraw/DrawingFillHandler.tsx6
3 files changed, 49 insertions, 75 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 2a2f9d342..e694419a4 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -526,18 +526,17 @@ export class DocumentOptions {
ai_firefly_seed?: number;
ai_firefly_prompt?: string;
- /**
- * JSON‐stringified slot configuration for ScrapbookBox
- */
- scrapbookConfig?: string;
-
- /**
- * The list of embedded Doc instances in each Scrapbook slot
- */
- scrapbookContents?: List<Doc>;
-
- _outpaintingMetadata?: STRt = new StrInfo('serialized JSON metadata needed for image outpainting', false);
+ /**
+ * JSON‐stringified slot configuration for ScrapbookBox
+ */
+ scrapbookConfig?: string;
+ /**
+ * The list of embedded Doc instances in each Scrapbook slot
+ */
+ scrapbookContents?: List<Doc>;
+
+ _outpaintingMetadata?: STRt = new StrInfo('serialized JSON metadata needed for image outpainting', false);
}
export const DocOptions = new DocumentOptions();
@@ -587,31 +586,6 @@ export namespace Docs {
options: { acl: '' },
},
],
-
- // AARAV ADD //
- [
- DocumentType.JOURNAL,
- {
- layout: { view: EmptyBox, dataField: 'text' },
- options: {
- title: 'Daily Journal',
- acl_Guest: SharingPermissions.View,
- },
- },
- ],
- // AARAV ADD //
-
- [
- DocumentType.SCRAPBOOK,
- {
- layout: { view: EmptyBox, dataField: 'text' },
- options: {
- title: 'Scrapbook',
- acl_Guest: SharingPermissions.View,
- },
-
- },
- ],
]);
const suffix = 'Proto';
@@ -944,18 +918,17 @@ export namespace Docs {
return InstanceFromProto(Prototypes.get(DocumentType.RTF), field, options, undefined, fieldKey);
}
- export function ScrapbookDocument(
- items: Doc[] = [],
- options: DocumentOptions = {},
- fieldKey: string = 'items'
- ) {
+ export function ScrapbookDocument(items: Doc[] = [], options: DocumentOptions = {}, fieldKey: string = 'items') {
return InstanceFromProto(
Prototypes.get(DocumentType.SCRAPBOOK),
new List<Doc>(items),
{
- title: options.title
- ?? new Date().toLocaleDateString(undefined, {
- year: 'numeric', month: 'short', day: 'numeric'
+ title:
+ options.title ??
+ new Date().toLocaleDateString(undefined, {
+ year: 'numeric',
+ month: 'short',
+ day: 'numeric',
}),
...options,
},
@@ -1006,8 +979,6 @@ export namespace Docs {
// AARAV ADD //
-
-
export function LinkDocument(source: Doc, target: Doc, options: DocumentOptions = {}, id?: string) {
const linkDoc = InstanceFromProto(
Prototypes.get(DocumentType.LINK),
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index 1fcabaf21..9c6b8e99c 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -140,7 +140,6 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
};
componentDidMount() {
- super.componentDidMount?.();
this._disposers.sizer = reaction(
() => ({
forceFull: this._props.renderDepth < 1 || this.layoutDoc._showFullRes,
@@ -426,38 +425,40 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
newDimensions: { width: newWidth, height: newHeight },
});
- const batch = UndoManager.StartBatch('outpaint image');
- if (response && typeof response === 'object' && 'url' in response && typeof response.url === 'string') {
- console.log('Received outpainted image:', response.url);
-
- if (!this.dataDoc[this.fieldKey + '_alternates']) {
- this.dataDoc[this.fieldKey + '_alternates'] = new List<Doc>();
- }
+ const error = ('error' in response && (response.error as string)) || '';
+ if (error.includes('Dropbox') && confirm('Outpaint image failed. Try authorizing DropBox?\r\n' + error.replace(/^[^"]*/, ''))) {
+ DrawingFillHandler.authorizeDropbox();
+ } else {
+ const batch = UndoManager.StartBatch('outpaint image');
+ if (response && typeof response === 'object' && 'url' in response && typeof response.url === 'string') {
+ if (!this.dataDoc[this.fieldKey + '_alternates']) {
+ this.dataDoc[this.fieldKey + '_alternates'] = new List<Doc>();
+ }
- const originalDoc = Docs.Create.ImageDocument(field.url.href, {
- title: `Original: ${this.Document.title}`,
- _nativeWidth: Doc.NativeWidth(this.dataDoc),
- _nativeHeight: Doc.NativeHeight(this.dataDoc),
- });
+ const originalDoc = Docs.Create.ImageDocument(field.url.href, {
+ title: `Original: ${this.Document.title}`,
+ _nativeWidth: Doc.NativeWidth(this.dataDoc),
+ _nativeHeight: Doc.NativeHeight(this.dataDoc),
+ });
- Doc.AddDocToList(this.dataDoc, this.fieldKey + '_alternates', originalDoc);
+ Doc.AddDocToList(this.dataDoc, this.fieldKey + '_alternates', originalDoc);
- // Replace with new outpainted image
- this.dataDoc[this.fieldKey] = new ImageField(response.url);
+ // Replace with new outpainted image
+ this.dataDoc[this.fieldKey] = new ImageField(response.url);
- Doc.SetNativeWidth(this.dataDoc, newWidth);
- Doc.SetNativeHeight(this.dataDoc, newHeight);
+ Doc.SetNativeWidth(this.dataDoc, newWidth);
+ Doc.SetNativeHeight(this.dataDoc, newHeight);
- this.Document.$ai = true;
- this.Document.$ai_outpainted = true;
- this.Document.$ai_outpaint_prompt = customPrompt;
- } else {
- console.error('Unexpected API response:', response);
- this.Document._width = origWidth;
- this.Document._height = origHeight;
- alert('Failed to receive a valid image URL from server.');
+ this.Document.$ai = true;
+ this.Document.$ai_outpainted = true;
+ this.Document.$ai_outpaint_prompt = customPrompt;
+ } else {
+ this.Document._width = origWidth;
+ this.Document._height = origHeight;
+ alert('Failed to receive a valid image URL from server.');
+ }
+ batch.end();
}
- batch.end();
this._mainCont?.removeChild(loadingOverlay);
} catch (error) {
diff --git a/src/client/views/smartdraw/DrawingFillHandler.tsx b/src/client/views/smartdraw/DrawingFillHandler.tsx
index b0945fd83..2c69284db 100644
--- a/src/client/views/smartdraw/DrawingFillHandler.tsx
+++ b/src/client/views/smartdraw/DrawingFillHandler.tsx
@@ -12,6 +12,9 @@ import { AspectRatioLimits, FireflyDimensionsMap, FireflyImageDimensions, Firefl
const DashDropboxId = '2m86iveqdr9vzsa';
export class DrawingFillHandler {
+ static authorizeDropbox = () => {
+ window.open(`https://www.dropbox.com/oauth2/authorize?client_id=${DashDropboxId}&response_type=code&token_access_type=offline&redirect_uri=http://localhost:1050/refreshDropbox`, '_blank')?.focus();
+ };
static drawingToImage = async (drawing: Doc, strength: number, user_prompt: string, styleDoc?: Doc) => {
const tags = StrListCast(drawing.$tags).map(tag => tag.slice(1));
const styles = tags.filter(tag => FireflyStylePresets.has(tag));
@@ -46,8 +49,7 @@ export class DrawingFillHandler {
.then(res => {
const error = ('error' in res && (res.error as string)) || '';
if (error.includes('Dropbox') && confirm('Create image failed. Try authorizing DropBox?\r\n' + error.replace(/^[^"]*/, ''))) {
- window.open(`https://www.dropbox.com/oauth2/authorize?client_id=${DashDropboxId}&response_type=code&token_access_type=offline&redirect_uri=http://localhost:1050/refreshDropbox`, '_blank')?.focus();
- return;
+ return DrawingFillHandler.authorizeDropbox();
}
const genratedDocs = DocCast(drawing.ai_firefly_generatedDocs) ?? Docs.Create.MasonryDocument([], { title: StrCast(drawing.title) + ' AI Images', _width: 400, _height: 400 });
drawing.$ai_firefly_generatedDocs = genratedDocs;