Route corrected
This commit is contained in:
@@ -16,6 +16,7 @@ import { workflowQueue } from '../worker';
|
|||||||
import { AuthenticatedRequest } from './record';
|
import { AuthenticatedRequest } from './record';
|
||||||
import { computeNextRun } from '../utils/schedule';
|
import { computeNextRun } from '../utils/schedule';
|
||||||
import { capture } from "../utils/analytics";
|
import { capture } from "../utils/analytics";
|
||||||
|
import { tryCatch } from 'bullmq';
|
||||||
|
|
||||||
export const router = Router();
|
export const router = Router();
|
||||||
|
|
||||||
@@ -57,6 +58,60 @@ router.get('/recordings/:id', requireSignIn, async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.get(('/recordings/:id/runs'), requireSignIn, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const runs = await Run.findAll({
|
||||||
|
where: {
|
||||||
|
robotMetaId: req.params.id
|
||||||
|
},
|
||||||
|
raw: true
|
||||||
|
});
|
||||||
|
const formattedRuns = runs.map(formatRunResponse);
|
||||||
|
const response = {
|
||||||
|
statusCode: 200,
|
||||||
|
messageCode: "success",
|
||||||
|
runs: {
|
||||||
|
totalCount: formattedRuns.length,
|
||||||
|
items: formattedRuns,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
res.status(200).json(response);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching runs:", error);
|
||||||
|
res.status(500).json({
|
||||||
|
statusCode: 500,
|
||||||
|
messageCode: "error",
|
||||||
|
message: "Failed to retrieve runs",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function formatRunResponse(run: any) {
|
||||||
|
const formattedRun = {
|
||||||
|
id: run.id,
|
||||||
|
status: run.status,
|
||||||
|
name: run.name,
|
||||||
|
robotId: run.robotMetaId, // Renaming robotMetaId to robotId
|
||||||
|
startedAt: run.startedAt,
|
||||||
|
finishedAt: run.finishedAt,
|
||||||
|
runId: run.runId,
|
||||||
|
runByUserId: run.runByUserId,
|
||||||
|
runByScheduleId: run.runByScheduleId,
|
||||||
|
runByAPI: run.runByAPI,
|
||||||
|
data: {},
|
||||||
|
screenshot: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (run.serializableOutput && run.serializableOutput['item-0']) {
|
||||||
|
formattedRun.data = run.serializableOutput['item-0'];
|
||||||
|
} else if (run.binaryOutput && run.binaryOutput['item-0']) {
|
||||||
|
formattedRun.screenshot = run.binaryOutput['item-0'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return formattedRun;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE endpoint for deleting a recording from the storage.
|
* DELETE endpoint for deleting a recording from the storage.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { apiUrl } from "../apiConfig";
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const getStoredRecordings = async (): Promise<string[] | null> => {
|
export const getStoredRecordings = async (): Promise<string[] | null> => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${apiUrl}/storage/recordings`);
|
const response = await axios.get(`${apiUrl}/storage/recordings`);
|
||||||
@@ -52,24 +53,15 @@ 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
|
export const checkRunsForRecording = async (id: string): Promise<boolean> => {
|
||||||
if (!apiKey) {
|
|
||||||
console.error('API key is missing.');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${apiUrl}/api/robots/${id}/runs`, {
|
const response = await axios.get(`${apiUrl}/storage/recordings/${id}/runs`);
|
||||||
headers: {
|
|
||||||
'x-api-key': apiKey, // Pass the valid API key in the header
|
|
||||||
},
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const runs = response.data;
|
const runs = response.data;
|
||||||
|
console.log(runs.runs.totalCount)
|
||||||
return runs.runs.totalCount > 0;
|
return runs.runs.totalCount > 0;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking runs for recording:', error);
|
console.error('Error checking runs for recording:', error);
|
||||||
@@ -77,6 +69,7 @@ export const checkRunsForRecording = async (id: string): Promise<boolean> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
|
export const deleteRecordingFromStorage = async (id: string): Promise<boolean> => {
|
||||||
|
|
||||||
const hasRuns = await checkRunsForRecording(id);
|
const hasRuns = await checkRunsForRecording(id);
|
||||||
@@ -85,7 +78,6 @@ export const deleteRecordingFromStorage = async (id: string): Promise<boolean> =
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`);
|
const response = await axios.delete(`${apiUrl}/storage/recordings/${id}`);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
@@ -99,6 +91,10 @@ export const deleteRecordingFromStorage = async (id: string): Promise<boolean> =
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
|
export const deleteRunFromStorage = async (id: string): Promise<boolean> => {
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import { Add } from "@mui/icons-material";
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { stopRecording } from "../../api/recording";
|
import { stopRecording } from "../../api/recording";
|
||||||
import { GenericModal } from '../atoms/GenericModal';
|
import { GenericModal } from '../atoms/GenericModal';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { apiUrl } from '../../apiConfig';
|
||||||
|
|
||||||
|
|
||||||
/** TODO:
|
/** TODO:
|
||||||
@@ -159,12 +161,7 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const hasAssociatedRuns = async (robotId: string): Promise<boolean> => {
|
|
||||||
|
|
||||||
const associatedRuns = await fetch(`/api/robot/${robotId}/runs`);
|
|
||||||
const data = await associatedRuns.json();
|
|
||||||
return data.length > 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
@@ -258,21 +255,31 @@ export const RecordingsTable = ({ handleEditRecording, handleRunRecording, handl
|
|||||||
case 'delete':
|
case 'delete':
|
||||||
return (
|
return (
|
||||||
<TableCell key={column.id} align={column.align}>
|
<TableCell key={column.id} align={column.align}>
|
||||||
<IconButton aria-label="add" size="small" onClick={() => {
|
<IconButton aria-label="add" size="small" onClick={async () => {
|
||||||
|
|
||||||
checkRunsForRecording(row.id).then((result: boolean) => {
|
checkRunsForRecording(row.id).then((result: boolean) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
notify('warning', 'Recording has associated runs, please delete them first');
|
notify('warning', 'Cannot delete recording as it has active runs');
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
|
||||||
if (result) {
|
|
||||||
setRows([]);
|
|
||||||
notify('success', 'Recording deleted successfully');
|
|
||||||
fetchRecordings();
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
deleteRecordingFromStorage(row.id).then((result: boolean) => {
|
||||||
|
if (result) {
|
||||||
|
setRows([]);
|
||||||
|
notify('success', 'Recording deleted successfully');
|
||||||
|
fetchRecordings();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}}>
|
}}>
|
||||||
<DeleteForever />
|
<DeleteForever />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ const ApiKeyManager = () => {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchApiKey = async () => {
|
const fetchApiKey = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -51,6 +53,7 @@ const ApiKeyManager = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchApiKey();
|
fetchApiKey();
|
||||||
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const generateApiKey = async () => {
|
const generateApiKey = async () => {
|
||||||
@@ -58,7 +61,7 @@ const ApiKeyManager = () => {
|
|||||||
try {
|
try {
|
||||||
const { data } = await axios.post(`${apiUrl}/auth/generate-api-key`);
|
const { data } = await axios.post(`${apiUrl}/auth/generate-api-key`);
|
||||||
setApiKey(data.api_key);
|
setApiKey(data.api_key);
|
||||||
localStorage.setItem('x-api-key', data.api_key);
|
|
||||||
notify('success', `Generated API Key successfully`);
|
notify('success', `Generated API Key successfully`);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
notify('error', `Failed to generate API Key - ${error.message}`);
|
notify('error', `Failed to generate API Key - ${error.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user