2026-05-25 16:10:11 +07:00
|
|
|
'use server'
|
|
|
|
|
|
|
|
|
|
import { getSessionData } from '@/app/actions/session';
|
2026-05-27 13:29:49 +07:00
|
|
|
import { API_BASE_URL, API_DASHBOARD_URL } from '@/app/actions/definitions';
|
2026-05-25 16:10:11 +07:00
|
|
|
|
2026-05-26 20:31:51 +07:00
|
|
|
export async function fetchModerationContentList(page?: number, size?: number, sortBy?: string, sortDirection?: 'asc' | 'desc' | string) {
|
2026-05-25 16:10:11 +07:00
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-26 20:31:51 +07:00
|
|
|
const response = await fetch(`${API_BASE_URL}/api/admin/info`, {
|
2026-05-25 16:10:11 +07:00
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
2026-05-26 20:31:51 +07:00
|
|
|
msg_id: 40001,
|
2026-05-25 16:10:11 +07:00
|
|
|
message_body: {
|
|
|
|
|
action: 'files_for_moderation',
|
2026-05-26 20:31:51 +07:00
|
|
|
page: page,
|
|
|
|
|
page_size: size,
|
2026-05-27 12:56:13 +07:00
|
|
|
sort_by: sortBy || '',
|
|
|
|
|
sort_order: sortDirection || 'asc',
|
2026-05-25 16:10:11 +07:00
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const parsed = await response.json();
|
|
|
|
|
|
|
|
|
|
if (parsed.message_code === 0) {
|
2026-05-26 20:31:51 +07:00
|
|
|
return parsed.message_body.message_body;
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function changeModerationContentStatus(fileId?: string, fileStatus?: string) {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
try {
|
2026-05-27 12:56:13 +07:00
|
|
|
const response = await fetch(`${API_BASE_URL}/api/admin/control`, {
|
2026-05-26 20:31:51 +07:00
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
version: 1,
|
|
|
|
|
msg_id: 40002,
|
|
|
|
|
message_body: {
|
|
|
|
|
action: 'change_file_status',
|
|
|
|
|
file_id: fileId,
|
|
|
|
|
file_status: fileStatus
|
|
|
|
|
}
|
|
|
|
|
}),
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Authorization': `Bearer ${token}`
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const parsed = await response.json();
|
|
|
|
|
console.log(parsed);
|
|
|
|
|
|
|
|
|
|
if (parsed.message_code === 0) {
|
|
|
|
|
return parsed.message_body.message_body;
|
2026-05-25 16:10:11 +07:00
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-05-27 13:29:49 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function downloadFile(fileId: string, fileName: string) {
|
|
|
|
|
const token = await getSessionData('token');
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`${API_DASHBOARD_URL}/api/v1/files/download/${fileId}`, {
|
|
|
|
|
headers: {
|
|
|
|
|
'Authorization': `Bearer ${token}`,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw 'failed-to-download-file';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const arrayBuffer = await response.arrayBuffer()
|
|
|
|
|
const base64 = Buffer.from(arrayBuffer).toString('base64')
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
data: base64,
|
|
|
|
|
contentType: response.headers.get('content-type') || 'application/octet-stream',
|
|
|
|
|
fileName: fileName
|
|
|
|
|
}
|
2026-05-25 16:10:11 +07:00
|
|
|
}
|