You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.6 KiB
77 lines
1.6 KiB
|
1 week ago
|
import axios from 'axios'
|
||
|
|
|
||
|
|
const instance = axios.create({
|
||
|
|
baseURL: '/api',
|
||
|
|
timeout: 10000,
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'application/json'
|
||
|
|
}
|
||
|
|
})
|
||
|
|
|
||
|
|
instance.interceptors.request.use(
|
||
|
|
(config) => {
|
||
|
|
const token = localStorage.getItem('auth_token')
|
||
|
|
if (token) {
|
||
|
|
config.headers.Authorization = `Bearer ${token}`
|
||
|
|
}
|
||
|
|
return config
|
||
|
|
},
|
||
|
|
(error) => Promise.reject(error)
|
||
|
|
)
|
||
|
|
|
||
|
|
instance.interceptors.response.use(
|
||
|
|
(response) => response.data,
|
||
|
|
(error) => {
|
||
|
|
if (error.response?.status === 401) {
|
||
|
|
localStorage.removeItem('auth_token')
|
||
|
|
localStorage.removeItem('user')
|
||
|
|
window.location.href = '/login'
|
||
|
|
}
|
||
|
|
return Promise.reject(error.response?.data || error.message)
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
export interface ScrapDto {
|
||
|
|
id: number
|
||
|
|
name: string
|
||
|
|
description: string
|
||
|
|
story: string
|
||
|
|
level: number
|
||
|
|
levelName: string
|
||
|
|
levelColor: string
|
||
|
|
attackBonus: number
|
||
|
|
defenseBonus: number
|
||
|
|
hpBonus: number
|
||
|
|
magicBonus: number
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ScrapScanResultDto {
|
||
|
|
scrap: ScrapDto
|
||
|
|
attackGain: number
|
||
|
|
defenseGain: number
|
||
|
|
hpGain: number
|
||
|
|
magicGain: number
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ScrapHistoryDto {
|
||
|
|
id: number
|
||
|
|
scrap: ScrapDto
|
||
|
|
obtainedAt: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export const scrapApi = {
|
||
|
|
getScrapList: (): Promise<ScrapDto[]> => {
|
||
|
|
return instance.get('/scrap/list')
|
||
|
|
},
|
||
|
|
|
||
|
|
scanScrap: (characterId: number): Promise<ScrapScanResultDto> => {
|
||
|
|
return instance.post('/scrap/scan', { characterId })
|
||
|
|
},
|
||
|
|
|
||
|
|
getScrapHistory: (characterId: number): Promise<ScrapHistoryDto[]> => {
|
||
|
|
return instance.get(`/scrap/history/${characterId}`)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export default instance
|