Skip to content

Commit

Permalink
#820 - Update endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jul 19, 2024
1 parent 00bbb38 commit f583e0e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
24 changes: 13 additions & 11 deletions src/commands/Backers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(CONTEXT.backer, 'global');
Expand Down
13 changes: 10 additions & 3 deletions src/constants/Links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/dashboardWebView/components/Chatbot/Chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }

Expand All @@ -36,7 +36,7 @@ export const Chatbot: React.FunctionComponent<IChatbotProps> = ({ }: 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;
Expand Down Expand Up @@ -70,7 +70,7 @@ export const Chatbot: React.FunctionComponent<IChatbotProps> = ({ }: 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',
Expand Down
3 changes: 2 additions & 1 deletion src/dashboardWebView/components/Chatbot/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,7 @@ export const Feedback: React.FunctionComponent<IFeedbackProps> = ({
}, []);

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',
Expand Down
2 changes: 1 addition & 1 deletion src/dashboardWebView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ if (elm) {
render(
<I10nProvider>
<SettingsProvider
aiUrl={WEBSITE_LINKS.api.url}
aiUrl={WEBSITE_LINKS.api.baseUrl}
experimental={experimental === 'true'}
version={version || ""}>
<Chatbot />
Expand Down
2 changes: 1 addition & 1 deletion src/services/SponsorAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f583e0e

Please sign in to comment.