feat: add Vue 3 admin frontend and integrate with backend like mediabot
This commit is contained in:
49
web/src/api/index.js
Normal file
49
web/src/api/index.js
Normal file
@@ -0,0 +1,49 @@
|
||||
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')
|
||||
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'),
|
||||
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 } })
|
||||
},
|
||||
health: () => api.get('/health', { baseURL: '' })
|
||||
}
|
||||
Reference in New Issue
Block a user