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.
This commit is contained in:
44
src/lib/api/config.ts
Normal file
44
src/lib/api/config.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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
|
||||
Reference in New Issue
Block a user