diff options
author | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-04 13:59:34 -0400 |
---|---|---|
committer | Skitty1238 <157652284+Skitty1238@users.noreply.github.com> | 2025-06-04 13:59:34 -0400 |
commit | 645df1d00f953524c6da22103d26c38ae4331cd6 (patch) | |
tree | 85fc3d4d3f0df579b5c53387d579e46b24e5c543 /src/server/ApiManagers | |
parent | 5a998955235d141d2488c1c2deef50a3d6cf65c7 (diff) |
partial google calendar task integration + fix with dark mode colors for task nodes so that text is still visible
Diffstat (limited to 'src/server/ApiManagers')
-rw-r--r-- | src/server/ApiManagers/FireflyManager.ts | 11 | ||||
-rw-r--r-- | src/server/ApiManagers/GeneralGoogleManager.ts | 73 |
2 files changed, 55 insertions, 29 deletions
diff --git a/src/server/ApiManagers/FireflyManager.ts b/src/server/ApiManagers/FireflyManager.ts index 07ef271a1..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, variations: number = 4) => + 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 diff --git a/src/server/ApiManagers/GeneralGoogleManager.ts b/src/server/ApiManagers/GeneralGoogleManager.ts index aa06ca1b3..e8debfc12 100644 --- a/src/server/ApiManagers/GeneralGoogleManager.ts +++ b/src/server/ApiManagers/GeneralGoogleManager.ts @@ -1,11 +1,10 @@ import ApiManager, { Registration } from './ApiManager'; -import { Method } from '../RouteManager'; +import { Method, _success } 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)], ['retrieve', (api, params) => api.get(params)], @@ -18,9 +17,10 @@ export default class GeneralGoogleManager extends ApiManager { method: Method.GET, subscription: '/readGoogleAccessToken', secureHandler: async ({ user, res }) => { - const { credentials } = await GoogleApiServerUtils.retrieveCredentials(user.id); + const { credentials } = await GoogleApiServerUtils.retrieveCredentials(user); if (!credentials?.access_token) { - return res.send(GoogleApiServerUtils.generateAuthenticationUrl()); + const url = GoogleApiServerUtils.generateAuthenticationUrl(); + return res.send(url); } return res.send(credentials); }, @@ -49,7 +49,7 @@ export default class GeneralGoogleManager extends ApiManager { secureHandler: async ({ req, res, user }) => { const sector: GoogleApiServerUtils.Service = req.params.sector as GoogleApiServerUtils.Service; const action: GoogleApiServerUtils.Action = req.params.action as GoogleApiServerUtils.Action; - const endpoint = await GoogleApiServerUtils.GetEndpoint(GoogleApiServerUtils.Service[sector], user.id); + const endpoint = await GoogleApiServerUtils.GetEndpoint(GoogleApiServerUtils.Service[sector], user); const handler = EndpointHandlerMap.get(action); if (endpoint && handler) { try { @@ -70,31 +70,48 @@ export default class GeneralGoogleManager extends ApiManager { method: Method.POST, subscription: new RouteSubscriber('googleTasks').add('create'), secureHandler: async ({ req, res, user }) => { - try { - const { credentials } = await GoogleApiServerUtils.retrieveCredentials(user.id); - if (!credentials?.access_token) { - return res.status(401).send('Google access token not found.'); + try { + const { credentials } = await GoogleApiServerUtils.retrieveCredentials(user.id); + const access_token = user.googleToken || credentials?.access_token; // if googleToken expires, we need to renew it. + + if (!access_token) { + return res.status(401).send('Google access token not found.'); + } + + const auth = new google.auth.OAuth2(); + auth.setCredentials({ access_token: access_token }); + + const tasks = google.tasks({ version: 'v1', auth }); + + const { title, notes, due } = req.body; + const result = await tasks.tasks.insert({ + tasklist: '@default', + requestBody: { title, notes, due }, + }); + + res.status(200).send(result.data); + } catch (err) { + console.error('Google Tasks error:', err); + res.status(500).send('Failed to create task.'); } - - const auth = new google.auth.OAuth2(); - auth.setCredentials({ access_token: credentials.access_token }); - - const tasks = google.tasks({ version: 'v1', auth }); - - const { title, notes, due } = req.body; - const result = await tasks.tasks.insert({ - tasklist: '@default', - requestBody: { title, notes, due }, - }); - - res.status(200).send(result.data); - } catch (err) { - console.error('Google Tasks error:', err); - res.status(500).send('Failed to create task.'); - } }, - }); + }); - + register({ + method: Method.GET, + subscription: '/refreshGoogle', + secureHandler: async ({ user, req, res }) => { + const code = req.query.code as string; + _success(res, code); + user.googleToken = code; + user.save(); + + // const response2 = await Networking.PostToServer('/writeGoogleAccessToken', { authenticationCode }); + // runInAction(() => { + // this.success = true; + // this.credentials = response2 as { user_info: { name: string; picture: string }; access_token: string }; + // }); + }, + }); } } |