59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import axios from 'axios'
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api/v1',
|
|
timeout: 30000
|
|
})
|
|
|
|
api.interceptors.request.use(config => {
|
|
const token = localStorage.getItem('par_token')
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
}
|
|
return config
|
|
})
|
|
|
|
api.interceptors.response.use(
|
|
response => response.data,
|
|
error => {
|
|
if (error.response?.status === 401) {
|
|
localStorage.removeItem('par_token')
|
|
localStorage.removeItem('par_user')
|
|
window.location.href = '/login'
|
|
}
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
export default {
|
|
auth: {
|
|
login: (data) => api.post('/auth/login', data),
|
|
register: (data) => api.post('/auth/register', data)
|
|
},
|
|
sites: {
|
|
list: () => api.get('/sites'),
|
|
get: (id) => api.get(`/sites/${id}`),
|
|
create: (data) => api.post('/sites', data),
|
|
update: (id, data) => api.put(`/sites/${id}`, data)
|
|
},
|
|
configs: {
|
|
list: () => api.get('/configs'),
|
|
pending: () => api.get('/configs/pending'),
|
|
bySite: (siteId) => api.get(`/configs/${siteId}`),
|
|
download: (siteId, version) => api.get(`/configs/${siteId}/${version}`),
|
|
content: (siteId, version) => api.get(`/configs/${siteId}/${version}/content`),
|
|
approve: (id, comment) => api.post(`/admin/reviews/${id}/approve`, null, { params: { comment } }),
|
|
reject: (id, comment) => api.post(`/admin/reviews/${id}/reject`, null, { params: { comment } })
|
|
},
|
|
users: {
|
|
list: () => api.get('/admin/accounts'),
|
|
setTrustLevel: (id, level) => api.post(`/admin/accounts/${id}/trust-level`, null, { params: { level } }),
|
|
},
|
|
psks: {
|
|
list: () => api.get('/admin/psks'),
|
|
add: (data) => api.post('/admin/psks', data),
|
|
toggle: (id) => api.post(`/admin/psks/${id}/toggle`)
|
|
},
|
|
health: () => api.get('/health', { baseURL: '' })
|
|
}
|