diff options
Diffstat (limited to 'src/server/ApiManagers/FireflyManager.ts')
-rw-r--r-- | src/server/ApiManagers/FireflyManager.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/server/ApiManagers/FireflyManager.ts b/src/server/ApiManagers/FireflyManager.ts index 5e3ba1f83..29aed2c54 100644 --- a/src/server/ApiManagers/FireflyManager.ts +++ b/src/server/ApiManagers/FireflyManager.ts @@ -36,6 +36,61 @@ export default class FireflyManager extends ApiManager { ); return fetched; }; + + askFireflyStructure = (prompt: string = 'a realistic illustration of a cat coding', strength: number, imageReference: ) => { + const fetched = this.getBearerToken().then(response => + response.json().then((data: { access_token: string }) => { + const body = { + prompt: prompt, + structure: { + strength: strength, + imageReference: { + source: { + uploadId: + } + } + } + } + return fetch('https://firefly-api.adobe.io/v3/images/generate', { + method: 'POST', + headers: [ + ['Content-Type', 'application/json'], + ['Accept', 'application/json'], + ['x-api-key', process.env._CLIENT_FIREFLY_CLIENT_ID ?? ''], + ['Authorization', `Bearer ${data.access_token}`], + ], + body: JSON.stringify(body), + }) + .then(response => response.json().then(json => JSON.stringify((json.outputs?.[0] as { image: { url: string } })?.image))) + .catch(error => { + console.error('Error:', error); + return ''; + }) + }) + ); + return fetched; + }; + + uploadImageToFirefly = (image: File | Blob) => { + const fetched = this.getBearerToken().then(response => + response.json().then((data: { access_token: string }) => + fetch('https://firefly-api.adobe.io/v3/uploads', { + method: 'POST', + headers: [ + ['Content-Type', image.type], + ['x-api-key', process.env._CLIENT_FIREFLY_CLIENT_ID ?? ''], + ['Authorization', `Bearer ${data.access_token}`], // You can replace this with a dynamic token if needed + ], + body: image, + }) + .then(response => response.json()) + .then(data => data.uploadId) // Extract the uploadId from the response + .catch(error => { + console.error('Error uploading image:', error); + return ''; + }); + }; + protected initialize(register: Registration): void { register({ method: Method.POST, |