add cases to Shop (roulette don't work :( )
This commit is contained in:
@ -207,6 +207,94 @@ export interface MeResponse {
|
||||
is_admin: boolean;
|
||||
}
|
||||
|
||||
export interface CaseItemMeta {
|
||||
display_name?: string | null;
|
||||
lore?: string[] | null;
|
||||
}
|
||||
|
||||
export interface CaseItem {
|
||||
id: string;
|
||||
name?: string;
|
||||
material: string;
|
||||
amount: number;
|
||||
weight?: number;
|
||||
meta?: CaseItemMeta;
|
||||
}
|
||||
|
||||
export interface Case {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
price: number;
|
||||
image_url?: string;
|
||||
server_ids?: string[];
|
||||
items_count?: number;
|
||||
items?: CaseItem[];
|
||||
}
|
||||
|
||||
export interface OpenCaseResponse {
|
||||
status: string;
|
||||
message: string;
|
||||
operation_id: string;
|
||||
balance: number;
|
||||
reward: CaseItem;
|
||||
}
|
||||
|
||||
// ===== КЕЙСЫ =====
|
||||
|
||||
export async function fetchCases(): Promise<Case[]> {
|
||||
const response = await fetch(`${API_BASE_URL}/cases`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить список кейсов');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
// Если у тебя есть отдельный эндпоинт деталей кейса, можно использовать это:
|
||||
export async function fetchCase(case_id: string): Promise<Case> {
|
||||
const response = await fetch(`${API_BASE_URL}/cases/${case_id}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить информацию о кейсе');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function openCase(
|
||||
case_id: string,
|
||||
username: string,
|
||||
server_id: string,
|
||||
): Promise<OpenCaseResponse> {
|
||||
// Формируем URL с query-параметрами, как любит текущий бэкенд
|
||||
const url = new URL(`${API_BASE_URL}/cases/${case_id}/open`);
|
||||
url.searchParams.append('username', username);
|
||||
url.searchParams.append('server_id', server_id);
|
||||
|
||||
const response = await fetch(url.toString(), {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let msg = 'Не удалось открыть кейс';
|
||||
|
||||
try {
|
||||
const errorData = await response.json();
|
||||
if (errorData.message) {
|
||||
msg = errorData.message;
|
||||
} else if (Array.isArray(errorData.detail)) {
|
||||
msg = errorData.detail.map((d: any) => d.msg).join(', ');
|
||||
} else if (typeof errorData.detail === 'string') {
|
||||
msg = errorData.detail;
|
||||
}
|
||||
} catch {
|
||||
// если бэкенд вернул не-JSON, оставляем дефолтное сообщение
|
||||
}
|
||||
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function fetchMe(): Promise<MeResponse> {
|
||||
const { accessToken, clientToken } = getAuthTokens();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user