continue: work on violation page
This commit is contained in:
@@ -5,7 +5,6 @@ import { API_BASE_URL } from '@/app/actions/definitions';
|
||||
|
||||
export async function getViolationSearchStatus() {
|
||||
const token = await getSessionData('token');
|
||||
console.log('getViolationSearchStatus');
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/actual-task`, {
|
||||
@@ -16,14 +15,25 @@ export async function getViolationSearchStatus() {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
}
|
||||
});
|
||||
/* console.log(response); */
|
||||
|
||||
if (response.ok) {
|
||||
console.log('parsed');
|
||||
const parsed = await response.json();
|
||||
console.log(parsed);
|
||||
const text = await response.text();
|
||||
|
||||
if (text) {
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
console.log('Parsed:', parsed);
|
||||
return parsed;
|
||||
} catch (e) {
|
||||
console.log('Not JSON, raw text:', text);
|
||||
return {
|
||||
status: text === 'Task not found' ? 'task-not-found' : text
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parsed
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
@@ -40,19 +50,25 @@ export async function startGlobalMonitoring(monitoringType: 'monitoring' | 'all_
|
||||
const response = await fetch(`${API_BASE_URL}/api/v1/global-search/start`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
searchType: monitoringType
|
||||
searchType: monitoringType,
|
||||
...(monitoringType === 'all_files' && { fileIds: [] })
|
||||
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
}
|
||||
});
|
||||
console.log(response);
|
||||
|
||||
if (response.ok) {
|
||||
const parsed = await response.json();
|
||||
const parsed: {
|
||||
taskId: string,
|
||||
status: string,
|
||||
totalFiles: number
|
||||
} = await response.json();
|
||||
|
||||
console.log(parsed);
|
||||
if (parsed?.message_code === 0) {
|
||||
if (parsed?.status === 'ACCEPTED') {
|
||||
return parsed
|
||||
} else {
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user