Files
no-copy-frontend/src/app/actions/action.ts
T

65 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-11-25 17:13:16 +07:00
'use server'
2025-12-09 16:35:47 +07:00
import { getSessionData } from '@/app/actions/session';
2025-12-27 11:54:54 +07:00
import { testUserData, API_BASE_URL } from '@/app/actions/definitions';
2026-01-12 13:39:35 +07:00
import {tokenLifeExtension} from '@/app/actions/auth';
2025-11-29 14:40:26 +07:00
2025-12-02 17:11:53 +07:00
export async function getUserData() {
const userEmail = await getSessionData('email');
const token = await getSessionData('token');
2025-12-11 18:28:35 +07:00
/* для теста */
if (userEmail === "test" && token === "1111") {
return testUserData;
}
/* для теста */
2025-11-25 17:13:16 +07:00
try {
2025-12-07 10:58:53 +07:00
const response = await fetch(`${API_BASE_URL}/v1/api/user?email=${userEmail}`, {
2025-12-02 17:11:53 +07:00
method: 'GET',
2025-11-25 17:13:16 +07:00
headers: {
"Content-Type": "application/json",
2025-12-02 17:11:53 +07:00
"Accept": "application/json",
"Authorization": `Bearer ${token}`,
2025-11-25 17:13:16 +07:00
}
});
2025-12-02 17:11:53 +07:00
if (response.ok) {
return await response.json();
}
2025-11-25 17:13:16 +07:00
} catch (error) {
2025-12-02 17:11:53 +07:00
console.error('error');
2025-11-25 17:13:16 +07:00
}
2026-01-07 13:03:50 +07:00
}
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}`);
}
2025-11-25 17:13:16 +07:00
}