Aethel Bot OSS repository!
aethel.xyz
bot
fun
ai
discord
discord-bot
aethel
1import axios from 'axios';
2import { toast } from 'sonner';
3
4const api = axios.create({
5 baseURL: `${import.meta.env.VITE_FRONTEND_URL}/api`,
6 timeout: 10000,
7});
8
9api.interceptors.request.use(
10 (config) => {
11 const token = localStorage.getItem('token');
12 if (token) {
13 config.headers.Authorization = `Bearer ${token}`;
14 }
15 return config;
16 },
17 (error) => {
18 return Promise.reject(error);
19 },
20);
21
22api.interceptors.response.use(
23 (response) => response,
24 (error) => {
25 if (error.response?.status === 401) {
26 localStorage.removeItem('token');
27 window.location.href = '/';
28 toast.error('Session expired. Please login again.');
29 } else if (error.response?.status >= 500) {
30 toast.error('Server error. Please try again later.');
31 } else if (error.response?.data?.message) {
32 toast.error(error.response.data.message);
33 } else {
34 toast.error('An unexpected error occurred.');
35 }
36 return Promise.reject(error);
37 },
38);
39
40export default api;
41
42export const authAPI = {
43 getDiscordAuthUrl: () => api.get('/auth/discord'),
44 getMe: () => api.get('/auth/me'),
45 logout: () => api.post('/auth/logout'),
46};
47
48export const todosAPI = {
49 getTodos: () => api.get('/todos'),
50 createTodo: (data: { item: string }) => api.post('/todos', data),
51 updateTodo: (id: number, data: { item?: string; done?: boolean }) =>
52 api.put(`/todos/${id}`, data),
53 deleteTodo: (id: number) => api.delete(`/todos/${id}`),
54 clearTodos: () => api.delete('/todos'),
55};
56
57export const apiKeysAPI = {
58 getApiKeys: () => api.get('/user/api-keys'),
59 updateApiKey: (data: { apiKey?: string; model?: string; apiUrl?: string }) =>
60 api.post('/user/api-keys', data),
61 deleteApiKey: () => api.delete('/user/api-keys'),
62 testApiKey: (data: { apiKey: string; model?: string; apiUrl?: string }) =>
63 api.post('/user/api-keys/test', data),
64};
65
66export const remindersAPI = {
67 getReminders: () => api.get('/reminders'),
68 createReminder: (data: { message: string; expires_at: string }) => api.post('/reminders', data),
69 getReminder: (id: string) => api.get(`/reminders/${id}`),
70 completeReminder: (id: string) => api.patch(`/reminders/${id}/complete`),
71 getActiveReminders: () => api.get('/reminders/active/all'),
72 clearCompletedReminders: () => api.delete('/reminders/completed'),
73};