refactor: use apiUrl

This commit is contained in:
karishmas6
2024-11-01 08:25:14 +05:30
parent bb38786027
commit ba9e046576
6 changed files with 36 additions and 30 deletions

View File

@@ -1,8 +1,9 @@
import { default as axios } from "axios";
import { apiUrl } from "../apiConfig"
export const getUserById = async (userId: string) => {
try {
const response = await axios.get(`http://localhost:8080/auth/user/${userId}`);
const response = await axios.get(`${apiUrl}/auth/user/${userId}`);
if (response.status === 200) {
return response.data;
} else {

View File

@@ -1,8 +1,9 @@
import { default as axios } from "axios";
import { apiUrl } from "../apiConfig";
export const handleUploadCredentials = async (fileName: string, credentials: any, spreadsheetId: string, range: string): Promise<boolean> => {
try {
const response = await axios.post('http://localhost:8080/integration/upload-credentials', { fileName, credentials: JSON.parse(credentials), spreadsheetId, range });
const response = await axios.post(`${apiUrl}/integration/upload-credentials`, { fileName, credentials: JSON.parse(credentials), spreadsheetId, range });
if (response.status === 200) {
return response.data;
} else {

View File

@@ -1,8 +1,9 @@
import { default as axios } from "axios";
import { apiUrl } from "../apiConfig";
export const sendProxyConfig = async (proxyConfig: { server_url: string, username?: string, password?: string }): Promise<boolean> => {
try {
const response = await axios.post(`http://localhost:8080/proxy/config`, proxyConfig);
const response = await axios.post(`${apiUrl}/proxy/config`, proxyConfig);
if (response.status === 200) {
return response.data;
} else {
@@ -16,7 +17,7 @@ export const sendProxyConfig = async (proxyConfig: { server_url: string, usernam
export const getProxyConfig = async (): Promise<{ proxy_url: string, auth: boolean }> => {
try {
const response = await axios.get(`http://localhost:8080/proxy/config`);
const response = await axios.get(`${apiUrl}/proxy/config`);
if (response.status === 200) {
return response.data;
} else {
@@ -30,7 +31,7 @@ export const getProxyConfig = async (): Promise<{ proxy_url: string, auth: boole
export const testProxyConfig = async (): Promise<{ success: boolean }> => {
try {
const response = await axios.get(`http://localhost:8080/proxy/test`);
const response = await axios.get(`${apiUrl}/proxy/test`);
if (response.status === 200) {
return response.data;
} else {
@@ -44,7 +45,7 @@ export const testProxyConfig = async (): Promise<{ success: boolean }> => {
export const deleteProxyConfig = async (): Promise<boolean> => {
try {
const response = await axios.delete(`http://localhost:8080/proxy/config`);
const response = await axios.delete(`${apiUrl}/proxy/config`);
if (response.status === 200) {
return response.data;
} else {

View File

@@ -1,8 +1,9 @@
import { default as axios, AxiosResponse } from "axios";
import { apiUrl } from "../apiConfig";
export const startRecording = async() : Promise<string> => {
try {
const response = await axios.get('http://localhost:8080/record/start')
const response = await axios.get(`${apiUrl}/record/start`)
if (response.status === 200) {
return response.data;
} else {
@@ -14,7 +15,7 @@ export const startRecording = async() : Promise<string> => {
};
export const stopRecording = async (id: string): Promise<void> => {
await axios.get(`http://localhost:8080/record/stop/${id}`)
await axios.get(`${apiUrl}/record/stop/${id}`)
.then((response : AxiosResponse<boolean>) => {
})
.catch((error: any) => {
@@ -23,7 +24,7 @@ export const stopRecording = async (id: string): Promise<void> => {
export const getActiveBrowserId = async(): Promise<string> => {
try {
const response = await axios.get('http://localhost:8080/record/active');
const response = await axios.get(`${apiUrl}/record/active`);
if (response.status === 200) {
return response.data;
} else {
@@ -36,7 +37,7 @@ export const getActiveBrowserId = async(): Promise<string> => {
export const interpretCurrentRecording = async(): Promise<boolean> => {
try {
const response = await axios.get('http://localhost:8080/record/interpret');
const response = await axios.get(`${apiUrl}/record/interpret`);
if (response.status === 200) {
return true;
} else {
@@ -50,7 +51,7 @@ export const interpretCurrentRecording = async(): Promise<boolean> => {
export const stopCurrentInterpretation = async(): Promise<void> => {
try {
const response = await axios.get('http://localhost:8080/record/interpret/stop');
const response = await axios.get(`${apiUrl}/record/interpret/stop`);
if (response.status === 200) {
return;
} else {
@@ -63,7 +64,7 @@ export const stopCurrentInterpretation = async(): Promise<void> => {
export const getCurrentUrl = async (): Promise<string | null> => {
try {
const response = await axios.get('http://localhost:8080/record/active/url');
const response = await axios.get(`${apiUrl}/record/active/url`);
if (response.status === 200) {
return response.data;
} else {
@@ -77,7 +78,7 @@ export const getCurrentUrl = async (): Promise<string | null> => {
export const getCurrentTabs = async (): Promise<string[] | null> => {
try {
const response = await axios.get('http://localhost:8080/record/active/tabs');
const response = await axios.get(`${apiUrl}/record/active/tabs`);
if (response.status === 200) {
return response.data;
} else {

View File

@@ -3,10 +3,11 @@ import { WorkflowFile } from "maxun-core";
import { RunSettings } from "../components/molecules/RunSettings";
import { ScheduleSettings } from "../components/molecules/ScheduleSettings";
import { CreateRunResponse, ScheduleRunResponse } from "../pages/MainPage";
import { apiUrl } from "../apiConfig";
export const getStoredRecordings = async (): Promise<string[] | null> => {
try {
const response = await axios.get('http://localhost:8080/storage/recordings');
const response = await axios.get(`${apiUrl}/storage/recordings`);
if (response.status === 200) {
return response.data;
} else {
@@ -20,7 +21,7 @@ export const getStoredRecordings = async (): Promise<string[] | null> => {
export const getStoredRuns = async (): Promise<string[] | null> => {
try {
const response = await axios.get('http://localhost:8080/storage/runs');
const response = await axios.get(`${apiUrl}/storage/runs`);
if (response.status === 200) {
return response.data;
} else {
@@ -34,7 +35,7 @@ export const getStoredRuns = async (): Promise<string[] | null> => {
export const getStoredRecording = async (id: string) => {
try {
const response = await axios.get(`http://localhost:8080/storage/recordings/${id}`);
const response = await axios.get(`${apiUrl}/storage/recordings/${id}`);
if (response.status === 200) {
return response.data;
} else {
@@ -48,7 +49,7 @@ export const getStoredRecording = async (id: string) => {
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
try {
const response = await axios.delete(`http://localhost:8080/storage/recordings/${id}`);
const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`);
if (response.status === 200) {
return response.data;
} else {
@@ -62,7 +63,7 @@ export const deleteRecordingFromStorage = async (id: string): Promise<boolean> =
export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
try {
const response = await axios.delete(`http://localhost:8080/storage/runs/${id}`);
const response = await axios.delete(`${apiUrl}/storage/runs/${id}`);
if (response.status === 200) {
return response.data;
} else {
@@ -76,7 +77,7 @@ export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
export const editRecordingFromStorage = async (browserId: string, id: string): Promise<WorkflowFile | null> => {
try {
const response = await axios.put(`http://localhost:8080/workflow/${browserId}/${id}`);
const response = await axios.put(`${apiUrl}/workflow/${browserId}/${id}`);
if (response.status === 200) {
return response.data;
} else {
@@ -91,7 +92,7 @@ export const editRecordingFromStorage = async (browserId: string, id: string): P
export const createRunForStoredRecording = async (id: string, settings: RunSettings): Promise<CreateRunResponse> => {
try {
const response = await axios.put(
`http://localhost:8080/storage/runs/${id}`,
`${apiUrl}/storage/runs/${id}`,
{ ...settings });
if (response.status === 200) {
return response.data;
@@ -106,7 +107,7 @@ export const createRunForStoredRecording = async (id: string, settings: RunSetti
export const interpretStoredRecording = async (id: string): Promise<boolean> => {
try {
const response = await axios.post(`http://localhost:8080/storage/runs/run/${id}`);
const response = await axios.post(`${apiUrl}/storage/runs/run/${id}`);
if (response.status === 200) {
return response.data;
} else {
@@ -120,7 +121,7 @@ export const interpretStoredRecording = async (id: string): Promise<boolean> =>
export const notifyAboutAbort = async (id: string): Promise<boolean> => {
try {
const response = await axios.post(`http://localhost:8080/storage/runs/abort/${id}`);
const response = await axios.post(`${apiUrl}/storage/runs/abort/${id}`);
if (response.status === 200) {
return response.data;
} else {
@@ -135,7 +136,7 @@ export const notifyAboutAbort = async (id: string): Promise<boolean> => {
export const scheduleStoredRecording = async (id: string, settings: ScheduleSettings): Promise<ScheduleRunResponse> => {
try {
const response = await axios.put(
`http://localhost:8080/storage/schedule/${id}`,
`${apiUrl}/storage/schedule/${id}`,
{ ...settings });
if (response.status === 200) {
return response.data;
@@ -150,7 +151,7 @@ export const scheduleStoredRecording = async (id: string, settings: ScheduleSett
export const getSchedule = async (id: string) => {
try {
const response = await axios.get(`http://localhost:8080/storage/schedule/${id}`);
const response = await axios.get(`${apiUrl}/storage/schedule/${id}`);
if (response.status === 200) {
return response.data.schedule;
} else {
@@ -164,7 +165,7 @@ export const getSchedule = async (id: string) => {
export const deleteSchedule = async (id: string): Promise<boolean> => {
try {
const response = await axios.delete(`http://localhost:8080/storage/schedule/${id}`);
const response = await axios.delete(`${apiUrl}/storage/schedule/${id}`);
if (response.status === 200) {
return response.data;
} else {

View File

@@ -1,10 +1,11 @@
import { WhereWhatPair, WorkflowFile } from "maxun-core";
import { emptyWorkflow } from "../shared/constants";
import { default as axios, AxiosResponse } from "axios";
import { apiUrl } from "../apiConfig";
export const getActiveWorkflow = async(id: string) : Promise<WorkflowFile> => {
try {
const response = await axios.get(`http://localhost:8080/workflow/${id}`)
const response = await axios.get(`${apiUrl}/workflow/${id}`)
if (response.status === 200) {
return response.data;
} else {
@@ -18,7 +19,7 @@ export const getActiveWorkflow = async(id: string) : Promise<WorkflowFile> => {
export const getParamsOfActiveWorkflow = async(id: string) : Promise<string[]|null> => {
try {
const response = await axios.get(`http://localhost:8080/workflow/params/${id}`)
const response = await axios.get(`${apiUrl}/workflow/params/${id}`)
if (response.status === 200) {
return response.data;
} else {
@@ -32,7 +33,7 @@ export const getParamsOfActiveWorkflow = async(id: string) : Promise<string[]|nu
export const deletePair = async(index: number): Promise<WorkflowFile> => {
try {
const response = await axios.delete(`http://localhost:8080/workflow/pair/${index}`);
const response = await axios.delete(`${apiUrl}/workflow/pair/${index}`);
if (response.status === 200) {
return response.data;
} else {
@@ -46,7 +47,7 @@ export const deletePair = async(index: number): Promise<WorkflowFile> => {
export const AddPair = async(index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
try {
const response = await axios.post(`http://localhost:8080/workflow/pair/${index}`, {
const response = await axios.post(`${apiUrl}/workflow/pair/${index}`, {
pair,
}, {headers: {'Content-Type': 'application/json'}});
if (response.status === 200) {
@@ -62,7 +63,7 @@ export const AddPair = async(index: number, pair: WhereWhatPair): Promise<Workfl
export const UpdatePair = async(index: number, pair: WhereWhatPair): Promise<WorkflowFile> => {
try {
const response = await axios.put(`http://localhost:8080/workflow/pair/${index}`, {
const response = await axios.put(`${apiUrl}/workflow/pair/${index}`, {
pair,
}, {headers: {'Content-Type': 'application/json'}});
if (response.status === 200) {