diff --git a/src/components/manga/ChapterCard.tsx b/src/components/manga/ChapterCard.tsx index 1d011a47..1b6962cb 100644 --- a/src/components/manga/ChapterCard.tsx +++ b/src/components/manga/ChapterCard.tsx @@ -91,7 +91,7 @@ const ChapterCard: React.FC = (props: IProps) => { }; const downloadChapter = () => { - requestManager.addChapterToDownloadQueue(chapter.mangaId, chapter.index); + requestManager.addChapterToDownloadQueue(chapter.id); handleClose(); }; diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index f6521af4..f9ce743f 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -41,6 +41,8 @@ import { CategoryOrderBy, CheckForServerUpdatesQuery, CheckForServerUpdatesQueryVariables, + ClearDownloaderMutation, + ClearDownloaderMutationVariables, CreateCategoryInput, CreateCategoryMutation, CreateCategoryMutationVariables, @@ -50,6 +52,14 @@ import { DeleteDownloadedChapterMutationVariables, DeleteDownloadedChaptersMutation, DeleteDownloadedChaptersMutationVariables, + DequeueChapterDownloadMutation, + DequeueChapterDownloadMutationVariables, + DequeueChapterDownloadsMutation, + DequeueChapterDownloadsMutationVariables, + EnqueueChapterDownloadMutation, + EnqueueChapterDownloadMutationVariables, + EnqueueChapterDownloadsMutation, + EnqueueChapterDownloadsMutationVariables, GetAboutQuery, GetAboutQueryVariables, GetExtensionsFetchMutation, @@ -66,6 +76,8 @@ import { GetSourcesQueryVariables, InstallExternalExtensionMutation, InstallExternalExtensionMutationVariables, + ReorderChapterDownloadMutation, + ReorderChapterDownloadMutationVariables, SetCategoryMetadataMutation, SetCategoryMetadataMutationVariables, SetChapterMetadataMutation, @@ -73,6 +85,10 @@ import { SetGlobalMetadataMutation, SetGlobalMetadataMutationVariables, SetMangaMetadataMutation, + StartDownloaderMutation, + StartDownloaderMutationVariables, + StopDownloaderMutation, + StopDownloaderMutationVariables, UpdateCategoryMutation, UpdateCategoryMutationVariables, UpdateCategoryOrderMutation, @@ -106,7 +122,18 @@ import { SET_MANGA_METADATA, UPDATE_MANGA, UPDATE_MANGA_CATEGORIES } from '@/lib import { GET_MANGA, GET_MANGAS } from '@/lib/graphql/queries/MangaQuery.ts'; import { GET_CATEGORIES, GET_CATEGORY, GET_CATEGORY_MANGAS } from '@/lib/graphql/queries/CategoryQuery.ts'; import { GET_SOURCE_MANGAS_FETCH } from '@/lib/graphql/mutations/SourceMutation.ts'; -import { DELETE_DOWNLOADED_CHAPTER, DELETE_DOWNLOADED_CHAPTERS } from '@/lib/graphql/mutations/DownloaderMutation.ts'; +import { + CLEAR_DOWNLOADER, + DELETE_DOWNLOADED_CHAPTER, + DELETE_DOWNLOADED_CHAPTERS, + DEQUEUE_CHAPTER_DOWNLOAD, + DEQUEUE_CHAPTER_DOWNLOADS, + ENQUEUE_CHAPTER_DOWNLOAD, + ENQUEUE_CHAPTER_DOWNLOADS, + REORDER_CHAPTER_DOWNLOAD, + START_DOWNLOADER, + STOP_DOWNLOADER, +} from '@/lib/graphql/mutations/DownloaderMutation.ts'; import { GET_CHAPTER, GET_CHAPTERS } from '@/lib/graphql/queries/ChapterQuery.ts'; import { SET_CHAPTER_METADATA, UPDATE_CHAPTER, UPDATE_CHAPTERS } from '@/lib/graphql/mutations/ChapterMutation.ts'; import { @@ -116,6 +143,7 @@ import { UPDATE_CATEGORY, UPDATE_CATEGORY_ORDER, } from '@/lib/graphql/mutations/CategoryMutation.ts'; +import { GET_DOWNLOAD_STATUS } from '@/lib/graphql/queries/DownloaderQuery.ts'; enum SWRHttpMethod { SWR_GET, @@ -923,43 +951,79 @@ export class RequestManager { return this.getValidUrlFor('backup/export/file'); } - public startDownloads(): AbortableAxiosResponse { - return this.doRequest(HttpMethod.GET, 'downloads/start'); + public startDownloads(): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + START_DOWNLOADER, + {}, + ); } - public stopDownloads(): AbortableAxiosResponse { - return this.doRequest(HttpMethod.GET, 'downloads/stop'); + public stopDownloads(): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + STOP_DOWNLOADER, + {}, + ); } - public clearDownloads(): AbortableAxiosResponse { - return this.doRequest(HttpMethod.GET, 'downloads/clear'); + public clearDownloads(): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + CLEAR_DOWNLOADER, + {}, + { refetchQueries: [GET_DOWNLOAD_STATUS] }, + ); } - public addChapterToDownloadQueue(mangaId: number | string, chapterIndex: number | string): AbortableAxiosResponse { - return this.doRequest(HttpMethod.GET, `download/${mangaId}/chapter/${chapterIndex}`); + public addChapterToDownloadQueue(id: number): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + ENQUEUE_CHAPTER_DOWNLOAD, + { input: { id } }, + { refetchQueries: [GET_DOWNLOAD_STATUS] }, + ); } - public removeChapterFromDownloadQueue( - mangaId: number | string, - chapterIndex: number | string, - ): AbortableAxiosResponse { - return this.doRequest(HttpMethod.DELETE, `download/${mangaId}/chapter/${chapterIndex}`); + public removeChapterFromDownloadQueue(id: number): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + DEQUEUE_CHAPTER_DOWNLOAD, + { input: { id } }, + { refetchQueries: [GET_DOWNLOAD_STATUS] }, + ); } public reorderChapterInDownloadQueue( - mangaId: number | string, - chapterIndex: number | string, + chapterId: number, position: number, - ): AbortableAxiosResponse { - return this.doRequest(HttpMethod.PATCH, `download/${mangaId}/chapter/${chapterIndex}/reorder/${position}`); + ): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + REORDER_CHAPTER_DOWNLOAD, + { input: { chapterId, to: position } }, + { refetchQueries: [GET_DOWNLOAD_STATUS] }, + ); } - public addChaptersToDownloadQueue(chapterIds: number[]): AbortableAxiosResponse { - return this.doRequest(HttpMethod.POST, 'download/batch', { data: { chapterIds } }); + public addChaptersToDownloadQueue(ids: number[]): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + ENQUEUE_CHAPTER_DOWNLOADS, + { input: { ids } }, + { refetchQueries: [GET_DOWNLOAD_STATUS] }, + ); } - public removeChaptersFromDownloadQueue(chapterIds: number[]): AbortableAxiosResponse { - return this.doRequest(HttpMethod.DELETE, 'download/batch', { data: { chapterIds } }); + public removeChaptersFromDownloadQueue( + ids: number[], + ): AbortableApolloMutationResponse { + return this.doRequestNew( + GQLMethod.MUTATION, + DEQUEUE_CHAPTER_DOWNLOADS, + { input: { ids } }, + { refetchQueries: [GET_DOWNLOAD_STATUS] }, + ); } public useGetRecentlyUpdatedChapters( diff --git a/src/screens/DownloadQueue.tsx b/src/screens/DownloadQueue.tsx index 21b8dd8b..219b4c41 100644 --- a/src/screens/DownloadQueue.tsx +++ b/src/screens/DownloadQueue.tsx @@ -71,7 +71,7 @@ const DownloadQueue: React.FC = () => { await Promise.all([ // remove from download queue - requestManager.removeChapterFromDownloadQueue(chapter.mangaId, chapter.index).response, + requestManager.removeChapterFromDownloadQueue(chapter.id).response, // delete partial download, should be handle server side? // bug: The folder and the last image downloaded are not deleted requestManager.deleteDownloadedChapter(chapter.id).response, diff --git a/src/screens/Updates.tsx b/src/screens/Updates.tsx index 85e13d84..87462a91 100644 --- a/src/screens/Updates.tsx +++ b/src/screens/Updates.tsx @@ -146,7 +146,7 @@ const Updates: React.FC = () => { }; const downloadChapter = (chapter: IChapter) => { - requestManager.addChapterToDownloadQueue(chapter.mangaId, chapter.index); + requestManager.addChapterToDownloadQueue(chapter.id); }; const loadMore = useCallback(() => {