48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
'use server'
|
|||
|
|
|
||
|
|
import { getSessionData } from '@/app/actions/session';
|
||
|
|
import { API_BASE_URL } from '@/app/actions/definitions';
|
||
|
|
|
||
|
|
export async function fetchModerationContentList(page?: number, size?: number, sortBy?: string, sortDirection?: 'asc' | 'desc' | string, nameQuery?: string) {
|
||
|
|
const token = await getSessionData('token');
|
||
|
|
console.log('fetchModerationContentList');
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch(`${API_BASE_URL}/api/admin`, {
|
||
|
|
method: 'POST',
|
||
|
|
body: JSON.stringify({
|
||
|
|
version: 1,
|
||
|
|
msg_id: 20005,
|
||
|
|
message_body: {
|
||
|
|
action: 'files_for_moderation',
|
||
|
|
/* page: page,
|
||
|
|
size: size,
|
||
|
|
sort_by: sortBy || '',
|
||
|
|
sort_direction: sortDirection || 'asc',
|
||
|
|
full_name: nameQuery */
|
||
|
|
}
|
||
|
|
}),
|
||
|
|
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;
|
||
|
|
} else {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
} else {
|
||
|
|
throw new Error(`${response.status}`);
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|