2023-05-18 13:25:19 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-06-04 00:30:48 +02:00
|
|
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
2023-06-08 13:40:50 +02:00
|
|
|
import useSWR, { Middleware, SWRConfiguration, SWRResponse } from 'swr';
|
2023-05-18 13:25:19 +02:00
|
|
|
import useSWRInfinite, { SWRInfiniteConfiguration, SWRInfiniteResponse } from 'swr/infinite';
|
|
|
|
|
import {
|
|
|
|
|
BackupValidationResult,
|
|
|
|
|
BatchChaptersChange,
|
|
|
|
|
IAbout,
|
|
|
|
|
ICategory,
|
|
|
|
|
IChapter,
|
|
|
|
|
IExtension,
|
|
|
|
|
IManga,
|
|
|
|
|
IMangaChapter,
|
|
|
|
|
IncludeInGlobalUpdate,
|
|
|
|
|
ISource,
|
|
|
|
|
ISourceFilters,
|
|
|
|
|
IUpdateStatus,
|
|
|
|
|
Metadata,
|
|
|
|
|
PaginatedList,
|
2023-05-20 13:12:23 +02:00
|
|
|
PaginatedMangaList,
|
2023-05-18 13:25:19 +02:00
|
|
|
SourcePreferences,
|
|
|
|
|
SourceSearchResult,
|
|
|
|
|
UpdateCheck,
|
2023-08-15 13:54:29 +02:00
|
|
|
} from '@/typings.ts';
|
|
|
|
|
import { HttpMethod as DefaultHttpMethod, IRestClient, RestClient } from '@/lib/RestClient.ts';
|
|
|
|
|
import storage from '@/util/localStorage.tsx';
|
2023-05-18 13:25:19 +02:00
|
|
|
|
|
|
|
|
enum SWRHttpMethod {
|
|
|
|
|
SWR_GET,
|
|
|
|
|
SWR_GET_INFINITE,
|
|
|
|
|
SWR_POST,
|
2023-05-22 14:04:05 +02:00
|
|
|
SWR_POST_INFINITE,
|
2023-05-18 13:25:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type HttpMethodType = DefaultHttpMethod | SWRHttpMethod;
|
|
|
|
|
const HttpMethod = { ...SWRHttpMethod, ...DefaultHttpMethod };
|
|
|
|
|
|
|
|
|
|
type RequestOption = { doOnlineFetch?: boolean };
|
|
|
|
|
|
|
|
|
|
type CustomSWROptions<Data> = {
|
|
|
|
|
skipRequest?: boolean;
|
|
|
|
|
getEndpoint?: (index: number, previousData: Data | null) => string | null;
|
2023-06-08 13:40:50 +02:00
|
|
|
disableCache?: boolean;
|
2023-05-18 13:25:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type SWROptions<Data = any, Error = any> = SWRConfiguration<Data, Error> & CustomSWROptions<Data>;
|
|
|
|
|
type SWRInfiniteOptions<Data = any, Error = any> = SWRInfiniteConfiguration<Data, Error> & CustomSWROptions<Data>;
|
|
|
|
|
|
2023-05-28 02:18:23 +02:00
|
|
|
type SWRInfiniteResponseLoadInfo = {
|
|
|
|
|
isInitialLoad: boolean;
|
|
|
|
|
isLoadMore: boolean;
|
|
|
|
|
};
|
2023-05-23 13:27:38 +02:00
|
|
|
type AbortableRequest = { abortRequest: AbortController['abort'] };
|
2023-06-04 00:30:48 +02:00
|
|
|
export type AbortableAxiosResponse<Data = any> = { response: Promise<Data> } & AbortableRequest;
|
2023-05-28 12:16:06 +02:00
|
|
|
export type AbortableSWRResponse<Data = any, Error = any> = SWRResponse<Data, Error> & AbortableRequest;
|
|
|
|
|
export type AbortableSWRInfiniteResponse<Data = any, Error = any> = SWRInfiniteResponse<Data, Error> &
|
2023-05-28 02:18:23 +02:00
|
|
|
AbortableRequest &
|
|
|
|
|
SWRInfiniteResponseLoadInfo;
|
2023-05-23 13:27:38 +02:00
|
|
|
|
2023-06-08 13:40:50 +02:00
|
|
|
const isLoadingMore = (swrResult: SWRInfiniteResponse): boolean => {
|
|
|
|
|
const isNextPageMissing = !!swrResult.data && typeof swrResult.data[swrResult.size - 1] === 'undefined';
|
2023-06-16 00:14:22 +02:00
|
|
|
const isRequestActive = swrResult.isValidating;
|
2023-06-08 13:40:50 +02:00
|
|
|
// SWR "isLoading" state is only updated for the first load, for every subsequent load it's "false"
|
2023-06-16 00:14:22 +02:00
|
|
|
return !swrResult.isLoading && swrResult.size > 0 && isNextPageMissing && isRequestActive;
|
2023-06-08 13:40:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const disableSwrInfiniteCache: Middleware = (useSWRNext) => (key, fetcher, config) => {
|
|
|
|
|
const swr = useSWRNext(key, fetcher, config) as unknown as SWRInfiniteResponse;
|
|
|
|
|
const { size, data, isLoading, isValidating } = swr;
|
|
|
|
|
const isActuallyValidating = !isLoading && !isLoadingMore(swr) && isValidating;
|
|
|
|
|
return {
|
|
|
|
|
...swr,
|
|
|
|
|
isLoading: isActuallyValidating ? true : isLoading,
|
|
|
|
|
data: isActuallyValidating ? undefined : data,
|
|
|
|
|
size: isActuallyValidating ? 1 : size,
|
|
|
|
|
} as SWRResponse;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const disableSwrCache: Middleware = (useSWRNext) => (key, fetcher, config) => {
|
|
|
|
|
const swr = useSWRNext(key, fetcher, config);
|
|
|
|
|
const { data, isLoading, isValidating } = swr;
|
|
|
|
|
return { ...swr, isLoading: isValidating ? true : isLoading, data: isValidating ? undefined : data };
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-18 13:25:19 +02:00
|
|
|
// the following endpoints have not been implemented:
|
|
|
|
|
// - PUT /api/v1/manga/{mangaId}/chapter/{chapterIndex} - modify chapter # PATCH endpoint used instead
|
|
|
|
|
// - POST /api/v1/backup/import - import backup # "import backup file" endpoint used instead
|
|
|
|
|
// - POST /api/v1/backup/validate - validate backup # "validate backup file" endpoint used instead
|
|
|
|
|
// - GET /api/v1/backup/export - export backup # no function needed, url gets called via link triggering the download
|
|
|
|
|
export class RequestManager {
|
2023-06-04 00:50:58 +02:00
|
|
|
public static readonly API_VERSION = '/api/v1/';
|
2023-05-18 13:25:19 +02:00
|
|
|
|
|
|
|
|
private readonly restClient: RestClient = new RestClient();
|
|
|
|
|
|
|
|
|
|
public getClient(): IRestClient {
|
|
|
|
|
return this.restClient;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:25:48 +02:00
|
|
|
public updateClient(config: Partial<AxiosInstance['defaults']>): void {
|
2023-05-18 13:25:19 +02:00
|
|
|
this.restClient.updateConfig(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getBaseUrl(): string {
|
|
|
|
|
return this.restClient.getClient().defaults.baseURL!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getWebSocketBaseUrl(): string {
|
|
|
|
|
return this.getBaseUrl().replace('http', 'ws');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getValidWebSocketUrl(path: string, apiVersion = RequestManager.API_VERSION): string {
|
|
|
|
|
return `${this.getWebSocketBaseUrl()}${apiVersion}${path}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getUpdateWebSocket(): WebSocket {
|
|
|
|
|
return new WebSocket(this.getValidWebSocketUrl('update'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getDownloadWebSocket(): WebSocket {
|
|
|
|
|
return new WebSocket(this.getValidWebSocketUrl('downloads'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getValidUrlFor(endpoint: string, apiVersion: string = RequestManager.API_VERSION): string {
|
|
|
|
|
return `${this.getBaseUrl()}${apiVersion}${endpoint}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getValidImgUrlFor(imageUrl: string, apiVersion: string = ''): string {
|
|
|
|
|
const useCache = storage.getItem('useCache', true);
|
|
|
|
|
const useCacheQuery = `?useCache=${useCache}`;
|
|
|
|
|
// server provided image urls already contain the api version
|
|
|
|
|
return `${this.getValidUrlFor(imageUrl, apiVersion)}${useCacheQuery}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private useSwr<
|
|
|
|
|
Data = any,
|
|
|
|
|
ErrorResponse = any,
|
|
|
|
|
OptionsSWR extends SWROptions<Data, ErrorResponse> = SWROptions<Data, ErrorResponse>,
|
|
|
|
|
>(
|
|
|
|
|
url: string,
|
|
|
|
|
httpMethod: DefaultHttpMethod,
|
|
|
|
|
{
|
|
|
|
|
data,
|
|
|
|
|
axiosOptions,
|
|
|
|
|
swrOptions,
|
|
|
|
|
}: {
|
|
|
|
|
data?: Data;
|
|
|
|
|
axiosOptions?: AxiosRequestConfig;
|
|
|
|
|
swrOptions?: OptionsSWR;
|
|
|
|
|
} = {},
|
|
|
|
|
): SWRResponse<Data, ErrorResponse> {
|
2023-06-08 13:40:50 +02:00
|
|
|
const { skipRequest, disableCache, ...swrConfig } = swrOptions ?? {};
|
2023-05-18 13:25:19 +02:00
|
|
|
|
|
|
|
|
// in case "null" gets passed as the url, SWR won't do the request
|
|
|
|
|
return useSWR(skipRequest ? null : url, {
|
|
|
|
|
fetcher: (path: string) => this.restClient.fetcher(path, { data, httpMethod, config: axiosOptions }),
|
2023-06-08 13:40:50 +02:00
|
|
|
use: disableCache ? [disableSwrCache] : undefined,
|
2023-05-18 13:25:19 +02:00
|
|
|
...swrConfig,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-20 13:12:23 +02:00
|
|
|
public useSwrInfinite<
|
|
|
|
|
Data = any,
|
|
|
|
|
ErrorResponse = any,
|
|
|
|
|
OptionsSWR extends SWRInfiniteOptions<Data, ErrorResponse> = SWRInfiniteOptions<Data, ErrorResponse>,
|
|
|
|
|
>(
|
2023-05-18 13:25:19 +02:00
|
|
|
getEndpoint: Required<CustomSWROptions<Data>>['getEndpoint'],
|
2023-05-22 14:04:05 +02:00
|
|
|
httpMethod: DefaultHttpMethod,
|
|
|
|
|
{
|
|
|
|
|
data,
|
|
|
|
|
axiosOptions,
|
|
|
|
|
swrOptions,
|
|
|
|
|
}: { data?: any; axiosOptions?: AxiosRequestConfig; swrOptions?: OptionsSWR } = {},
|
2023-05-28 02:18:23 +02:00
|
|
|
): SWRInfiniteResponse<Data, ErrorResponse> & SWRInfiniteResponseLoadInfo {
|
2023-06-08 13:40:50 +02:00
|
|
|
const { skipRequest, disableCache, ...swrConfig } = swrOptions ?? {};
|
2023-05-20 13:12:23 +02:00
|
|
|
|
2023-05-18 13:25:19 +02:00
|
|
|
// useSWRInfinite will (by default) revalidate the first page, to check if the other pages have to be revalidated as well
|
2023-05-28 02:18:23 +02:00
|
|
|
const swrResult = useSWRInfinite<Data, ErrorResponse>(
|
2023-05-18 13:25:19 +02:00
|
|
|
(index, previousData) => {
|
|
|
|
|
const pageEndpoint = getEndpoint(index, previousData);
|
2023-05-20 13:12:23 +02:00
|
|
|
return pageEndpoint !== null && !skipRequest ? this.getValidUrlFor(pageEndpoint) : null;
|
2023-05-18 13:25:19 +02:00
|
|
|
},
|
|
|
|
|
{
|
2023-05-22 14:04:05 +02:00
|
|
|
fetcher: (path: string) => this.restClient.fetcher(path, { httpMethod, data, config: axiosOptions }),
|
2023-06-08 13:40:50 +02:00
|
|
|
use: disableCache ? [disableSwrInfiniteCache] : undefined,
|
2023-05-20 13:12:23 +02:00
|
|
|
...swrConfig,
|
2023-05-18 13:25:19 +02:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
2023-05-28 02:18:23 +02:00
|
|
|
const customSwrResult = {
|
|
|
|
|
...swrResult,
|
|
|
|
|
isInitialLoad: swrResult.isLoading,
|
2023-06-08 13:40:50 +02:00
|
|
|
isLoadMore: isLoadingMore(swrResult),
|
2023-05-18 13:25:19 +02:00
|
|
|
};
|
2023-05-28 02:18:23 +02:00
|
|
|
customSwrResult.isLoading = customSwrResult.isInitialLoad || customSwrResult.isLoadMore;
|
|
|
|
|
|
|
|
|
|
return customSwrResult;
|
2023-05-18 13:25:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Performs the actual server request.
|
|
|
|
|
*
|
|
|
|
|
* In case {@link HttpMethod.GET_SWR} gets passed, the "useSWR" hook gets called.
|
|
|
|
|
* In case {@link HttpMethod.GET_SWR_INFINITE} gets passed, the "useSWRInfinite" hook gets called.
|
|
|
|
|
* In that case "getEndpoint" has to be passed, which gets used over "endpoint"
|
|
|
|
|
*
|
|
|
|
|
* Pass "skipRequest" to make SWR skip sending the request to the server.
|
|
|
|
|
* In case "formData" is passed, "data" gets ignored.
|
|
|
|
|
*/
|
|
|
|
|
private doRequest<
|
2023-05-23 13:27:38 +02:00
|
|
|
Result extends AbortableAxiosResponse | AbortableSWRResponse | AbortableSWRInfiniteResponse,
|
2023-05-18 13:25:19 +02:00
|
|
|
OptionsSWR extends SWROptions | SWRInfiniteOptions,
|
|
|
|
|
>(
|
|
|
|
|
httpMethod: HttpMethodType,
|
|
|
|
|
endpoint: string,
|
|
|
|
|
{
|
|
|
|
|
apiVersion = RequestManager.API_VERSION,
|
|
|
|
|
data: dataToSend,
|
|
|
|
|
formData,
|
|
|
|
|
axiosOptions,
|
|
|
|
|
swrOptions,
|
|
|
|
|
}: {
|
|
|
|
|
apiVersion?: string;
|
|
|
|
|
data?: any;
|
|
|
|
|
formData?: { [key: string]: any };
|
|
|
|
|
axiosOptions?: AxiosRequestConfig;
|
|
|
|
|
swrOptions?: OptionsSWR;
|
|
|
|
|
} = {},
|
|
|
|
|
): Result {
|
|
|
|
|
const url = `${apiVersion}${endpoint}`;
|
|
|
|
|
|
|
|
|
|
let data = dataToSend;
|
|
|
|
|
if (formData) {
|
|
|
|
|
data = new FormData();
|
|
|
|
|
|
|
|
|
|
Object.entries(formData).forEach(([key, value]) => {
|
2023-06-04 00:32:08 +02:00
|
|
|
if (value !== undefined) data.append(key, value); // "append" automatically converts non string or blob values to strings
|
2023-05-18 13:25:19 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
const abortController = new AbortController();
|
|
|
|
|
const abortRequest = (reason?: any): void => {
|
|
|
|
|
if (!abortController.signal.aborted) {
|
|
|
|
|
abortController.abort(reason);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const axiosOptionsWithAbortController = { ...axiosOptions, signal: abortController.signal };
|
2023-05-18 13:25:19 +02:00
|
|
|
switch (httpMethod) {
|
|
|
|
|
case HttpMethod.SWR_GET:
|
2023-05-23 13:27:38 +02:00
|
|
|
return {
|
|
|
|
|
...(this.useSwr(url, HttpMethod.GET, { axiosOptions, swrOptions }) as Result),
|
|
|
|
|
abortRequest,
|
|
|
|
|
};
|
2023-05-18 13:25:19 +02:00
|
|
|
case HttpMethod.SWR_GET_INFINITE:
|
|
|
|
|
// throw TypeError in case options aren't correctly passed
|
2023-05-23 13:27:38 +02:00
|
|
|
return {
|
|
|
|
|
...(this.useSwrInfinite(swrOptions!.getEndpoint!, HttpMethod.GET, {
|
|
|
|
|
axiosOptions: axiosOptionsWithAbortController,
|
|
|
|
|
swrOptions,
|
|
|
|
|
}) as Result),
|
|
|
|
|
abortRequest,
|
|
|
|
|
};
|
2023-05-22 14:04:05 +02:00
|
|
|
case SWRHttpMethod.SWR_POST_INFINITE:
|
2023-05-23 13:27:38 +02:00
|
|
|
return {
|
|
|
|
|
...(this.useSwrInfinite(swrOptions!.getEndpoint!, HttpMethod.POST, {
|
|
|
|
|
data,
|
|
|
|
|
axiosOptions: axiosOptionsWithAbortController,
|
|
|
|
|
swrOptions,
|
|
|
|
|
}) as Result),
|
|
|
|
|
abortRequest,
|
|
|
|
|
};
|
2023-05-18 13:25:19 +02:00
|
|
|
case HttpMethod.SWR_POST:
|
2023-05-23 13:27:38 +02:00
|
|
|
return {
|
|
|
|
|
...(this.useSwr(url, HttpMethod.POST, {
|
|
|
|
|
data,
|
|
|
|
|
axiosOptions: axiosOptionsWithAbortController,
|
|
|
|
|
swrOptions,
|
|
|
|
|
}) as Result),
|
|
|
|
|
controller: abortController,
|
|
|
|
|
};
|
2023-05-18 13:25:19 +02:00
|
|
|
default:
|
2023-05-23 13:27:38 +02:00
|
|
|
return {
|
|
|
|
|
response: this.restClient.fetcher(url, {
|
|
|
|
|
data,
|
|
|
|
|
httpMethod,
|
|
|
|
|
config: axiosOptionsWithAbortController,
|
|
|
|
|
checkResponseIsJson: false,
|
|
|
|
|
}),
|
|
|
|
|
abortRequest,
|
|
|
|
|
} as Result;
|
2023-05-18 13:25:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetGlobalMeta(swrOptions?: SWROptions<Metadata>): AbortableSWRResponse<Metadata> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, 'meta', { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public setGlobalMetadata(key: string, value: any): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, 'meta', { formData: { key, value } });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetAbout(swrOptions?: SWROptions<IAbout>): AbortableSWRResponse<IAbout> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, 'settings/about', { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useCheckForUpdate(swrOptions?: SWROptions<UpdateCheck[]>): AbortableSWRResponse<UpdateCheck[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, 'settings/check-update', { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetExtensionList(swrOptions?: SWROptions<IExtension[]>): AbortableSWRResponse<IExtension[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, 'extension/list', { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public installExtension(extension: string | File): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
if (typeof extension === 'string') {
|
|
|
|
|
return this.doRequest(HttpMethod.GET, `extension/install/${extension}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this.doRequest(HttpMethod.POST, `extension/install`, { formData: { file: extension } });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public updateExtension(extension: string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, `extension/update/${extension}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public uninstallExtension(extension: string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, `extension/uninstall/${extension}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getExtensionIconUrl(extension: string): string {
|
|
|
|
|
return this.getValidImgUrlFor(`extension/icon/${extension}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetSourceList(swrOptions?: SWROptions<ISource[]>): AbortableSWRResponse<ISource[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, 'source/list', { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetSource(sourceId: string, swrOptions?: SWROptions<ISource>): AbortableSWRResponse<ISource> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}`, { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetSourcePopularMangas(
|
|
|
|
|
sourceId: string,
|
|
|
|
|
initialPages?: number,
|
2023-05-20 13:12:23 +02:00
|
|
|
swrOptions?: SWRInfiniteOptions<PaginatedMangaList>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRInfiniteResponse<PaginatedMangaList> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(SWRHttpMethod.SWR_GET_INFINITE, '', {
|
|
|
|
|
swrOptions: {
|
|
|
|
|
getEndpoint: (page, previousData) =>
|
2023-05-20 13:12:23 +02:00
|
|
|
previousData?.hasNextPage ?? true ? `source/${sourceId}/popular/${page + 1}` : null,
|
2023-05-18 13:25:19 +02:00
|
|
|
initialSize: initialPages,
|
|
|
|
|
...swrOptions,
|
|
|
|
|
} as typeof swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetSourceLatestMangas(
|
|
|
|
|
sourceId: string,
|
|
|
|
|
initialPages?: number,
|
2023-05-20 13:12:23 +02:00
|
|
|
swrOptions?: SWRInfiniteOptions<PaginatedMangaList>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRInfiniteResponse<PaginatedMangaList> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(SWRHttpMethod.SWR_GET_INFINITE, '', {
|
|
|
|
|
swrOptions: {
|
|
|
|
|
getEndpoint: (page, previousData) =>
|
2023-05-20 13:12:23 +02:00
|
|
|
previousData?.hasNextPage ?? true ? `source/${sourceId}/latest/${page + 1}` : null,
|
2023-05-18 13:25:19 +02:00
|
|
|
initialSize: initialPages,
|
|
|
|
|
...swrOptions,
|
|
|
|
|
} as typeof swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetSourcePreferences(
|
|
|
|
|
sourceId: string,
|
|
|
|
|
swrOptions?: SWROptions<SourcePreferences[]>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<SourcePreferences[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}/preferences`, { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public setSourcePreferences(sourceId: string, position: number, value: string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, `source/${sourceId}/preferences`, { data: { position, value } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetSourceFilters(
|
|
|
|
|
sourceId: string,
|
|
|
|
|
reset?: boolean,
|
|
|
|
|
swrOptions?: SWROptions<ISourceFilters[]>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<ISourceFilters[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `source/${sourceId}/filters`, { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public setSourceFilters(sourceId: string, filters: { position: number; state: string }[]): AbortableAxiosResponse {
|
2023-05-22 14:03:50 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, `source/${sourceId}/filters`, { data: filters });
|
2023-05-18 13:25:19 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public resetSourceFilters(sourceId: string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, `source/${sourceId}/filters?reset=true`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useSourceSearch(
|
|
|
|
|
sourceId: string,
|
|
|
|
|
searchTerm: string,
|
|
|
|
|
initialPages?: number,
|
|
|
|
|
swrOptions?: SWRInfiniteOptions<SourceSearchResult>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRInfiniteResponse<SourceSearchResult> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET_INFINITE, '', {
|
|
|
|
|
swrOptions: {
|
|
|
|
|
getEndpoint: (page, previousData) =>
|
2023-05-20 13:12:23 +02:00
|
|
|
previousData?.hasNextPage ?? true
|
|
|
|
|
? `source/${sourceId}/search?searchTerm=${searchTerm}&pageNum=${page + 1}`
|
2023-05-18 13:25:19 +02:00
|
|
|
: null,
|
|
|
|
|
initialSize: initialPages,
|
|
|
|
|
...swrOptions,
|
|
|
|
|
} as typeof swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useSourceQuickSearch(
|
|
|
|
|
sourceId: string,
|
|
|
|
|
searchTerm: string,
|
|
|
|
|
filters: { position: number; state: string }[],
|
|
|
|
|
initialPages?: number,
|
|
|
|
|
swrOptions?: SWRInfiniteOptions<SourceSearchResult>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRInfiniteResponse<SourceSearchResult> {
|
2023-05-22 14:04:05 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_POST_INFINITE, '', {
|
|
|
|
|
data: { searchTerm, filter: filters },
|
2023-05-18 13:25:19 +02:00
|
|
|
swrOptions: {
|
|
|
|
|
getEndpoint: (page, previousData) =>
|
2023-05-20 13:12:23 +02:00
|
|
|
previousData?.hasNextPage ?? true
|
|
|
|
|
? `source/${sourceId}/quick-search?searchTerm=${searchTerm}&pageNum=${page + 1}`
|
2023-05-18 13:25:19 +02:00
|
|
|
: null,
|
|
|
|
|
initialSize: initialPages,
|
|
|
|
|
...swrOptions,
|
|
|
|
|
} as typeof swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetManga(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
{ doOnlineFetch, ...swrOptions }: SWROptions<IManga> & RequestOption = {},
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<IManga> {
|
2023-05-18 13:25:19 +02:00
|
|
|
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
|
|
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}${onlineFetch}`, {
|
|
|
|
|
swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-04 00:50:58 +02:00
|
|
|
public getManga(mangaId: number | string, doOnlineFetch?: boolean): AbortableAxiosResponse<IManga> {
|
|
|
|
|
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
|
|
|
|
|
return this.doRequest(HttpMethod.GET, `manga/${mangaId}${onlineFetch}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 13:25:19 +02:00
|
|
|
public useGetFullManga(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
{ doOnlineFetch, ...swrOptions }: SWROptions<IManga> & RequestOption = {},
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<IManga> {
|
2023-05-18 13:25:19 +02:00
|
|
|
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
|
|
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/full${onlineFetch}`, {
|
|
|
|
|
swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getMangaThumbnailUrl(mangaId: number): string {
|
|
|
|
|
return this.getValidImgUrlFor(`manga/${mangaId}/thumbnail`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetMangaCategories(
|
|
|
|
|
mangaId: number,
|
|
|
|
|
swrOptions?: SWROptions<ICategory[]>,
|
|
|
|
|
): AbortableSWRResponse<ICategory[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/category`, { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public addMangaToCategory(mangaId: number, categoryId: number): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, `manga/${mangaId}/category/${categoryId}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public removeMangaFromCategory(mangaId: number, categoryId: number): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/category/${categoryId}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public addMangaToLibrary(mangaId: number | string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, `manga/${mangaId}/library`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public removeMangaFromLibrary(mangaId: number | string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/library`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public setMangaMeta(mangaId: number, key: string, value: any): AbortableAxiosResponse {
|
2023-06-04 00:50:58 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `manga/${mangaId}/meta`, { formData: { key, value } });
|
2023-05-18 13:25:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetMangaChapters(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
{ doOnlineFetch, ...swrOptions }: SWROptions<IChapter[]> & RequestOption = {},
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<IChapter[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
|
|
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/chapters${onlineFetch}`, {
|
|
|
|
|
swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-04 00:50:58 +02:00
|
|
|
public getMangaChapters(mangaId: number | string, doOnlineFetch?: boolean): AbortableAxiosResponse<IChapter[]> {
|
|
|
|
|
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
|
|
|
|
|
return this.doRequest(HttpMethod.GET, `manga/${mangaId}/chapters${onlineFetch}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 13:25:19 +02:00
|
|
|
public updateMangaChapters(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
{
|
|
|
|
|
chapterIds,
|
|
|
|
|
chapterIndexes,
|
|
|
|
|
change,
|
|
|
|
|
}: (
|
|
|
|
|
| { chapterIds?: number[]; chapterIndexes: number[] }
|
|
|
|
|
| { chapterIds: number[]; chapterIndexes?: number[] }
|
|
|
|
|
) & { change: BatchChaptersChange },
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, `manga/${mangaId}/chapter/batch`, {
|
|
|
|
|
data: {
|
|
|
|
|
chapterIds,
|
|
|
|
|
chapterIndexes,
|
|
|
|
|
change,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetChapter(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
chapterIndex: number | string,
|
|
|
|
|
swrOptions?: SWROptions<IChapter>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<IChapter> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `manga/${mangaId}/chapter/${chapterIndex}`, {
|
|
|
|
|
swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-04 00:50:58 +02:00
|
|
|
public getChapter(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse<IChapter> {
|
|
|
|
|
return this.doRequest(HttpMethod.GET, `manga/${mangaId}/chapter/${chapterIndex}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public deleteDownloadedChapter(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/chapter/${chapterIndex}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateChapter(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
chapterIndex: number | string,
|
|
|
|
|
change: { read?: boolean; bookmarked?: boolean; markPrevRead?: boolean; lastPageRead?: number } = {},
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `manga/${mangaId}/chapter/${chapterIndex}`, { formData: change });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setChapterMeta(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
chapterIndex: number | string,
|
|
|
|
|
key: string,
|
|
|
|
|
value: any,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `manga/${mangaId}/chapter/${chapterIndex}/meta`, {
|
|
|
|
|
formData: { key, value },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getChapterPageUrl(mangaId: number | string, chapterIndex: number | string, page: number): string {
|
|
|
|
|
return this.getValidImgUrlFor(
|
|
|
|
|
`manga/${mangaId}/chapter/${chapterIndex}/page/${page}`,
|
|
|
|
|
RequestManager.API_VERSION,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public updateChapters(chapterIds: number[], change: BatchChaptersChange): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, `chapter/batch`, { data: { chapterIds, change } });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetCategories(swrOptions?: SWROptions<ICategory[]>): AbortableSWRResponse<ICategory[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `category`, { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public createCategory(name: string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, `category`, { formData: { name } });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public reorderCategory(currentPosition: number, newPosition: number): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `category/reorder`, {
|
|
|
|
|
formData: { from: currentPosition, to: newPosition },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetCategoryMangas(categoryId: number, swrOptions?: SWROptions<IManga[]>): AbortableSWRResponse<IManga[]> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, `category/${categoryId}`, { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public deleteCategory(categoryId: number): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.DELETE, `category/${categoryId}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateCategory(
|
|
|
|
|
categoryId: number,
|
|
|
|
|
change: { name?: string; default?: boolean; includeInUpdate?: IncludeInGlobalUpdate } = {},
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `category/${categoryId}`, { formData: change });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public setCategoryMeta(categoryId: number, key: string, value: any): AbortableAxiosResponse {
|
2023-06-04 00:50:58 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `category/${categoryId}/meta`, { formData: { key, value } });
|
2023-05-18 13:25:19 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public restoreBackupFile(file: File): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, 'backup/import/file', { formData: { 'backup.proto.gz': file } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useValidateBackupFile(
|
|
|
|
|
file: File,
|
|
|
|
|
swrOptions?: SWROptions<BackupValidationResult>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRResponse<BackupValidationResult> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_POST, 'backup/validate/file', {
|
|
|
|
|
formData: { 'backup.proto.gz': file },
|
|
|
|
|
swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getExportBackupUrl(): string {
|
|
|
|
|
return this.getValidUrlFor('backup/export/file');
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public startDownloads(): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, 'downloads/start');
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public stopDownloads(): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, 'downloads/stop');
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public clearDownloads(): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, 'downloads/clear');
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public addChapterToDownloadQueue(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.GET, `download/${mangaId}/chapter/${chapterIndex}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public removeChapterFromDownloadQueue(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
chapterIndex: number | string,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.DELETE, `download/${mangaId}/chapter/${chapterIndex}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public reorderChapterInDownloadQueue(
|
|
|
|
|
mangaId: number | string,
|
|
|
|
|
chapterIndex: number | string,
|
|
|
|
|
position: number,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.PATCH, `download/${mangaId}/chapter/${chapterIndex}/reorder/${position}`);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public addChaptersToDownloadQueue(chapterIds: number[]): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, 'download/batch', { data: { chapterIds } });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public removeChaptersFromDownloadQueue(chapterIds: number[]): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.DELETE, 'download/batch', { data: { chapterIds } });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public useGetRecentlyUpdatedChapters(
|
|
|
|
|
initialPages?: number,
|
|
|
|
|
swrOptions?: SWRInfiniteOptions<PaginatedList<IMangaChapter>>,
|
2023-05-23 13:27:38 +02:00
|
|
|
): AbortableSWRInfiniteResponse<PaginatedList<IMangaChapter>> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET_INFINITE, '', {
|
|
|
|
|
swrOptions: {
|
|
|
|
|
getEndpoint: (page, previousData) =>
|
|
|
|
|
previousData?.hasNextPage ?? true ? `update/recentChapters/${page}` : null,
|
|
|
|
|
initialSize: initialPages,
|
|
|
|
|
...swrOptions,
|
|
|
|
|
} as typeof swrOptions,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public startGlobalUpdate(categoryId?: number): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, 'update/fetch', { formData: { categoryId } });
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public resetGlobalUpdate(): AbortableAxiosResponse {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.POST, 'update/reset');
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 13:27:38 +02:00
|
|
|
public useGetGlobalUpdateSummary(swrOptions?: SWROptions<IUpdateStatus>): AbortableSWRResponse<IUpdateStatus> {
|
2023-05-18 13:25:19 +02:00
|
|
|
return this.doRequest(HttpMethod.SWR_GET, 'update/summary', { swrOptions });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const requestManager = new RequestManager();
|
|
|
|
|
export default requestManager;
|