diff --git a/app/src/api/api.ts b/app/src/api/api.ts index 4e34c2303..4f36576a4 100644 --- a/app/src/api/api.ts +++ b/app/src/api/api.ts @@ -2,15 +2,10 @@ import { v4 as uuid } from 'uuid' import { useCache, type StorePath } from '@/composables/data' import { useInfos } from '@/composables/useInfos' -import { useRequests, type ReconnectingArgs } from '@/composables/useRequests' +import { useRequests } from '@/composables/useRequests' import { useSettings } from '@/composables/useSettings' import type { Obj } from '@/types/commons' -import { - APIBadRequestError, - APIErrorLog, - APIUnauthorizedError, - type APIError, -} from './errors' +import { APIBadRequestError, APIErrorLog, APIUnauthorizedError } from './errors' import { getError, getResponseData } from './handlers' export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' @@ -240,39 +235,4 @@ export default { const { updateRouterKey } = useInfos() updateRouterKey() }, - - /** - * Api reconnection helper. Resolve when server is reachable or fail after n attemps - * - * @param attemps - Number of attemps before rejecting - * @param delay - Delay between calls to the API in ms - * @param initialDelay - Delay before calling the API for the first time in ms - * - * @returns Promise that resolve yunohost version infos - * @throws Throw an `APIError` or subclass depending on server response - */ - tryToReconnect({ - attemps = 5, - delay = 2000, - initialDelay = 0, - }: ReconnectingArgs = {}) { - const { getYunoHostVersion } = useInfos() - return new Promise((resolve, reject) => { - function reconnect(n: number) { - getYunoHostVersion() - .then(resolve) - .catch((err: APIError) => { - if (err instanceof APIUnauthorizedError) { - reject(err) - } else if (n < 1) { - reject(err) - } else { - setTimeout(() => reconnect(n - 1), delay) - } - }) - } - if (initialDelay > 0) setTimeout(() => reconnect(attemps), initialDelay) - else reconnect(attemps) - }) - }, } diff --git a/app/src/composables/useInfos.ts b/app/src/composables/useInfos.ts index 7dcbde99b..1cc4c24ee 100644 --- a/app/src/composables/useInfos.ts +++ b/app/src/composables/useInfos.ts @@ -13,7 +13,6 @@ import api from '@/api' import { timeout } from '@/helpers/commons' import i18n from '@/i18n' import { useDomains } from './data' -import { useRequests, type ReconnectingArgs } from './useRequests' import { useSSE } from './useSSE' type BreadcrumbRoutes = { @@ -181,10 +180,6 @@ export const useInfos = createGlobalState(() => { return api.get('logout') } - function tryToReconnect(args?: ReconnectingArgs) { - useRequests().reconnecting.value = args - } - function updateRouterKey(to?: RouteLocationNormalized) { if (!to) { // Trick to force a view reload @@ -223,7 +218,6 @@ export const useInfos = createGlobalState(() => { onLogout, login, logout, - tryToReconnect, updateHtmlTitle, updateRouterKey, } diff --git a/app/src/composables/useRequests.ts b/app/src/composables/useRequests.ts index 62cea660e..e73d8248b 100644 --- a/app/src/composables/useRequests.ts +++ b/app/src/composables/useRequests.ts @@ -1,5 +1,5 @@ import { createGlobalState } from '@vueuse/core' -import { computed, reactive, ref, shallowRef } from 'vue' +import { computed, reactive, shallowRef } from 'vue' import { useRouter } from 'vue-router' import type { RequestMethod } from '@/api/api' @@ -45,18 +45,10 @@ export type RequestMessage = { variant: StateVariant } -export type ReconnectingArgs = { - attemps?: number - origin?: string - initialDelay?: number - delay?: number -} - export const useRequests = createGlobalState(() => { const router = useRouter() const requests = shallowRef([]) - const reconnecting = ref() const currentRequest = computed(() => { return requests.value.find((r) => r.showModal) }) @@ -230,7 +222,6 @@ export const useRequests = createGlobalState(() => { requests, historyList, currentRequest, - reconnecting, locked, startRequest, endRequest,