2025-08-07 23:24:56 +02:00
|
|
|
import type { Sound, VoiceChannelInfo } from './types';
|
|
|
|
|
|
|
|
|
|
const API_BASE = import.meta.env.VITE_API_BASE_URL || '/api';
|
|
|
|
|
|
|
|
|
|
export async function fetchSounds(q?: string): Promise<Sound[]> {
|
|
|
|
|
const url = new URL(`${API_BASE}/sounds`, window.location.origin);
|
|
|
|
|
if (q) url.searchParams.set('q', q);
|
|
|
|
|
const res = await fetch(url.toString());
|
|
|
|
|
if (!res.ok) throw new Error('Fehler beim Laden der Sounds');
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function fetchChannels(): Promise<VoiceChannelInfo[]> {
|
|
|
|
|
const res = await fetch(`${API_BASE}/channels`);
|
|
|
|
|
if (!res.ok) throw new Error('Fehler beim Laden der Channels');
|
|
|
|
|
return res.json();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-08 01:23:52 +02:00
|
|
|
export async function playSound(soundName: string, guildId: string, channelId: string, volume: number): Promise<void> {
|
2025-08-07 23:24:56 +02:00
|
|
|
const res = await fetch(`${API_BASE}/play`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
2025-08-08 01:23:52 +02:00
|
|
|
body: JSON.stringify({ soundName, guildId, channelId, volume })
|
2025-08-07 23:24:56 +02:00
|
|
|
});
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const data = await res.json().catch(() => ({}));
|
|
|
|
|
throw new Error(data?.error || 'Play fehlgeschlagen');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|