52 lines
1.0 KiB
TypeScript
52 lines
1.0 KiB
TypeScript
import axios from 'axios'
|
|
import router from '@/router'
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api/v1',
|
|
timeout: 30000,
|
|
})
|
|
|
|
api.interceptors.request.use((config) => {
|
|
const token = localStorage.getItem('app_token')
|
|
if (token && token !== 'disabled') {
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
}
|
|
return config
|
|
})
|
|
|
|
api.interceptors.response.use(
|
|
(res) => res,
|
|
(err) => {
|
|
if (err.response?.status === 401 && err.config?.url !== '/auth/login') {
|
|
localStorage.removeItem('app_token')
|
|
if (!router.currentRoute.value.path.startsWith('/admin/login')) {
|
|
router.push('/admin/login')
|
|
}
|
|
}
|
|
return Promise.reject(err)
|
|
},
|
|
)
|
|
|
|
export default api
|
|
|
|
export interface DashboardData {
|
|
app_name: string
|
|
data_dir: string
|
|
}
|
|
|
|
export interface SettingsData {
|
|
app_name: string
|
|
api_port: string
|
|
admin_password: string
|
|
auth_enabled: string
|
|
ui_locale: string
|
|
}
|
|
|
|
export interface AuditLog {
|
|
id: number
|
|
action: string
|
|
resource: string
|
|
detail: string
|
|
created_at: string
|
|
}
|