Files
parcer/src/api/recording.ts

92 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-10-24 22:24:29 +05:30
import { default as axios, AxiosResponse } from "axios";
2024-11-01 08:25:14 +05:30
import { apiUrl } from "../apiConfig";
2024-06-09 01:06:04 +05:30
export const startRecording = async() : Promise<string> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/record/start`)
2024-06-09 01:06:04 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Couldn\'t start recording');
}
} catch(error: any) {
return '';
}
};
2024-06-09 01:06:22 +05:30
export const stopRecording = async (id: string): Promise<void> => {
2024-11-01 08:25:14 +05:30
await axios.get(`${apiUrl}/record/stop/${id}`)
2024-06-09 01:06:22 +05:30
.then((response : AxiosResponse<boolean>) => {
})
.catch((error: any) => {
});
};
2024-06-09 01:06:38 +05:30
export const getActiveBrowserId = async(): Promise<string> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/record/active`);
2024-06-09 01:06:38 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Couldn\'t get active browser');
}
} catch(error: any) {
return '';
}
};
2024-06-09 01:06:58 +05:30
export const interpretCurrentRecording = async(): Promise<boolean> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/record/interpret`);
2024-06-09 01:06:58 +05:30
if (response.status === 200) {
return true;
} else {
throw new Error('Couldn\'t interpret current recording');
}
} catch(error: any) {
console.log(error);
return false;
}
};
2024-06-09 01:07:17 +05:30
export const stopCurrentInterpretation = async(): Promise<void> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/record/interpret/stop`);
2024-06-09 01:07:17 +05:30
if (response.status === 200) {
return;
} else {
throw new Error('Couldn\'t interpret current recording');
}
} catch(error: any) {
console.log(error);
}
};
2024-06-09 01:07:30 +05:30
export const getCurrentUrl = async (): Promise<string | null> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/record/active/url`);
2024-06-09 01:07:30 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Couldn\'t retrieve stored recordings');
}
} catch(error: any) {
console.log(error);
return null;
}
};
2024-06-09 01:07:37 +05:30
export const getCurrentTabs = async (): Promise<string[] | null> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/record/active/tabs`);
2024-06-09 01:07:37 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error('Couldn\'t retrieve stored recordings');
}
} catch(error: any) {
console.log(error);
return null;
}
};