aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/FireflyManager.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-11-22 15:00:07 -0500
committerbobzel <zzzman@gmail.com>2024-11-22 15:00:07 -0500
commit2fee49a7cd342331633bf39d1ac837838d252a18 (patch)
treee48a95d82dc98a41118513e4e799c558bd5e4fc4 /src/server/ApiManagers/FireflyManager.ts
parentad90e036b5ba32cb17314d9629a5738d87717ff0 (diff)
switched to providing secret instead of bearer token for adobe api access
Diffstat (limited to 'src/server/ApiManagers/FireflyManager.ts')
-rw-r--r--src/server/ApiManagers/FireflyManager.ts34
1 files changed, 19 insertions, 15 deletions
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 {