💽 Wiring up simple mongo import from CV result
This commit is contained in:
@@ -13,8 +13,12 @@ import {
|
|||||||
CV_API_CALL_IN_PROGRESS,
|
CV_API_CALL_IN_PROGRESS,
|
||||||
CV_SEARCH_SUCCESS,
|
CV_SEARCH_SUCCESS,
|
||||||
CV_CLEANUP,
|
CV_CLEANUP,
|
||||||
|
IMS_CV_METADATA_IMPORT_CALL_IN_PROGRESS,
|
||||||
|
IMS_CV_METADATA_IMPORT_SUCCESSFUL,
|
||||||
|
IMS_CV_METADATA_IMPORT_FAILED,
|
||||||
} from "../constants/action-types";
|
} from "../constants/action-types";
|
||||||
import { refineQuery } from "../shared/utils/filenameparser.utils";
|
import { refineQuery } from "../shared/utils/filenameparser.utils";
|
||||||
|
import { extend } from "lodash";
|
||||||
import sortBy from "array-sort-by";
|
import sortBy from "array-sort-by";
|
||||||
|
|
||||||
export async function walkFolder(path: string): Promise<Array<IFolderData>> {
|
export async function walkFolder(path: string): Promise<Array<IFolderData>> {
|
||||||
@@ -80,7 +84,6 @@ export const fetchComicBookMetadata = (options) => async (dispatch) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("comicBookCoverMetadata", (data: IExtractedComicBookCoverFile) => {
|
socket.on("comicBookCoverMetadata", (data: IExtractedComicBookCoverFile) => {
|
||||||
console.log("Recd cover");
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: IMS_COMICBOOK_METADATA_FETCHED,
|
type: IMS_COMICBOOK_METADATA_FETCHED,
|
||||||
data,
|
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) => {
|
export const fetchComicVineMatches = (searchPayload) => (dispatch) => {
|
||||||
try {
|
try {
|
||||||
const issueString = searchPayload.rawFileDetails.name;
|
const issueString = searchPayload.rawFileDetails.name;
|
||||||
|
|||||||
@@ -165,10 +165,12 @@ export const Library = ({}: IComicBookLibraryProps): ReactElement => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
RawFileDetails.propTypes = {
|
RawFileDetails.propTypes = {
|
||||||
name: PropTypes.string,
|
value: PropTypes.shape({
|
||||||
path: PropTypes.string,
|
name: PropTypes.string,
|
||||||
fileSize: PropTypes.number,
|
path: PropTypes.string,
|
||||||
extension: PropTypes.string,
|
fileSize: PropTypes.number,
|
||||||
|
extension: PropTypes.string,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
ImportStatus.propTypes = {
|
ImportStatus.propTypes = {
|
||||||
|
|||||||
@@ -1,13 +1,7 @@
|
|||||||
import React, { useMemo, useCallback, ReactElement } from "react";
|
import React, { useMemo, useCallback, ReactElement } from "react";
|
||||||
import {
|
import { isNil, isEmpty } from "lodash";
|
||||||
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 { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings";
|
import { IExtractedComicBookCoverFile, RootState } from "threetwo-ui-typings";
|
||||||
|
import { importToDB } from "../actions/fileops.actions";
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
||||||
import { search } from "../services/api/SearchApi";
|
import { search } from "../services/api/SearchApi";
|
||||||
@@ -33,7 +27,7 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
|||||||
limit: "10",
|
limit: "10",
|
||||||
offset: "0",
|
offset: "0",
|
||||||
field_list: "id,name,deck,api_detail_url,image,description",
|
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) => {
|
const getDCPPSearchResults = useCallback((searchQuery) => {
|
||||||
search(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(
|
const comicVineSearchResults = useSelector(
|
||||||
(state: RootState) => state.comicInfo.searchResults,
|
(state: RootState) => state.comicInfo.searchResults,
|
||||||
@@ -56,20 +67,7 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
|||||||
<h1 className="title">Search</h1>
|
<h1 className="title">Search</h1>
|
||||||
|
|
||||||
<Form
|
<Form
|
||||||
onSubmit={() =>
|
onSubmit={getCVSearchResults}
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
initialValues={{
|
initialValues={{
|
||||||
...formData,
|
...formData,
|
||||||
}}
|
}}
|
||||||
@@ -98,20 +96,24 @@ export const Search = ({}: ISearchProps): ReactElement => {
|
|||||||
{!isNil(comicVineSearchResults.results) &&
|
{!isNil(comicVineSearchResults.results) &&
|
||||||
!isEmpty(comicVineSearchResults.results) ? (
|
!isEmpty(comicVineSearchResults.results) ? (
|
||||||
<>
|
<>
|
||||||
{comicVineSearchResults.results.map(
|
{comicVineSearchResults.results.map((result) => {
|
||||||
({ id, name, description, api_detail_url, image }) => {
|
return (
|
||||||
return (
|
<div key={result.id}>
|
||||||
<div key={id}>
|
{result.id} {result.name}
|
||||||
{id} {name}
|
<p>{result.api_detail_url}</p>
|
||||||
<p>{api_detail_url}</p>
|
<p>{result.description}</p>
|
||||||
<p>{description}</p>
|
<figure>
|
||||||
<figure>
|
<img src={result.image.thumb_url} alt="name" />
|
||||||
<img src={image.thumb_url} alt="name" />
|
</figure>
|
||||||
</figure>
|
<button
|
||||||
</div>
|
className="button"
|
||||||
);
|
onClick={() => addToLibrary(result)}
|
||||||
},
|
>
|
||||||
)}
|
Add to Library
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<article className="message is-dark is-half">
|
<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_SUCCESSFUL = "IMS_RAW_IMPORT_SUCCESSFUL";
|
||||||
export const IMS_RAW_IMPORT_FAILED = "IMS_RAW_IMPORT_FAILED";
|
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_RECENT_COMICS_FETCHED = "IMS_RECENT_COMICS_FETCHED";
|
||||||
export const IMS_DATA_FETCH_ERROR = "IMS_DATA_FETCH_ERROR";
|
export const IMS_DATA_FETCH_ERROR = "IMS_DATA_FETCH_ERROR";
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,16 @@ import {
|
|||||||
IMS_RAW_IMPORT_FAILED,
|
IMS_RAW_IMPORT_FAILED,
|
||||||
IMS_RECENT_COMICS_FETCHED,
|
IMS_RECENT_COMICS_FETCHED,
|
||||||
IMS_DATA_FETCH_ERROR,
|
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";
|
} from "../constants/action-types";
|
||||||
const initialState = {
|
const initialState = {
|
||||||
dataTransferred: false,
|
dataTransferred: false,
|
||||||
comicBookMetadata: [],
|
comicBookMetadata: [],
|
||||||
socketConnected: false,
|
socketConnected: false,
|
||||||
|
isComicVineMetadataImportInProgress: false,
|
||||||
|
comicVineMetadataImportError: {},
|
||||||
rawImportError: {},
|
rawImportError: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,6 +49,23 @@ function fileOpsReducer(state = initialState, action) {
|
|||||||
...state,
|
...state,
|
||||||
recentComics: action.data,
|
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:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ export const search = async (data: SearchData) => {
|
|||||||
`search/${instance.id}/hub_search`,
|
`search/${instance.id}/hub_search`,
|
||||||
data,
|
data,
|
||||||
);
|
);
|
||||||
|
return searchQueueInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSearchSent = async (item, instance, unsubscribe, searchInfo): any => {
|
const onSearchSent = async (item, instance, unsubscribe, searchInfo) => {
|
||||||
// Collect the results for 5 seconds
|
// Collect the results for 5 seconds
|
||||||
await sleep(5000);
|
await sleep(5000);
|
||||||
|
|
||||||
@@ -53,7 +54,6 @@ const onSearchSent = async (item, instance, unsubscribe, searchInfo): any => {
|
|||||||
// target_directory: item.target_directory,
|
// target_directory: item.target_directory,
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
return results;
|
|
||||||
// Remove listener for this search instance
|
// Remove listener for this search instance
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user