aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/FireflyManager.ts
diff options
context:
space:
mode:
authoreleanor-park <eleanor_park@brown.edu>2025-01-14 17:19:16 +0100
committereleanor-park <eleanor_park@brown.edu>2025-01-14 17:19:16 +0100
commit859bb1b733901e4697f1d53781af725e4830c607 (patch)
treeffafb078019d861f71232348176c02a7557a8965 /src/server/ApiManagers/FireflyManager.ts
parentfd922d7898ed7a405ed47a7e48b85c582d787c07 (diff)
added drawing fill style reference
Diffstat (limited to 'src/server/ApiManagers/FireflyManager.ts')
-rw-r--r--src/server/ApiManagers/FireflyManager.ts35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/server/ApiManagers/FireflyManager.ts b/src/server/ApiManagers/FireflyManager.ts
index 185752404..d92db1522 100644
--- a/src/server/ApiManagers/FireflyManager.ts
+++ b/src/server/ApiManagers/FireflyManager.ts
@@ -20,11 +20,11 @@ export default class FireflyManager extends ApiManager {
return undefined;
});
- generateImageFromStructure = (prompt: string = 'a realistic illustration of a cat coding', width: number = 2048, height: number = 2048, structureUrl: string, strength: number = 50, styles: string[], styleUrl: string) =>
+ generateImageFromStructure = (prompt: string = 'a realistic illustration of a cat coding', width: number = 2048, height: number = 2048, structureUrl: string, strength: number = 50, styles: string[], styleUrl: string | undefined) =>
this.getBearerToken().then(response =>
- response?.json().then((data: { access_token: string }) =>
+ response?.json().then((data: { access_token: string }) => {
//prettier-ignore
- fetch('https://firefly-api.adobe.io/v3/images/generate', {
+ return fetch('https://firefly-api.adobe.io/v3/images/generate', {
method: 'POST',
headers: [
['Content-Type', 'application/json'],
@@ -43,12 +43,14 @@ export default class FireflyManager extends ApiManager {
source: { url: structureUrl },
},
},
- //prettier-ignore
- style: {
- imageReference: {
- source: { uploadId: styleUrl }
- },
- presets: styles
+ // prettier-ignore
+ style: {
+ presets: styles,
+ ...(styleUrl && {
+ imageReference: {
+ source: { uploadId: styleUrl },
+ },
+ }),
}
}),
})
@@ -57,7 +59,7 @@ export default class FireflyManager extends ApiManager {
console.error('Error:', error);
return '';
})
- )
+ })
);
uploadImageToDropbox = (fileUrl: string, dbx = new Dropbox({ accessToken: process.env.DROPBOX_TOKEN })) =>
@@ -239,8 +241,8 @@ export default class FireflyManager extends ApiManager {
register({
method: Method.POST,
subscription: '/queryFireflyImageFromStructure',
- secureHandler: async ({ req, res }) =>
- this.uploadImageToDropbox(req.body.styleRef)
+ secureHandler: async ({ req, res }) => {
+ (req.body.styleRef ? this.uploadImageToDropbox(req.body.styleRef) : Promise.resolve(undefined))
.then(styleUrl => {
if (styleUrl instanceof Error) {
_invalid(res, styleUrl.message);
@@ -255,13 +257,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 =>
+ this.generateImageFromStructure(req.body.prompt, req.body.width, req.body.height, uploads.structureUrl, req.body.strength, req.body.presets, req.body.styleUrl).then(fire => {
DashUploadUtils.UploadImage(JSON.parse(fire ?? '').url).then(info => {
if (info instanceof Error) _invalid(res, info.message);
else _success(res, info);
- })
- )
- ),
+ });
+ })
+ );
+ },
});
register({
method: Method.POST,