From f583e0e91a0ad9b2b50ae93441f3b397fc4f485a Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Fri, 19 Jul 2024 16:29:10 +0200 Subject: [PATCH] #820 - Update endpoints --- src/commands/Backers.ts | 24 ++++++++++--------- src/constants/Links.ts | 13 +++++++--- .../components/Chatbot/Chatbot.tsx | 6 ++--- .../components/Chatbot/Feedback.tsx | 3 ++- src/dashboardWebView/index.tsx | 2 +- src/services/SponsorAI.ts | 2 +- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/commands/Backers.ts b/src/commands/Backers.ts index ff153ee2..dd6df62e 100644 --- a/src/commands/Backers.ts +++ b/src/commands/Backers.ts @@ -22,17 +22,19 @@ export class Backers { const githubAuth = await authentication.getSession('github', ['read:user'], { silent: true }); if (githubAuth && githubAuth.accessToken) { try { - const isBeta = ext.isBetaVersion(); - const response = await fetch(`${WEBSITE_LINKS.api.url}/api/v2/backers`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - accept: 'application/json' - }, - body: JSON.stringify({ - token: githubAuth.accessToken - }) - }); + const response = await fetch( + `${WEBSITE_LINKS.api.baseUrl}${WEBSITE_LINKS.api.endpoints.backers}`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + accept: 'application/json' + }, + body: JSON.stringify({ + token: githubAuth.accessToken + }) + } + ); if (response.ok) { const prevData = await ext.getState(CONTEXT.backer, 'global'); diff --git a/src/constants/Links.ts b/src/constants/Links.ts index ec48b3c6..a28d7ec3 100644 --- a/src/constants/Links.ts +++ b/src/constants/Links.ts @@ -14,9 +14,16 @@ export const DOCS_SUBMODULES = 'https://frontmatter.codes/docs/git-integration#g export const WEBSITE_LINKS = { root: 'https://frontmatter.codes', api: { - url: 'https://fontmatter-fncs.azurewebsites.net', - metrics: 'https://frontmatter.codes/api/metrics', - ai: 'https://frontmatter.codes/api/ai' + baseUrl: 'https://fontmatter-fncs.azurewebsites.net', + endpoints: { + ai: '/api/ai', + chat: { + init: '/api/ai-init', + message: '/api/ai-chat', + feedback: '/api/ai-feedback' + }, + backers: '/api/backers' + } }, docs: { dataDashboard: 'https://frontmatter.codes/docs/dashboard/datafiles-view', diff --git a/src/dashboardWebView/components/Chatbot/Chatbot.tsx b/src/dashboardWebView/components/Chatbot/Chatbot.tsx index 295cb9fa..90d4dea6 100644 --- a/src/dashboardWebView/components/Chatbot/Chatbot.tsx +++ b/src/dashboardWebView/components/Chatbot/Chatbot.tsx @@ -10,7 +10,7 @@ import { AiInitResponse } from './models/AiInitResponse'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../../../localization'; import { messageHandler } from '@estruyf/vscode/dist/client'; -import { GeneralCommands } from '../../../constants'; +import { GeneralCommands, WEBSITE_LINKS } from '../../../constants'; export interface IChatbotProps { } @@ -36,7 +36,7 @@ export const Chatbot: React.FunctionComponent = ({ }: React.Props setLocaleReady(true); }); - const initResponse = await fetch(`${aiUrl}/api/ai-init`); + const initResponse = await fetch(`${aiUrl}${WEBSITE_LINKS.api.endpoints.chat.init}`); if (!initResponse.ok) { return; @@ -70,7 +70,7 @@ export const Chatbot: React.FunctionComponent = ({ }: React.Props return; } - const response = await fetch(`${aiUrl}/api/ai-chat`, { + const response = await fetch(`${aiUrl}${WEBSITE_LINKS.api.endpoints.chat.message}`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/dashboardWebView/components/Chatbot/Feedback.tsx b/src/dashboardWebView/components/Chatbot/Feedback.tsx index 535d3ee7..664f1932 100644 --- a/src/dashboardWebView/components/Chatbot/Feedback.tsx +++ b/src/dashboardWebView/components/Chatbot/Feedback.tsx @@ -3,6 +3,7 @@ import { HandThumbDownIcon, HandThumbUpIcon } from '@heroicons/react/24/outline' import { HandThumbDownIcon as ThumbDownSolidIcon, HandThumbUpIcon as ThumbUpSolidIcon } from '@heroicons/react/24/solid'; import { useCallback } from 'react'; import { useSettingsContext } from '../../providers/SettingsProvider'; +import { WEBSITE_LINKS } from '../../../constants'; export interface IFeedbackProps { answerId: number; @@ -28,7 +29,7 @@ export const Feedback: React.FunctionComponent = ({ }, []); const callVote = useCallback(async (vote: boolean) => { - await fetch(`${aiUrl}/api/ai-feedback`, { + await fetch(`${aiUrl}${WEBSITE_LINKS.api.endpoints.chat.feedback}`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/dashboardWebView/index.tsx b/src/dashboardWebView/index.tsx index c0018ae4..fc6e4ec5 100644 --- a/src/dashboardWebView/index.tsx +++ b/src/dashboardWebView/index.tsx @@ -93,7 +93,7 @@ if (elm) { render( diff --git a/src/services/SponsorAI.ts b/src/services/SponsorAI.ts index 02b6c0ad..fe459b5f 100644 --- a/src/services/SponsorAI.ts +++ b/src/services/SponsorAI.ts @@ -9,7 +9,7 @@ import { TaxonomyType } from '../models'; import * as l10n from '@vscode/l10n'; import { LocalizationKey } from '../localization'; -const AI_URL = `${WEBSITE_LINKS.api.url}/api/ai`; +const AI_URL = `${WEBSITE_LINKS.api.baseUrl}${WEBSITE_LINKS.api.endpoints.ai}`; // const AI_URL = 'http://localhost:3000/api/ai'; export class SponsorAi {