add commands tab in shop
This commit is contained in:
59
src/renderer/api/commands.ts
Normal file
59
src/renderer/api/commands.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import { API_BASE_URL } from '../api';
|
||||
|
||||
export interface PrankCommand {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
price: number;
|
||||
command_template: string;
|
||||
server_ids: string[]; // ["*"] или конкретные id
|
||||
targetDescription: string;
|
||||
globalDescription: string;
|
||||
}
|
||||
|
||||
export interface PrankServer {
|
||||
id: string;
|
||||
name: string;
|
||||
ip: string;
|
||||
online_players: number;
|
||||
max_players: number;
|
||||
}
|
||||
|
||||
export const fetchPrankCommands = async (): Promise<PrankCommand[]> => {
|
||||
const res = await fetch(`${API_BASE_URL}/api/pranks/commands`);
|
||||
if (!res.ok) throw new Error('Failed to load prank commands');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const fetchPrankServers = async (): Promise<PrankServer[]> => {
|
||||
const res = await fetch(`${API_BASE_URL}/api/pranks/servers`);
|
||||
if (!res.ok) throw new Error('Failed to load prank servers');
|
||||
return res.json();
|
||||
};
|
||||
|
||||
export const executePrank = async (
|
||||
username: string,
|
||||
commandId: string,
|
||||
targetPlayer: string,
|
||||
serverId: string,
|
||||
) => {
|
||||
const res = await fetch(
|
||||
`${API_BASE_URL}/api/pranks/execute?username=${username}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
command_id: commandId,
|
||||
target_player: targetPlayer,
|
||||
server_id: serverId,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!res.ok) {
|
||||
const err = await res.text();
|
||||
throw new Error(err);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user