From 2fee49a7cd342331633bf39d1ac837838d252a18 Mon Sep 17 00:00:00 2001 From: bobzel Date: Fri, 22 Nov 2024 15:00:07 -0500 Subject: switched to providing secret instead of bearer token for adobe api access --- src/server/ApiManagers/FireflyManager.ts | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/server/ApiManagers/FireflyManager.ts b/src/server/ApiManagers/FireflyManager.ts index a110d112f..5e3ba1f83 100644 --- a/src/server/ApiManagers/FireflyManager.ts +++ b/src/server/ApiManagers/FireflyManager.ts @@ -15,21 +15,25 @@ export default class FireflyManager extends ApiManager { return ''; }); askFirefly = (prompt: string = 'a realistic illustration of a cat coding') => { - const fetched = 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 ${process.env._CLIENT_FIREFLY_BEARER_TOKEN}`], - ], - body: `{ "prompt": "${prompt}" }`, - }) - .then(response => response.json().then(json => JSON.stringify((json.outputs?.[0] as { image: { url: string } })?.image))) - .catch(error => { - console.error('Error:', error); - return ''; - }); + const fetched = this.getBearerToken().then(response => + response.json().then((data: { access_token: string }) => + 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: `{ "prompt": "${prompt}" }`, + }) + .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; }; protected initialize(register: Registration): void { -- cgit v1.2.3-70-g09d2