2022-01-22 13:35:11 +00:00
|
|
|
import client from "../queries/client";
|
2021-03-25 14:22:43 +00:00
|
|
|
|
|
|
|
type UrlTestResponse =
|
|
|
|
| {
|
|
|
|
status: true;
|
|
|
|
version: string;
|
|
|
|
}
|
|
|
|
| {
|
|
|
|
status: false;
|
|
|
|
error: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RequestUtils {
|
2022-03-16 06:26:15 +00:00
|
|
|
async urlTest(protocol: string, url: string, params?: LooseObject) {
|
2021-06-02 02:02:02 +00:00
|
|
|
try {
|
2022-01-22 13:35:11 +00:00
|
|
|
const result = await client.axios.get<UrlTestResponse>(
|
2021-06-02 02:02:02 +00:00
|
|
|
`../test/${protocol}/${url}api/system/status`,
|
|
|
|
{ params }
|
|
|
|
);
|
|
|
|
const { data } = result;
|
|
|
|
if (data.status && data.version) {
|
|
|
|
return data;
|
|
|
|
} else {
|
|
|
|
throw new Error("Cannot get response, fallback to v3 api");
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-01-22 13:35:11 +00:00
|
|
|
const result = await client.axios.get<UrlTestResponse>(
|
2021-06-02 02:02:02 +00:00
|
|
|
`../test/${protocol}/${url}api/v3/system/status`,
|
|
|
|
{ params }
|
|
|
|
);
|
|
|
|
return result.data;
|
|
|
|
}
|
2021-03-25 14:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new RequestUtils();
|