add: marketplace
This commit is contained in:
@ -60,15 +60,6 @@ export interface ActiveServersResponse {
|
||||
servers: Server[];
|
||||
}
|
||||
|
||||
// Исправьте тип возвращаемого значения
|
||||
export async function fetchActiveServers(): Promise<Server[]> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/pranks/servers`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить активные сервера');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export interface OnlinePlayersResponse {
|
||||
server: {
|
||||
id: string;
|
||||
@ -83,6 +74,284 @@ export interface OnlinePlayersResponse {
|
||||
count: number;
|
||||
}
|
||||
|
||||
export interface MarketplaceResponse {
|
||||
items: [
|
||||
{
|
||||
_id: string;
|
||||
id: string;
|
||||
material: string;
|
||||
amount: number;
|
||||
price: number;
|
||||
seller_name: string;
|
||||
server_ip: string;
|
||||
display_name: string | null;
|
||||
lore: string | null;
|
||||
enchants: string | null;
|
||||
item_data: {
|
||||
slot: number;
|
||||
material: string;
|
||||
amount: number;
|
||||
};
|
||||
created_at: string;
|
||||
},
|
||||
];
|
||||
total: number;
|
||||
page: number;
|
||||
pages: number;
|
||||
}
|
||||
|
||||
export interface MarketplaceItemResponse {
|
||||
_id: string;
|
||||
id: string;
|
||||
material: string;
|
||||
amount: number;
|
||||
price: number;
|
||||
seller_name: string;
|
||||
server_ip: string;
|
||||
display_name: string | null;
|
||||
lore: string | null;
|
||||
enchants: string | null;
|
||||
item_data: {
|
||||
slot: number;
|
||||
material: string;
|
||||
amount: number;
|
||||
};
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface SellItemResponse {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface BuyItemResponse {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface PlayerInventoryResponse {
|
||||
status: string;
|
||||
request_id: string;
|
||||
}
|
||||
|
||||
export interface PlayerInventory {
|
||||
status: string;
|
||||
result: {
|
||||
player_name: string;
|
||||
server_ip: string;
|
||||
inventory_data: PlayerInventoryItem[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface PlayerInventoryItem {
|
||||
slot: number;
|
||||
material: string;
|
||||
amount: number;
|
||||
enchants: {
|
||||
[key: string]: number;
|
||||
};
|
||||
}
|
||||
|
||||
export interface MarketplaceOperation {
|
||||
id: string;
|
||||
type: 'sell' | 'buy';
|
||||
player_name: string;
|
||||
slot_index?: number;
|
||||
amount?: number;
|
||||
price: number;
|
||||
server_ip: string;
|
||||
status: 'pending' | 'completed' | 'failed';
|
||||
item_id?: string;
|
||||
error?: string;
|
||||
created_at: string;
|
||||
item_data?: any;
|
||||
}
|
||||
|
||||
export interface OperationsResponse {
|
||||
operations: MarketplaceOperation[];
|
||||
}
|
||||
|
||||
export async function getPlayerInventory(
|
||||
request_id: string,
|
||||
): Promise<PlayerInventory> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/api/server/inventory/${request_id}`,
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить инвентарь игрока');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function RequestPlayerInventory(
|
||||
server_ip: string,
|
||||
player_name: string,
|
||||
): Promise<PlayerInventoryResponse> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/server/inventory`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
server_ip: server_ip,
|
||||
player_name: player_name,
|
||||
}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить инвентарь игрока');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function buyItem(
|
||||
buyer_username: string,
|
||||
item_id: string,
|
||||
): Promise<{ status: string; operation_id: string; message: string }> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/api/marketplace/items/buy/${item_id}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username: buyer_username,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(
|
||||
errorData.message || errorData.detail || 'Не удалось купить предмет',
|
||||
);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function confirmMarketplaceOperation(
|
||||
operation_id: string,
|
||||
status: string = 'success',
|
||||
error?: string,
|
||||
): Promise<{ status: string }> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/api/marketplace/operations/confirm`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_id,
|
||||
status,
|
||||
error,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось подтвердить операцию');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function submitItemDetails(
|
||||
operation_id: string,
|
||||
item_data: any,
|
||||
): Promise<{ status: string }> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/api/marketplace/items/details`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
operation_id,
|
||||
item_data,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось отправить данные предмета');
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function sellItem(
|
||||
username: string,
|
||||
slot_index: number,
|
||||
amount: number,
|
||||
price: number,
|
||||
server_ip: string,
|
||||
): Promise<{ status: string; operation_id: string }> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/marketplace/items/sell`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username,
|
||||
slot_index,
|
||||
amount,
|
||||
price,
|
||||
server_ip,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json();
|
||||
throw new Error(
|
||||
errorData.message ||
|
||||
errorData.detail ||
|
||||
'Не удалось выставить предмет на продажу',
|
||||
);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function fetchMarketplaceItem(
|
||||
item_id: string,
|
||||
): Promise<MarketplaceItemResponse> {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/api/marketplace/items/${item_id}`,
|
||||
);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить рынок');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function fetchMarketplace(
|
||||
server_ip: string,
|
||||
page: number,
|
||||
limit: number,
|
||||
): Promise<MarketplaceResponse> {
|
||||
// Создаем URL с параметрами запроса
|
||||
const url = new URL(`${API_BASE_URL}/api/marketplace/items`);
|
||||
url.searchParams.append('server_ip', server_ip);
|
||||
url.searchParams.append('page', page.toString());
|
||||
url.searchParams.append('limit', limit.toString());
|
||||
|
||||
const response = await fetch(url.toString());
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить предметы рынка');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
// Исправьте тип возвращаемого значения
|
||||
export async function fetchActiveServers(): Promise<Server[]> {
|
||||
const response = await fetch(`${API_BASE_URL}/api/pranks/servers`);
|
||||
if (!response.ok) {
|
||||
throw new Error('Не удалось получить активные сервера');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export async function fetchOnlinePlayers(
|
||||
server_id: string,
|
||||
): Promise<OnlinePlayersResponse> {
|
||||
|
Reference in New Issue
Block a user