aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers')
-rw-r--r--src/server/ApiManagers/FireflyManager.ts18
-rw-r--r--src/server/ApiManagers/GeneralGoogleManager.ts135
-rw-r--r--src/server/ApiManagers/UploadManager.ts2
3 files changed, 148 insertions, 7 deletions
diff --git a/src/server/ApiManagers/FireflyManager.ts b/src/server/ApiManagers/FireflyManager.ts
index e934e635b..6393a1f74 100644
--- a/src/server/ApiManagers/FireflyManager.ts
+++ b/src/server/ApiManagers/FireflyManager.ts
@@ -23,7 +23,16 @@ 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 | 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 | undefined,
+ variations: number = 4
+ ) =>
this.getBearerToken().then(response =>
response?.json().then((data: { access_token: string }) =>
//prettier-ignore
@@ -37,7 +46,7 @@ export default class FireflyManager extends ApiManager {
],
body: JSON.stringify({
prompt,
- numVariations: 4,
+ numVariations: variations,
detailLevel: 'preview',
modelVersion: 'image3_fast',
size: { width, height },
@@ -107,10 +116,7 @@ export default class FireflyManager extends ApiManager {
});
generateImage = (prompt: string = 'a realistic illustration of a cat coding', width: number = 2048, height: number = 2048, seed?: number) => {
- let body = `{ "prompt": "${prompt}", "size": { "width": ${width}, "height": ${height}} }`;
- if (seed) {
- body = `{ "prompt": "${prompt}", "size": { "width": ${width}, "height": ${height}}, "seeds": [${seed}]}`;
- }
+ const body = `{ "prompt": "${prompt}", "size": { "width": ${width}, "height": ${height}} ${seed ? ', "seeds": [' + seed + ']' : ''}}`;
const fetched = this.getBearerToken().then(response =>
response?.json().then((data: { access_token: string }) =>
fetch('https://firefly-api.adobe.io/v3/images/generate', {
diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts
index 12913b1ef..110701418 100644
--- a/src/server/ApiManagers/GeneralGoogleManager.ts
+++ b/src/server/ApiManagers/GeneralGoogleManager.ts
@@ -3,6 +3,7 @@ import { Method } from '../RouteManager';
import { GoogleApiServerUtils } from '../apis/google/GoogleApiServerUtils';
import RouteSubscriber from '../RouteSubscriber';
import { Database } from '../database';
+import { google } from 'googleapis';
const EndpointHandlerMap = new Map<GoogleApiServerUtils.Action, GoogleApiServerUtils.ApiRouter>([
['create', (api, params) => api.create(params)],
@@ -61,5 +62,139 @@ export default class GeneralGoogleManager extends ApiManager {
res.send(undefined);
},
});
+
+ // Task Creation
+ register({
+ method: Method.POST,
+ subscription: new RouteSubscriber('googleTasks').add('create'),
+ secureHandler: async ({ req, res, user }) => {
+ try {
+ const auth = await GoogleApiServerUtils.retrieveOAuthClient(user.id);
+
+ if (!auth) {
+ return res.status(401).send('Google credentials missing or invalid.');
+ }
+
+ const tasks = google.tasks({ version: 'v1', auth });
+
+ const { title, notes, due, status, completed, deleted } = req.body;
+ const result = await tasks.tasks.insert({
+ tasklist: '@default',
+ requestBody: { title, notes, due, status, completed, deleted },
+ });
+
+ res.status(200).send(result.data);
+ } catch (err) {
+ console.error('Google Tasks error:', err);
+ res.status(500).send('Failed to create task.');
+ }
+ },
+ });
+
+ // Task Update
+ register({
+ method: Method.PATCH,
+ subscription: new RouteSubscriber('googleTasks').add('taskId'),
+ // any way to add static params? like /update (this is not very descriptive)
+ secureHandler: async ({ req, res, user }) => {
+ try {
+ const auth = await GoogleApiServerUtils.retrieveOAuthClient(user.id);
+
+ if (!auth) {
+ return res.status(401).send('Google credentials missing or invalid.');
+ }
+
+ const tasks = google.tasks({ version: 'v1', auth });
+
+ const { taskId } = req.params;
+ const { title, notes, due, status, completed, deleted } = req.body;
+
+ const result = await tasks.tasks.patch({
+ tasklist: '@default',
+ task: taskId,
+ requestBody: { title, notes, due, status, completed, deleted},
+ });
+
+ res.status(200).send(result.data);
+ } catch (err) {
+ console.error('Google Tasks update error:', err);
+ res.status(500).send('Failed to update task.');
+ }
+ },
+ });
+
+ // Task Deletion
+ register({
+ method: Method.DELETE,
+ subscription: new RouteSubscriber('googleTasks').add('taskId'),
+ secureHandler: async ({ req, res, user }) => {
+ try {
+ const auth = await GoogleApiServerUtils.retrieveOAuthClient(user.id);
+
+ if (!auth) {
+ return res.status(401).send('Google credentials missing or invalid.');
+ }
+
+ const tasks = google.tasks({ version: 'v1', auth });
+ const { taskId } = req.params;
+
+ await tasks.tasks.delete({
+ tasklist: '@default',
+ task: taskId,
+ });
+
+ res.status(200).send({ success: true });
+ } catch (err) {
+ console.error('Google Tasks delete error:', err);
+ res.status(500).send('Failed to delete task.');
+ }
+ },
+ });
+
+ // Google Account Linking
+
+ register({
+ method: Method.GET,
+ subscription: '/refreshGoogle',
+ secureHandler: async ({ user, req, res }) =>
+ new Promise<void>(resolve =>
+ GoogleApiServerUtils.processNewUser(user.id, req.query.code as string)
+ .then(() => res.status(200).send('Google account linked successfully!'))
+ .catch(err => {
+ console.error('Failed to process Google code:', err);
+ res.status(500).send('Error linking Google account');
+ })
+ .finally(resolve)
+ ),
+ });
+
+ // Task Retrieval
+ register({
+ method: Method.GET,
+ subscription: new RouteSubscriber('googleTasks').add('taskId'),
+ secureHandler: async ({ req, res, user }) => {
+ try {
+ const auth = await GoogleApiServerUtils.retrieveOAuthClient(user.id);
+
+ if (!auth) {
+ return res.status(401).send('Google credentials missing or invalid.');
+ }
+
+ const tasks = google.tasks({ version: 'v1', auth });
+ const { taskId } = req.params;
+
+ const result = await tasks.tasks.get({
+ tasklist: '@default',
+ task: taskId,
+ });
+
+ res.status(200).send(result.data);
+ } catch (err) {
+ console.error('Google Tasks retrieval error:', err);
+ res.status(500).send('Failed to retrieve task.');
+ }
+ },
+ });
}
+
}
diff --git a/src/server/ApiManagers/UploadManager.ts b/src/server/ApiManagers/UploadManager.ts
index 7c55e4a42..1e68a4e30 100644
--- a/src/server/ApiManagers/UploadManager.ts
+++ b/src/server/ApiManagers/UploadManager.ts
@@ -18,7 +18,7 @@ export default class UploadManager extends ApiManager {
protected initialize(register: Registration): void {
register({
method: Method.POST,
- subscription: '/ping',
+ subscription: '/DashPing',
secureHandler: async ({ /* req, */ res }) => {
_success(res, { message: DashVersion, date: new Date() });
},