Nightly: Kategorien eingeführt Persistenz (state.json), API (CRUD + Bulk-Assign), Sounds-Filter unterstützt categoryId
This commit is contained in:
parent
b11e7dd666
commit
3d1a6ca60b
3 changed files with 131 additions and 7 deletions
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ export type SoundsResponse = {
|
|||
items: Sound[];
|
||||
total: number;
|
||||
folders: Array<{ key: string; name: string; count: number }>;
|
||||
categories?: Category[];
|
||||
fileCategories?: Record<string, string[]>;
|
||||
};
|
||||
|
||||
export type VoiceChannelInfo = {
|
||||
|
|
@ -19,6 +21,8 @@ export type VoiceChannelInfo = {
|
|||
channelName: string;
|
||||
};
|
||||
|
||||
export type Category = { id: string; name: string; color?: string; sort?: number };
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue