mirror of
https://github.com/HangarMC/Hangar.git
synced 2025-03-07 15:31:00 +08:00
fix(frontend): bump timeout for some calls (closes #1075)
This commit is contained in:
parent
157b8a6b83
commit
834a15d067
@ -1,13 +1,13 @@
|
||||
import type { AxiosError, AxiosRequestConfig } from "axios";
|
||||
import qs from "qs";
|
||||
import Cookies from "universal-cookie";
|
||||
import { isEmpty } from "lodash-es";
|
||||
import type { Ref } from "vue";
|
||||
import { useCookies } from "~/composables/useCookies";
|
||||
import { authLog, fetchLog } from "~/lib/composables/useLog";
|
||||
import { useAxios } from "~/composables/useAxios";
|
||||
|
||||
function request<T>(url: string, method: AxiosRequestConfig["method"], data: object): Promise<T> {
|
||||
type FilteredAxiosConfig = Omit<AxiosRequestConfig, "method" | "url" | "data" | "params" | "baseURL">;
|
||||
|
||||
function request<T>(url: string, method: AxiosRequestConfig["method"], data: object, axiosOptions: FilteredAxiosConfig = {}): Promise<T> {
|
||||
const cookies = useCookies();
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
return useAxios()
|
||||
@ -16,6 +16,7 @@ function request<T>(url: string, method: AxiosRequestConfig["method"], data: obj
|
||||
url: `/api/${url}`,
|
||||
data: method?.toLowerCase() !== "get" ? data : {},
|
||||
params: method?.toLowerCase() === "get" ? data : {},
|
||||
...axiosOptions,
|
||||
paramsSerializer: (params) => {
|
||||
return qs.stringify(params, {
|
||||
arrayFormat: "repeat",
|
||||
@ -44,12 +45,17 @@ function request<T>(url: string, method: AxiosRequestConfig["method"], data: obj
|
||||
});
|
||||
}
|
||||
|
||||
export function useApi<T>(url: string, method: AxiosRequestConfig["method"] = "get", data: object = {}): Promise<T> {
|
||||
export function useApi<T>(url: string, method: AxiosRequestConfig["method"] = "get", data: object = {}, axiosOptions: FilteredAxiosConfig = {}): Promise<T> {
|
||||
fetchLog("useApi", url, data);
|
||||
return request(`v1/${url}`, method, data);
|
||||
return request(`v1/${url}`, method, data, axiosOptions);
|
||||
}
|
||||
|
||||
export function useInternalApi<T = void>(url: string, method: AxiosRequestConfig["method"] = "get", data: object = {}): Promise<T> {
|
||||
export function useInternalApi<T = void>(
|
||||
url: string,
|
||||
method: AxiosRequestConfig["method"] = "get",
|
||||
data: object = {},
|
||||
axiosOptions: FilteredAxiosConfig = {}
|
||||
): Promise<T> {
|
||||
fetchLog("useInternalApi", url, data);
|
||||
return request(`internal/${url}`, method, data);
|
||||
return request(`internal/${url}`, method, data, axiosOptions);
|
||||
}
|
||||
|
@ -227,8 +227,8 @@ async function createPendingVersion() {
|
||||
})
|
||||
);
|
||||
|
||||
pendingVersion.value = await useInternalApi<PendingVersion>(`versions/version/${props.project.id}/upload`, "post", formData).catch<any>((e) =>
|
||||
handleRequestError(e)
|
||||
pendingVersion.value = await useInternalApi<PendingVersion>(`versions/version/${props.project.id}/upload`, "post", formData, { timeout: 10000 }).catch<any>(
|
||||
(e) => handleRequestError(e)
|
||||
);
|
||||
loading.create = false;
|
||||
|
||||
@ -271,7 +271,7 @@ async function createVersion() {
|
||||
}
|
||||
|
||||
try {
|
||||
await useInternalApi(`versions/version/${props.project.id}/create`, "post", pendingVersion.value);
|
||||
await useInternalApi(`versions/version/${props.project.id}/create`, "post", pendingVersion.value, { timeout: 10000 });
|
||||
await router.push(`/${route.params.user}/${route.params.project}/versions`);
|
||||
} catch (e: any) {
|
||||
handleRequestError(e);
|
||||
|
Loading…
Reference in New Issue
Block a user