Feature/request manager remove get client usage (#325)

* Remove "getClient" usage from "metadata" util

* Remove "getClient" usage from "useRefreshManga" hook

* Remove "getClient" usage from "isDupChapter" util function

* Use correct endpoint for setting category metadata

"/meta" suffix was missing from url

* Use correct http method for updating manga metadata
This commit is contained in:
schroda
2023-06-04 00:50:58 +02:00
committed by GitHub
parent 207a87f3e9
commit 0fb204f141
4 changed files with 67 additions and 58 deletions

View File

@@ -69,7 +69,7 @@ export type AbortableSWRInfiniteResponse<Data = any, Error = any> = SWRInfiniteR
// - 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 {
private static readonly API_VERSION = '/api/v1/';
public static readonly API_VERSION = '/api/v1/';
private readonly restClient: RestClient = new RestClient();
@@ -425,6 +425,11 @@ export class RequestManager {
});
}
public getManga(mangaId: number | string, doOnlineFetch?: boolean): AbortableAxiosResponse<IManga> {
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
return this.doRequest(HttpMethod.GET, `manga/${mangaId}${onlineFetch}`);
}
public useGetFullManga(
mangaId: number | string,
{ doOnlineFetch, ...swrOptions }: SWROptions<IManga> & RequestOption = {},
@@ -463,7 +468,7 @@ export class RequestManager {
}
public setMangaMeta(mangaId: number, key: string, value: any): AbortableAxiosResponse {
return this.doRequest(HttpMethod.POST, `manga/${mangaId}/meta`, { formData: { key, value } });
return this.doRequest(HttpMethod.PATCH, `manga/${mangaId}/meta`, { formData: { key, value } });
}
public useGetMangaChapters(
@@ -476,6 +481,11 @@ export class RequestManager {
});
}
public getMangaChapters(mangaId: number | string, doOnlineFetch?: boolean): AbortableAxiosResponse<IChapter[]> {
const onlineFetch = doOnlineFetch ? '?onlineFetch=true' : '';
return this.doRequest(HttpMethod.GET, `manga/${mangaId}/chapters${onlineFetch}`);
}
public updateMangaChapters(
mangaId: number | string,
{
@@ -506,6 +516,10 @@ export class RequestManager {
});
}
public getChapter(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse<IChapter> {
return this.doRequest(HttpMethod.GET, `manga/${mangaId}/chapter/${chapterIndex}`);
}
public deleteDownloadedChapter(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse {
return this.doRequest(HttpMethod.DELETE, `manga/${mangaId}/chapter/${chapterIndex}`);
}
@@ -570,7 +584,7 @@ export class RequestManager {
}
public setCategoryMeta(categoryId: number, key: string, value: any): AbortableAxiosResponse {
return this.doRequest(HttpMethod.PATCH, `category/${categoryId}`, { formData: { key, value } });
return this.doRequest(HttpMethod.PATCH, `category/${categoryId}/meta`, { formData: { key, value } });
}
public restoreBackupFile(file: File): AbortableAxiosResponse {