2026-03-06 14:53:51 +07:00
|
|
|
'use server'
|
|
|
|
|
|
|
|
|
|
import { getSessionData } from '@/app/actions/session';
|
|
|
|
|
import { API_BASE_URL } from '@/app/actions/definitions';
|
|
|
|
|
|
|
|
|
|
export async function setMonitoring(fileId: string, monitoringType: string) {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30007,
|
|
|
|
|
message_body: {
|
|
|
|
|
monitoring_type: monitoringType,
|
2026-06-01 14:48:13 +07:00
|
|
|
file_id: fileId
|
2026-03-06 14:53:51 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
2026-06-01 14:48:13 +07:00
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
2026-03-06 14:53:51 +07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
let parsed = await response.json();
|
|
|
|
|
if (parsed.message_code === 0) {
|
|
|
|
|
return {
|
|
|
|
|
success: true,
|
|
|
|
|
errorMessage: null
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
throw parsed;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw (`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return {
|
|
|
|
|
success: false,
|
|
|
|
|
errorMessage: 'error'
|
|
|
|
|
};
|
|
|
|
|
}
|
2026-04-01 11:24:47 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface MonitoringStats {
|
|
|
|
|
total_searches: number;
|
|
|
|
|
searches_by_status: {
|
|
|
|
|
processing: number;
|
|
|
|
|
completed: number;
|
|
|
|
|
failed: number;
|
|
|
|
|
total: number;
|
|
|
|
|
};
|
|
|
|
|
recent_searches: any[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchMonitoringStats(): Promise<MonitoringStats | null> {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
2026-06-01 14:48:13 +07:00
|
|
|
msg_id: 30011
|
2026-04-01 11:24:47 +07:00
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
2026-06-01 14:48:13 +07:00
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
2026-04-01 11:24:47 +07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const parsed = await response.json();
|
|
|
|
|
if (parsed?.message_body?.searches_by_status) {
|
|
|
|
|
return parsed.message_body;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-04-20 16:48:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchLastMonitoringCheck() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 30011,
|
|
|
|
|
message_body: {
|
|
|
|
|
limit: 1
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
2026-06-01 14:48:13 +07:00
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
2026-04-20 16:48:15 +07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_body?.searches_by_status) {
|
|
|
|
|
return parsed.message_body;
|
2026-05-08 15:48:26 +07:00
|
|
|
} else {
|
|
|
|
|
return null
|
2026-04-20 16:48:15 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-04-20 17:36:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchMonitoringInfo() {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${API_BASE_URL}/api/v1/data`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
2026-06-01 14:48:13 +07:00
|
|
|
msg_id: 30027
|
2026-04-20 17:36:33 +07:00
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
2026-06-01 14:48:13 +07:00
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
2026-04-20 17:36:33 +07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed?.message_body) {
|
|
|
|
|
return parsed.message_body;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-03-06 14:53:51 +07:00
|
|
|
}
|