add: capes switch in user profile
This commit is contained in:
@ -19,6 +19,17 @@ export interface CoinsResponse {
|
||||
};
|
||||
}
|
||||
|
||||
export interface Cape {
|
||||
cape_id: string;
|
||||
cape_name: string;
|
||||
cape_description: string;
|
||||
image_url: string;
|
||||
purchased_at: string;
|
||||
is_active: boolean;
|
||||
}
|
||||
|
||||
export type CapesResponse = Cape[];
|
||||
|
||||
export interface ApiError {
|
||||
message: string;
|
||||
details?: string;
|
||||
@ -55,6 +66,63 @@ export async function fetchCoins(username: string): Promise<CoinsResponse> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchCapes(username: string): Promise<CapesResponse> {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/store/user/${username}/capes`,
|
||||
);
|
||||
if (!response.ok) {
|
||||
return []; // Если плащи не найдены, возвращаем пустой массив
|
||||
}
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error('API ошибка:', error);
|
||||
return []; // В случае ошибки возвращаем пустой массив
|
||||
}
|
||||
}
|
||||
|
||||
export async function activateCape(
|
||||
username: string,
|
||||
cape_id: string,
|
||||
): Promise<void> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/store/user/${username}/capes/activate/${cape_id}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
cape_id: cape_id,
|
||||
}),
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось активировать плащ');
|
||||
}
|
||||
}
|
||||
|
||||
export async function deactivateCape(
|
||||
username: string,
|
||||
cape_id: string,
|
||||
): Promise<void> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/store/user/${username}/capes/deactivate/${cape_id}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
cape_id: cape_id,
|
||||
}),
|
||||
},
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось деактивировать плащ');
|
||||
}
|
||||
}
|
||||
|
||||
// Загрузка скина
|
||||
export async function uploadSkin(
|
||||
username: string,
|
||||
|
Reference in New Issue
Block a user