💽 Wiring up simple mongo import from CV result
This commit is contained in:
@@ -13,8 +13,12 @@ import {
|
||||
CV_API_CALL_IN_PROGRESS,
|
||||
CV_SEARCH_SUCCESS,
|
||||
CV_CLEANUP,
|
||||
IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS,
|
||||
IMS_CV_METADATA_IMPORT_SUCCESSFUL,
|
||||
IMS_CV_METADATA_IMPORT_FAILED,
|
||||
} from "../constants/action-types";
|
||||
import { refineQuery } from "../shared/utils/filenameparser.utils";
|
||||
import { extend } from "lodash";
|
||||
import sortBy from "array-sort-by";
|
||||
|
||||
export async function walkFolder(path: string): Promise<Array<IFolderData>> {
|
||||
@@ -80,7 +84,6 @@ export const fetchComicBookMetadata = (options) => async (dispatch) => {
|
||||
});
|
||||
|
||||
socket.on("comicBookCoverMetadata", (data: IExtractedComicBookCoverFile) => {
|
||||
console.log("Recd cover");
|
||||
dispatch({
|
||||
type: IMS_COMICBOOK_METADATA_FETCHED,
|
||||
data,
|
||||
@@ -107,6 +110,45 @@ export const getComicBooks = (options) => async (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const importToDB = (payload) => (dispatch) => {
|
||||
try {
|
||||
const comicBookMetadata = extend(
|
||||
{
|
||||
importStatus: {
|
||||
isImported: true,
|
||||
tagged: false,
|
||||
matchedResult: {
|
||||
score: "0",
|
||||
},
|
||||
},
|
||||
},
|
||||
{ sourcedMetadata: { comicvine: payload } },
|
||||
);
|
||||
dispatch({
|
||||
type: IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS,
|
||||
});
|
||||
|
||||
return axios
|
||||
.request({
|
||||
url: "http://localhost:3000/api/import/rawImportToDb",
|
||||
method: "POST",
|
||||
data: comicBookMetadata,
|
||||
transformResponse: (r: string) => JSON.parse(r),
|
||||
})
|
||||
.then((response) => {
|
||||
const { data } = response;
|
||||
dispatch({
|
||||
type: IMS_CV_METADATA_IMPORT_SUCCESSFUL,
|
||||
importResult: data,
|
||||
});
|
||||
});
|
||||
} catch (error) {
|
||||
dispatch({
|
||||
type: IMS_CV_METADATA_IMPORT_FAILED,
|
||||
importError: error,
|
||||
});
|
||||
}
|
||||
};
|
||||
export const fetchComicVineMatches = (searchPayload) => (dispatch) => {
|
||||
try {
|
||||
const issueString = searchPayload.rawFileDetails.name;
|
||||
|
||||
@@ -165,10 +165,12 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => {
|
||||
);
|
||||
|
||||
RawFileDetails.propTypes = {
|
||||
name: PropTypes.string,
|
||||
path: PropTypes.string,
|
||||
fileSize: PropTypes.number,
|
||||
extension: PropTypes.string,
|
||||
value: PropTypes.shape({
|
||||
name: PropTypes.string,
|
||||
path: PropTypes.string,
|
||||
fileSize: PropTypes.number,
|
||||
extension: PropTypes.string,
|
||||
}),
|
||||
};
|
||||
|
||||
ImportStatus.propTypes = {
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import React, { useMemo, useCallback, ReactElement } from "react";
|
||||
import {
|
||||
removeLeadingPeriod,
|
||||
escapePoundSymbol,
|
||||
} from "../shared/utils/formatting.utils";
|
||||
import { useTable } from "react-table";
|
||||
import prettyBytes from "pretty-bytes";
|
||||
import ellipsize from "ellipsize";
|
||||
import { isNil, isUndefined, map, isEmpty } from "lodash";
|
||||
import { isNil, isEmpty } from "lodash";
|
||||
import { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings";
|
||||
import { importToDB } from "../actions/fileops.actions";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
||||
import { search } from "../services/api/SearchApi";
|
||||
@@ -33,7 +27,7 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
||||
limit: "10",
|
||||
offset: "0",
|
||||
field_list: "id,name,deck,api_detail_url,image,description",
|
||||
resources: "volume",
|
||||
resources: "issue",
|
||||
},
|
||||
}),
|
||||
);
|
||||
@@ -44,6 +38,23 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
||||
const getDCPPSearchResults = useCallback((searchQuery) => {
|
||||
search(searchQuery);
|
||||
}, []);
|
||||
const dcppQuery = {
|
||||
query: {
|
||||
pattern: "Iron Man - V1 194",
|
||||
// file_type: "compressed",
|
||||
extensions: ["cbz", "cbr"],
|
||||
},
|
||||
hub_urls: [
|
||||
"adcs://novosibirsk.dc-dev.club:7111/?kp=SHA256/4XFHJFFBFEI2RS75FPRPPXPZMMKPXR764ABVVCC2QGJPQ34SDZGA",
|
||||
"dc.fly-server.ru",
|
||||
],
|
||||
priority: 1,
|
||||
};
|
||||
|
||||
const addToLibrary = useCallback(
|
||||
(comicData) => dispatch(importToDB(comicData)),
|
||||
[],
|
||||
);
|
||||
|
||||
const comicVineSearchResults = useSelector(
|
||||
(state: RootState) => state.comicInfo.searchResults,
|
||||
@@ -56,20 +67,7 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
||||
<h1 className="title">Search</h1>
|
||||
|
||||
<Form
|
||||
onSubmit={() =>
|
||||
getDCPPSearchResults({
|
||||
query: {
|
||||
pattern: "Iron Man - V1 194",
|
||||
// file_type: "compressed",
|
||||
extensions: ["cbz", "cbr"],
|
||||
},
|
||||
hub_urls: [
|
||||
"adcs://novosibirsk.dc-dev.club:7111/?kp=SHA256/4XFHJFFBFEI2RS75FPRPPXPZMMKPXR764ABVVCC2QGJPQ34SDZGA",
|
||||
"dc.fly-server.ru",
|
||||
],
|
||||
priority: 1,
|
||||
})
|
||||
}
|
||||
onSubmit={getCVSearchResults}
|
||||
initialValues={{
|
||||
...formData,
|
||||
}}
|
||||
@@ -98,20 +96,24 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
||||
{!isNil(comicVineSearchResults.results) &&
|
||||
!isEmpty(comicVineSearchResults.results) ? (
|
||||
<>
|
||||
{comicVineSearchResults.results.map(
|
||||
({ id, name, description, api_detail_url, image }) => {
|
||||
return (
|
||||
<div key={id}>
|
||||
{id} {name}
|
||||
<p>{api_detail_url}</p>
|
||||
<p>{description}</p>
|
||||
<figure>
|
||||
<img src={image.thumb_url} alt="name" />
|
||||
</figure>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
)}
|
||||
{comicVineSearchResults.results.map((result) => {
|
||||
return (
|
||||
<div key={result.id}>
|
||||
{result.id} {result.name}
|
||||
<p>{result.api_detail_url}</p>
|
||||
<p>{result.description}</p>
|
||||
<figure>
|
||||
<img src={result.image.thumb_url} alt="name" />
|
||||
</figure>
|
||||
<button
|
||||
className="button"
|
||||
onClick={() => addToLibrary(result)}
|
||||
>
|
||||
Add to Library
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</>
|
||||
) : (
|
||||
<article className="message is-dark is-half">
|
||||
|
||||
@@ -15,6 +15,12 @@ export const IMS_SOCKET_ERROR = "IMS_SOCKET_ERROR";
|
||||
export const IMS_RAW_IMPORT_SUCCESSFUL = "IMS_RAW_IMPORT_SUCCESSFUL";
|
||||
export const IMS_RAW_IMPORT_FAILED = "IMS_RAW_IMPORT_FAILED";
|
||||
|
||||
export const IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS =
|
||||
"IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS";
|
||||
export const IMS_CV_METADATA_IMPORT_SUCCESSFUL =
|
||||
"IMS_CV_METADATA_IMPORT_SUCCESSFUL";
|
||||
export const IMS_CV_METADATA_IMPORT_FAILED = "IMS_CV_METADATA_IMPORT_FAILED";
|
||||
|
||||
export const IMS_RECENT_COMICS_FETCHED = "IMS_RECENT_COMICS_FETCHED";
|
||||
export const IMS_DATA_FETCH_ERROR = "IMS_DATA_FETCH_ERROR";
|
||||
|
||||
|
||||
@@ -7,11 +7,16 @@ import {
|
||||
IMS_RAW_IMPORT_FAILED,
|
||||
IMS_RECENT_COMICS_FETCHED,
|
||||
IMS_DATA_FETCH_ERROR,
|
||||
IMS_CV_METADATA_IMPORT_SUCCESSFUL,
|
||||
IMS_CV_METADATA_IMPORT_FAILED,
|
||||
IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS,
|
||||
} from "../constants/action-types";
|
||||
const initialState = {
|
||||
dataTransferred: false,
|
||||
comicBookMetadata: [],
|
||||
socketConnected: false,
|
||||
isComicVineMetadataImportInProgress: false,
|
||||
comicVineMetadataImportError: {},
|
||||
rawImportError: {},
|
||||
};
|
||||
|
||||
@@ -44,6 +49,23 @@ function fileOpsReducer(state = initialState, action) {
|
||||
...state,
|
||||
recentComics: action.data,
|
||||
};
|
||||
case IMS_CV_METADATA_IMPORT_SUCCESSFUL:
|
||||
return {
|
||||
...state,
|
||||
isComicVineMetadataImportInProgress: false,
|
||||
comicVineMetadataImportDetails: action.importResult,
|
||||
};
|
||||
case IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS:
|
||||
return {
|
||||
...state,
|
||||
isComicVineMetadataImportInProgress: true,
|
||||
};
|
||||
case IMS_CV_METADATA_IMPORT_FAILED:
|
||||
return {
|
||||
...state,
|
||||
isComicVineMetadataImportInProgress: false,
|
||||
comicVineMetadataImportError: action.importError,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ export const search = async (data: SearchData) => {
|
||||
`search/${instance.id}/hub_search`,
|
||||
data,
|
||||
);
|
||||
return searchQueueInfo;
|
||||
};
|
||||
|
||||
const onSearchSent = async (item, instance, unsubscribe, searchInfo): any => {
|
||||
const onSearchSent = async (item, instance, unsubscribe, searchInfo) => {
|
||||
// Collect the results for 5 seconds
|
||||
await sleep(5000);
|
||||
|
||||
@@ -53,7 +54,6 @@ const onSearchSent = async (item, instance, unsubscribe, searchInfo): any => {
|
||||
// target_directory: item.target_directory,
|
||||
// });
|
||||
}
|
||||
return results;
|
||||
// Remove listener for this search instance
|
||||
unsubscribe();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user