65 lines
1.4 KiB
TypeScript
65 lines
1.4 KiB
TypeScript
'use server'
|
|
import { getSessionData } from '@/app/actions/session';
|
|
import { testUserData, API_BASE_URL } from '@/app/actions/definitions';
|
|
import {tokenLifeExtension} from '@/app/actions/auth';
|
|
|
|
export async function getUserData() {
|
|
const userEmail = await getSessionData('email');
|
|
const token = await getSessionData('token');
|
|
|
|
/* для теста */
|
|
if (userEmail === "test" && token === "1111") {
|
|
return testUserData;
|
|
}
|
|
/* для теста */
|
|
|
|
try {
|
|
const response = await fetch(`${API_BASE_URL}/v1/api/user?email=${userEmail}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json",
|
|
"Authorization": `Bearer ${token}`,
|
|
}
|
|
});
|
|
|
|
if (response.ok) {
|
|
return await response.json();
|
|
}
|
|
} catch (error) {
|
|
console.error('error');
|
|
}
|
|
}
|
|
|
|
export async function getUserFilesInfo() {
|
|
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: 20005,
|
|
message_body: {
|
|
action: "user_files_info",
|
|
token: token
|
|
}
|
|
}),
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"Accept": "application/json"
|
|
}
|
|
});
|
|
|
|
if (response.ok) {
|
|
const parsed = await response.json();
|
|
if (parsed.message_code === 0) {
|
|
return parsed.message_body;
|
|
} else {
|
|
throw parsed.message_code;
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.error(`error: ${error}`);
|
|
}
|
|
} |