Nightly: Kategorien eingeführt Persistenz (state.json), API (CRUD + Bulk-Assign), Sounds-Filter unterstützt categoryId

This commit is contained in:
vibe-bot 2025-08-09 17:16:37 +02:00
parent b11e7dd666
commit 3d1a6ca60b
3 changed files with 131 additions and 7 deletions

View file

@ -2,15 +2,41 @@ import type { Sound, SoundsResponse, VoiceChannelInfo } from './types';
const API_BASE = import.meta.env.VITE_API_BASE_URL || '/api';
export async function fetchSounds(q?: string, folderKey?: string): Promise<SoundsResponse> {
export async function fetchSounds(q?: string, folderKey?: string, categoryId?: string): Promise<SoundsResponse> {
const url = new URL(`${API_BASE}/sounds`, window.location.origin);
if (q) url.searchParams.set('q', q);
if (folderKey !== undefined) url.searchParams.set('folder', folderKey);
if (categoryId) url.searchParams.set('categoryId', categoryId);
const res = await fetch(url.toString());
if (!res.ok) throw new Error('Fehler beim Laden der Sounds');
return res.json();
}
// Kategorien
export async function fetchCategories() {
const res = await fetch(`${API_BASE}/categories`, { credentials: 'include' });
if (!res.ok) throw new Error('Fehler beim Laden der Kategorien');
return res.json();
}
export async function createCategory(name: string, color?: string) {
const res = await fetch(`${API_BASE}/categories`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include',
body: JSON.stringify({ name, color })
});
if (!res.ok) throw new Error('Kategorie anlegen fehlgeschlagen');
return res.json();
}
export async function assignCategories(files: string[], add: string[], remove: string[] = []) {
const res = await fetch(`${API_BASE}/categories/assign`, {
method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include',
body: JSON.stringify({ files, add, remove })
});
if (!res.ok) throw new Error('Zuordnung fehlgeschlagen');
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');