Recording deletion warning while runs are active

This commit is contained in:
AmitChauhan63390
2024-11-15 16:16:01 +05:30
parent 04ed79b337
commit 8eedca1b1e
5 changed files with 64 additions and 5 deletions

View File

@@ -5,6 +5,10 @@ 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(`${apiUrl}/storage/recordings`);
@@ -47,16 +51,52 @@ export const getStoredRecording = async (id: string) => {
}
}
export const checkRunsForRecording = async (id: string): Promise<boolean> => {
const apiKey = localStorage.getItem('x-api-key');
// Check if the API key exists
if (!apiKey) {
console.error('API key is missing.');
return false;
}
try {
const response = await axios.get(`${apiUrl}/api/robots/${id}/runs`, {
headers: {
'x-api-key': apiKey, // Pass the valid API key in the header
},
withCredentials: true,
});
const runs = response.data;
return runs.runs.totalCount > 0;
} catch (error) {
console.error('Error checking runs for recording:', error);
return false;
}
};
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
const hasRuns = await checkRunsForRecording(id);
if (hasRuns) {
return false;
}
try {
const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`);
if (response.status === 200) {
return response.data;
return true;
} else {
throw new Error(`Couldn't delete stored recording ${id}`);
}
} catch (error: any) {
console.log(error);
return false;
}
};
@@ -93,7 +133,7 @@ export const createRunForStoredRecording = async (id: string, settings: RunSetti
try {
const response = await axios.put(
`${apiUrl}/storage/runs/${id}`,
{ ...settings });
{ ...settings });
if (response.status === 200) {
return response.data;
} else {