2024-07-31 19:47:52 +05:30
|
|
|
import { default as axios } from "axios";
|
2024-07-31 21:10:52 +05:30
|
|
|
import { WorkflowFile } from "maxun-core";
|
2024-07-31 19:47:52 +05:30
|
|
|
import { RunSettings } from "../components/molecules/RunSettings";
|
2024-09-12 23:41:33 +05:30
|
|
|
import { ScheduleSettings } from "../components/molecules/ScheduleSettings";
|
2024-09-13 08:01:18 +05:30
|
|
|
import { CreateRunResponse, ScheduleRunResponse } from "../pages/MainPage";
|
2024-07-31 19:47:52 +05:30
|
|
|
|
|
|
|
|
export const getStoredRecordings = async (): Promise<string[] | null> => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.get('http://localhost:8080/storage/recordings');
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Couldn\'t retrieve stored recordings');
|
|
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getStoredRuns = async (): Promise<string[] | null> => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.get('http://localhost:8080/storage/runs');
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error('Couldn\'t retrieve stored recordings');
|
|
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-17 15:28:52 +05:30
|
|
|
export const getStoredRecording = async (id: string) => {
|
2024-10-17 14:36:04 +05:30
|
|
|
try {
|
|
|
|
|
const response = await axios.get(`http://localhost:8080/storage/recordings/${id}`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`Couldn't retrieve stored recording ${id}`);
|
|
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-10-17 14:36:04 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-09 23:09:42 +05:30
|
|
|
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
|
2024-07-31 19:47:52 +05:30
|
|
|
try {
|
2024-10-09 23:09:42 +05:30
|
|
|
const response = await axios.delete(`http://localhost:8080/storage/recordings/${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-09 23:09:42 +05:30
|
|
|
throw new Error(`Couldn't delete stored recording ${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-09 23:09:42 +05:30
|
|
|
export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
|
2024-07-31 19:47:52 +05:30
|
|
|
try {
|
2024-10-09 23:09:42 +05:30
|
|
|
const response = await axios.delete(`http://localhost:8080/storage/runs/${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-09 23:09:42 +05:30
|
|
|
throw new Error(`Couldn't delete stored recording ${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-10 03:48:10 +05:30
|
|
|
export const editRecordingFromStorage = async (browserId: string, id: string): Promise<WorkflowFile | null> => {
|
2024-07-31 19:47:52 +05:30
|
|
|
try {
|
2024-10-10 03:48:10 +05:30
|
|
|
const response = await axios.put(`http://localhost:8080/workflow/${browserId}/${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-10 03:48:10 +05:30
|
|
|
throw new Error(`Couldn't edit stored recording ${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-09 23:09:42 +05:30
|
|
|
export const createRunForStoredRecording = async (id: string, settings: RunSettings): Promise<CreateRunResponse> => {
|
2024-07-31 19:47:52 +05:30
|
|
|
try {
|
|
|
|
|
const response = await axios.put(
|
2024-10-09 23:09:42 +05:30
|
|
|
`http://localhost:8080/storage/runs/${id}`,
|
2024-10-22 20:44:14 +05:30
|
|
|
{ ...settings });
|
2024-07-31 19:47:52 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-09 23:09:42 +05:30
|
|
|
throw new Error(`Couldn't create a run for a recording ${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
2024-10-22 20:44:14 +05:30
|
|
|
return { browserId: '', runId: '' };
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 02:24:23 +05:30
|
|
|
export const interpretStoredRecording = async (id: string): Promise<boolean> => {
|
2024-07-31 19:47:52 +05:30
|
|
|
try {
|
2024-10-10 02:24:23 +05:30
|
|
|
const response = await axios.post(`http://localhost:8080/storage/runs/run/${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-10 02:24:23 +05:30
|
|
|
throw new Error(`Couldn't run a recording ${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-22 20:44:14 +05:30
|
|
|
export const notifyAboutAbort = async (id: string): Promise<boolean> => {
|
2024-07-31 19:47:52 +05:30
|
|
|
try {
|
2024-10-10 02:24:23 +05:30
|
|
|
const response = await axios.post(`http://localhost:8080/storage/runs/abort/${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-10 02:24:23 +05:30
|
|
|
throw new Error(`Couldn't abort a running recording with id ${id}`);
|
2024-07-31 19:47:52 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-07-31 19:47:52 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 03:35:37 +05:30
|
|
|
export const scheduleStoredRecording = async (id: string, settings: ScheduleSettings): Promise<ScheduleRunResponse> => {
|
2024-09-12 23:41:33 +05:30
|
|
|
try {
|
|
|
|
|
const response = await axios.put(
|
2024-10-10 03:35:37 +05:30
|
|
|
`http://localhost:8080/storage/schedule/${id}`,
|
2024-10-22 20:44:14 +05:30
|
|
|
{ ...settings });
|
2024-09-12 23:41:33 +05:30
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
2024-10-10 03:35:37 +05:30
|
|
|
throw new Error(`Couldn't schedule recording ${id}. Please try again later.`);
|
2024-09-12 23:41:33 +05:30
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-09-12 23:41:33 +05:30
|
|
|
console.log(error);
|
2024-10-22 20:44:14 +05:30
|
|
|
return { message: '', runId: '' };
|
2024-09-12 23:41:33 +05:30
|
|
|
}
|
|
|
|
|
}
|
2024-10-22 20:43:49 +05:30
|
|
|
|
|
|
|
|
export const getSchedule = async (id: string): Promise<ScheduleSettings | null> => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.get(`http://localhost:8080/storage/schedule/${id}`);
|
|
|
|
|
if (response.status === 200) {
|
|
|
|
|
return response.data;
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`Couldn't retrieve schedule for recording ${id}`);
|
|
|
|
|
}
|
2024-10-22 20:44:14 +05:30
|
|
|
} catch (error: any) {
|
2024-10-22 20:43:49 +05:30
|
|
|
console.log(error);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|