From f8aff2bb1b6f93dea2e722e10f501c23ce02a916 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Thu, 8 Dec 2022 11:06:56 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=EF=B8=8F=20Massive=20refactor=20ar?= =?UTF-8?q?ound=20archive=20uncompression=20for=20reading/analysis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/client/actions/fileops.actions.tsx | 24 ++++++++----------- .../components/ComicDetail/ComicDetail.tsx | 2 +- .../ComicDetail/Tabs/ArchiveOperations.tsx | 10 +++++++- src/client/constants/action-types.ts | 2 ++ src/client/reducers/fileops.reducer.ts | 19 ++++++++++++++- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index d8433f2..3c1f1f0 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "pretty-bytes": "^5.6.0", "prop-types": "^15.8.1", "qs": "^6.10.5", - "react": "^18.1.0", + "react": "^18.2.0", "react-collapsible": "^2.9.0", "react-comic-viewer": "^0.4.0", "react-day-picker": "^8.0.6", diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index ee03372..457de36 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -36,7 +36,7 @@ import { CV_WEEKLY_PULLLIST_FETCHED, } from "../constants/action-types"; import { success } from "react-notification-system-redux"; -import { removeLeadingPeriod } from "../shared/utils/formatting.utils"; + import { isNil, map } from "lodash"; export async function walkFolder(path: string): Promise> { @@ -260,13 +260,12 @@ export const fetchComicVineMatches = * @returns {any} */ export const extractComicArchive = - (path: string, options: any): any => async (dispatch) => { - const comicBookPages: string[] = []; - console.log(options); + (path: string, options: any): any => + async (dispatch) => { dispatch({ type: IMS_COMIC_BOOK_ARCHIVE_EXTRACTION_CALL_IN_PROGRESS, }); - const extractedComicBookArchive = await axios({ + await axios({ method: "POST", url: `${LIBRARY_SERVICE_BASE_URI}/uncompressFullArchive`, headers: { @@ -277,17 +276,14 @@ export const extractComicArchive = options, }, }); - map(extractedComicBookArchive.data, (page) => { - const pageFilePath = removeLeadingPeriod(page); - const imagePath = encodeURI(`${LIBRARY_SERVICE_HOST}${pageFilePath}`); - comicBookPages.push(imagePath); - }); - dispatch({ - type: IMS_COMIC_BOOK_ARCHIVE_EXTRACTION_SUCCESS, - extractedComicBookArchive: comicBookPages, - }); }; +/** + * Description + * @param {any} query + * @param {any} options + * @returns {any} + */ export const searchIssue = (query, options) => async (dispatch) => { dispatch({ type: SS_SEARCH_IN_PROGRESS, diff --git a/src/client/components/ComicDetail/ComicDetail.tsx b/src/client/components/ComicDetail/ComicDetail.tsx index 0145c09..acab0a4 100644 --- a/src/client/components/ComicDetail/ComicDetail.tsx +++ b/src/client/components/ComicDetail/ComicDetail.tsx @@ -77,7 +77,7 @@ export const ComicDetail = (data: ComicDetailProps): ReactElement => { dispatch( extractComicArchive(filePath, { type: "full", - purpose: "readComicBook", + purpose: "reading", imageResizeOptions: { baseWidth: 1024, }, diff --git a/src/client/components/ComicDetail/Tabs/ArchiveOperations.tsx b/src/client/components/ComicDetail/Tabs/ArchiveOperations.tsx index c9655ed..2cf39ba 100644 --- a/src/client/components/ComicDetail/Tabs/ArchiveOperations.tsx +++ b/src/client/components/ComicDetail/Tabs/ArchiveOperations.tsx @@ -23,7 +23,15 @@ export const ArchiveOperations = (props): ReactElement => { const dispatch = useDispatch(); const unpackComicArchive = useCallback(() => { - dispatch(extractComicArchive(data.rawFileDetails.filePath)); + dispatch( + extractComicArchive(data.rawFileDetails.filePath, { + type: "full", + purpose: "analysis", + imageResizeOptions: { + baseWidth: 275, + }, + }), + ); }, []); // sliding panel config diff --git a/src/client/constants/action-types.ts b/src/client/constants/action-types.ts index a6be92d..f058853 100644 --- a/src/client/constants/action-types.ts +++ b/src/client/constants/action-types.ts @@ -81,6 +81,8 @@ export const IMS_COMIC_BOOK_ARCHIVE_EXTRACTION_CALL_IN_PROGRESS = export const IMS_COMIC_BOOK_ARCHIVE_EXTRACTION_CALL_FAILED = "IMS_COMIC_BOOK_ARCHIVE_EXTRACTION_CALL_FAILED"; +export const COMICBOOK_EXTRACTION_SUCCESS = "COMICBOOK_EXTRACTION_SUCCESS"; + // Image file stats export const IMG_ANALYSIS_CALL_IN_PROGRESS = "IMG_ANALYSIS_CALL_IN_PROGRESS"; export const IMG_ANALYSIS_DATA_FETCH_SUCCESS = diff --git a/src/client/reducers/fileops.reducer.ts b/src/client/reducers/fileops.reducer.ts index 2060797..3eb0b96 100644 --- a/src/client/reducers/fileops.reducer.ts +++ b/src/client/reducers/fileops.reducer.ts @@ -29,7 +29,11 @@ import { SS_SEARCH_FAILED, SS_SEARCH_RESULTS_FETCHED_SPECIAL, VOLUMES_FETCHED, + COMICBOOK_EXTRACTION_SUCCESS, } from "../constants/action-types"; +import { removeLeadingPeriod } from "../shared/utils/formatting.utils"; +import { LIBRARY_SERVICE_HOST } from "../constants/endpoints"; + const initialState = { IMSCallInProgress: false, IMGCallInProgress: false, @@ -157,6 +161,19 @@ function fileOpsReducer(state = initialState, action) { librarySearchResultCount: state.librarySearchResultCount + 1, }; } + + case COMICBOOK_EXTRACTION_SUCCESS: { + const comicBookPages: string[] = []; + map(action.result, (page) => { + const pageFilePath = removeLeadingPeriod(page); + const imagePath = encodeURI(`${LIBRARY_SERVICE_HOST}${pageFilePath}`); + comicBookPages.push(imagePath); + }); + return { + ...state, + extractedComicBookArchive: comicBookPages, + }; + } case LS_QUEUE_DRAINED: { console.log("drained", action); return { @@ -229,7 +246,7 @@ function fileOpsReducer(state = initialState, action) { volumes: action.data, SSCallInProgress: false, }; - + case SS_SEARCH_FAILED: { return { ...state,