-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
209 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { WoxMessageHelper } from "../utils/WoxMessageHelper.ts" | ||
import WoxRequest from "../utils/WoxRequest.ts" | ||
import { Theme } from "../entity/Theme.typings" | ||
|
||
export async function getTheme() { | ||
return WoxRequest.post<Theme>(`http://localhost:${WoxMessageHelper.getInstance().getPort()}/theme`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,4 +180,9 @@ export class WoxMessageHelper { | |
} | ||
} | ||
|
||
public getPort() { | ||
return this.port | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from "axios" | ||
import axios from "axios" | ||
|
||
type Result<T> = { | ||
code: number; | ||
message: string; | ||
result: T; | ||
}; | ||
|
||
export class Request { | ||
instance: AxiosInstance | ||
baseConfig: AxiosRequestConfig = { timeout: 60000 } | ||
|
||
constructor(config: AxiosRequestConfig) { | ||
this.instance = axios.create(Object.assign(this.baseConfig, config)) | ||
|
||
this.instance.interceptors.response.use( | ||
(res: AxiosResponse) => { | ||
return res.data | ||
}, | ||
(err: any) => { | ||
switch (err.response.status) { | ||
case 400: | ||
break | ||
case 401: | ||
break | ||
case 403: | ||
break | ||
case 404: | ||
break | ||
case 408: | ||
break | ||
case 500: | ||
break | ||
case 501: | ||
break | ||
case 502: | ||
break | ||
case 503: | ||
break | ||
case 504: | ||
break | ||
case 505: | ||
break | ||
default: | ||
} | ||
return Promise.reject(err.response.data) | ||
} | ||
) | ||
} | ||
|
||
public request(config: AxiosRequestConfig): Promise<AxiosResponse> { | ||
return this.instance.request(config) | ||
} | ||
|
||
public get<T = any>( | ||
url: string, | ||
config?: AxiosRequestConfig | ||
): Promise<AxiosResponse<Result<T>>> { | ||
return this.instance.get(url, config) | ||
} | ||
|
||
public post<T = any>( | ||
url: string, | ||
data?: any, | ||
config?: AxiosRequestConfig | ||
): Promise<AxiosResponse<Result<T>>> { | ||
return this.instance.post(url, data, config) | ||
} | ||
|
||
public put<T = any>( | ||
url: string, | ||
data?: any, | ||
config?: AxiosRequestConfig | ||
): Promise<AxiosResponse<Result<T>>> { | ||
return this.instance.put(url, data, config) | ||
} | ||
|
||
public delete<T = any>( | ||
url: string, | ||
config?: AxiosRequestConfig | ||
): Promise<AxiosResponse<Result<T>>> { | ||
return this.instance.delete(url, config) | ||
} | ||
} | ||
|
||
export default new Request({}) |