Skip to content

Commit

Permalink
add long http
Browse files Browse the repository at this point in the history
  • Loading branch information
mingchiuli committed Jan 14, 2025
1 parent 7ea7ed2 commit 7368321
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/http/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { loginStateStore } from '@/stores/store'

const http = axios.create({
baseURL: import.meta.env.VITE_BASE_URL,
timeout: 20000
timeout: 10000
})

const longHttp = axios.create({
baseURL: import.meta.env.VITE_BASE_URL
})

const requestInterceptor = async (config: any) => {
Expand Down Expand Up @@ -50,5 +54,7 @@ const errorInterceptor = (error: AxiosError<any, any>) => {

http.interceptors.request.use(requestInterceptor)
http.interceptors.response.use(responseInterceptor, errorInterceptor)
longHttp.interceptors.request.use(requestInterceptor)
longHttp.interceptors.response.use(responseInterceptor, errorInterceptor)

export default http
export default { http, longHttp }
10 changes: 5 additions & 5 deletions src/http/http.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import http from '@/http/axios'
import client from '@/http/axios'
import type { Data } from '@/type/entity'
import type { AxiosProgressEvent } from 'axios'
import { type Ref } from 'vue'

const GET = async <T>(url: string): Promise<T> => {
return Promise.resolve((await http.get<never, Data<T>>(url)).data)
return Promise.resolve((await client.http.get<never, Data<T>>(url)).data)
}

const POST = async <T>(url: string, params: any): Promise<T> => {
return Promise.resolve((await http.post<never, Data<T>>(url, params)).data)
return Promise.resolve((await client.http.post<never, Data<T>>(url, params)).data)
}

const handleProgress = (
Expand All @@ -28,7 +28,7 @@ const DOWNLOAD_DATA = async (
let data: any
percentageShow.value = true
percentage.value = 0
await http
await client.longHttp
.get(url, {
onDownloadProgress: (progressEvent) =>
handleProgress(percentage, percentageShow, progressEvent)
Expand Down Expand Up @@ -57,7 +57,7 @@ const UPLOAD = async (
percentageShow.value = true
percentage.value = 0
let url = ''
await http
await client.longHttp
.post(dest, formData, {
onUploadProgress: (progressEvent) => handleProgress(percentage, percentageShow, progressEvent)
})
Expand Down

0 comments on commit 7368321

Please sign in to comment.