Files
sbd2-frontend/src/lib/api/config.ts
JSC 6ce83c8317 Refactor API structure and integrate new modular API client
- Replaced legacy apiService with a new modular api client structure.
- Updated AuthContext, OAuthButtons, and AuthCallbackPage to use the new api client.
- Created separate services for auth, sounds, playlists, and users.
- Implemented centralized API configuration and error handling.
- Added support for OAuth providers and token exchange.
- Introduced a Toaster component for notifications in App.
- Updated API endpoints and request handling for better maintainability.
2025-07-26 19:21:36 +02:00

44 lines
1.5 KiB
TypeScript

// API Configuration
export const API_CONFIG = {
BASE_URL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000',
TIMEOUT: 30000, // 30 seconds
RETRY_ATTEMPTS: 1,
// API Endpoints
ENDPOINTS: {
AUTH: {
LOGIN: '/api/v1/auth/login',
REGISTER: '/api/v1/auth/register',
LOGOUT: '/api/v1/auth/logout',
REFRESH: '/api/v1/auth/refresh',
ME: '/api/v1/auth/me',
PROVIDERS: '/api/v1/auth/providers',
OAUTH_AUTHORIZE: (provider: string) => `/api/v1/auth/${provider}/authorize`,
OAUTH_CALLBACK: (provider: string) => `/api/v1/auth/${provider}/callback`,
EXCHANGE_OAUTH_TOKEN: '/api/v1/auth/exchange-oauth-token',
},
SOUNDS: {
LIST: '/api/v1/sounds',
CREATE: '/api/v1/sounds',
GET: (id: string | number) => `/api/v1/sounds/${id}`,
UPDATE: (id: string | number) => `/api/v1/sounds/${id}`,
DELETE: (id: string | number) => `/api/v1/sounds/${id}`,
UPLOAD: '/api/v1/sounds/upload',
},
PLAYLISTS: {
LIST: '/api/v1/playlists',
CREATE: '/api/v1/playlists',
GET: (id: string | number) => `/api/v1/playlists/${id}`,
UPDATE: (id: string | number) => `/api/v1/playlists/${id}`,
DELETE: (id: string | number) => `/api/v1/playlists/${id}`,
},
USERS: {
LIST: '/api/v1/users',
GET: (id: string | number) => `/api/v1/users/${id}`,
UPDATE: (id: string | number) => `/api/v1/users/${id}`,
DELETE: (id: string | number) => `/api/v1/users/${id}`,
},
},
} as const
export type ApiEndpoints = typeof API_CONFIG.ENDPOINTS