🍔 Parameterizing code
This commit is contained in:
@@ -5,13 +5,7 @@ import axios from "axios";
|
|||||||
import { withRouter } from "react-router-dom";
|
import { withRouter } from "react-router-dom";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
||||||
import MatchResult from "./MatchResult";
|
import { IFolderData } from "../shared/interfaces/comicinfo.interfaces";
|
||||||
import {
|
|
||||||
IFolderData,
|
|
||||||
IComicVineSearchMatch,
|
|
||||||
} from "../shared/interfaces/comicinfo.interfaces";
|
|
||||||
import { folderWalk } from "../shared/utils/folder.utils";
|
|
||||||
// import {} from "../constants/comicvine.mock";
|
|
||||||
import * as Comlink from "comlink";
|
import * as Comlink from "comlink";
|
||||||
import WorkerAdd from "../workers/extractCovers.worker";
|
import WorkerAdd from "../workers/extractCovers.worker";
|
||||||
interface IProps {
|
interface IProps {
|
||||||
@@ -26,7 +20,7 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
constructor(props: IProps) {
|
constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
folderWalkResults: undefined,
|
folderWalkResults: [],
|
||||||
searchPaneIndex: undefined,
|
searchPaneIndex: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -37,16 +31,9 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async init() {
|
|
||||||
// WebWorkers use `postMessage` and therefore work with Comlink.
|
|
||||||
const { add } = Comlink.wrap(new WorkerAdd());
|
|
||||||
const res = await add(1, 3);
|
|
||||||
console.log(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async startFolderWalk(): Promise<void> {
|
public async startFolderWalk(): Promise<void> {
|
||||||
this.init();
|
const { importComicBooks } = Comlink.wrap(new WorkerAdd());
|
||||||
const folderWalkResults = await folderWalk();
|
const folderWalkResults = await importComicBooks;
|
||||||
this.setState({
|
this.setState({
|
||||||
folderWalkResults,
|
folderWalkResults,
|
||||||
});
|
});
|
||||||
@@ -96,61 +83,9 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
</p>
|
</p>
|
||||||
{/* Folder walk results */}
|
{/* Folder walk results */}
|
||||||
{!_.isUndefined(this.state.folderWalkResults) ? (
|
{!_.isUndefined(this.state.folderWalkResults) ? (
|
||||||
<table className="table">
|
<>
|
||||||
<thead>
|
<div>poopie</div>
|
||||||
<tr>
|
</>
|
||||||
<th>Name</th>
|
|
||||||
<th>Format</th>
|
|
||||||
<th>Is File</th>
|
|
||||||
</tr>
|
|
||||||
{!_.isUndefined(this.state.folderWalkResults) &&
|
|
||||||
this.state.folderWalkResults.map((result, idx) => (
|
|
||||||
<tr key={idx}>
|
|
||||||
<td>
|
|
||||||
{!result.isLink && !result.isFile ? (
|
|
||||||
<span className="icon-text">
|
|
||||||
<span className="icon">
|
|
||||||
<i className="fas fa-folder"></i>
|
|
||||||
</span>
|
|
||||||
<span>{result.name}</span>
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="ml-5">{result.name}</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{this.state.searchPaneIndex === idx &&
|
|
||||||
!_.isUndefined(this.props.matches) ? (
|
|
||||||
<MatchResult
|
|
||||||
queryData={result}
|
|
||||||
matchData={this.props.matches}
|
|
||||||
visible={true}
|
|
||||||
/>
|
|
||||||
) : null}
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
{!_.isEmpty(result.extension) ? (
|
|
||||||
<span className="tag is-info">
|
|
||||||
{result.extension}
|
|
||||||
</span>
|
|
||||||
) : null}
|
|
||||||
</td>
|
|
||||||
<td>{result.isFile.toString()}</td>
|
|
||||||
<td>
|
|
||||||
<button
|
|
||||||
key={idx}
|
|
||||||
className="button is-small is-primary is-outlined"
|
|
||||||
onClick={(e) => {
|
|
||||||
this.props.findMatches(e, result);
|
|
||||||
this.toggleSearchResultsPane(idx);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Find Match
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</thead>
|
|
||||||
</table>
|
|
||||||
) : null}
|
) : null}
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
@@ -158,29 +93,14 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state: IState) {
|
||||||
return {
|
return {
|
||||||
matches: state.comicInfo.searchResults,
|
// matches: state.comicInfo.searchResults,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
findMatches(e, results) {
|
name: "rishi",
|
||||||
dispatch(
|
|
||||||
comicinfoAPICall({
|
|
||||||
callURIAction: "search",
|
|
||||||
callMethod: "get",
|
|
||||||
callParams: {
|
|
||||||
format: "json",
|
|
||||||
query: results.name,
|
|
||||||
limit: 10,
|
|
||||||
offset: 5,
|
|
||||||
sort: "name:asc",
|
|
||||||
resources: "issue",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(Import);
|
export default connect(mapStateToProps, mapDispatchToProps)(Import);
|
||||||
|
|||||||
@@ -25,6 +25,65 @@ class MatchResult extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
<table className="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Format</th>
|
||||||
|
<th>Is File</th>
|
||||||
|
</tr>
|
||||||
|
{!_.isUndefined(this.state.folderWalkResults) &&
|
||||||
|
this.state.folderWalkResults.map((result, idx) => (
|
||||||
|
<tr key={idx}>
|
||||||
|
<td>
|
||||||
|
{!result.isLink && !result.isFile ? (
|
||||||
|
<span className="icon-text">
|
||||||
|
<span className="icon">
|
||||||
|
<i className="fas fa-folder"></i>
|
||||||
|
</span>
|
||||||
|
<span>{result.name}</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="ml-5">{result.name}</span>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{this.state.searchPaneIndex === idx &&
|
||||||
|
!_.isUndefined(this.props.matches) ? (
|
||||||
|
<MatchResult
|
||||||
|
queryData={result}
|
||||||
|
matchData={this.props.matches}
|
||||||
|
visible={true}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{!_.isEmpty(result.extension) ? (
|
||||||
|
<span className="tag is-info">
|
||||||
|
{result.extension}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</td>
|
||||||
|
<td>{result.isFile.toString()}</td>
|
||||||
|
<td>
|
||||||
|
<button
|
||||||
|
key={idx}
|
||||||
|
className="button is-small is-primary is-outlined"
|
||||||
|
onClick={(e) => {
|
||||||
|
this.props.findMatches(e, result);
|
||||||
|
this.toggleSearchResultsPane(idx);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Find Match
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</thead>
|
||||||
|
</table>
|
||||||
|
*/
|
||||||
|
}
|
||||||
return this.props.visible ? (
|
return this.props.visible ? (
|
||||||
<div>
|
<div>
|
||||||
<h3>Matches</h3>
|
<h3>Matches</h3>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import * as Comlink from "comlink";
|
import * as Comlink from "comlink";
|
||||||
import { walkFolder } from "../actions/fileops.actions";
|
import { walkFolder } from "../actions/fileops.actions";
|
||||||
import { IExtractionOptions } from "../../server/interfaces/folder.interface";
|
import { IExtractionOptions } from "../../server/interfaces/folder.interface";
|
||||||
|
import { IFolderData } from "../shared/interfaces/comicinfo.interfaces";
|
||||||
|
|
||||||
async function importComicBooks() {
|
async function importComicBooks(): Promise<IFolderData[]> {
|
||||||
// 1. Walk the folder structure
|
// 1. Walk the folder structure
|
||||||
// 2. Scan for .cbz, .cbr
|
// 2. Scan for .cbz, .cbr
|
||||||
// 3. extract cover image
|
// 3. extract cover image
|
||||||
@@ -12,6 +13,7 @@ async function importComicBooks() {
|
|||||||
// 6. Save model to mongo
|
// 6. Save model to mongo
|
||||||
|
|
||||||
const fileObjects = await walkFolder("./comics");
|
const fileObjects = await walkFolder("./comics");
|
||||||
|
return fileObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
Comlink.expose({
|
Comlink.expose({
|
||||||
|
|||||||
@@ -7,17 +7,14 @@ import {
|
|||||||
extractMetadataFromImage,
|
extractMetadataFromImage,
|
||||||
explodePath,
|
explodePath,
|
||||||
} from "../../utils/fs.utils";
|
} from "../../utils/fs.utils";
|
||||||
|
import { IExtractionOptions } from "../../interfaces/folder.interface";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
||||||
const options = {
|
typeof req.body.extractionOptions === "object"
|
||||||
name: "30 Days of Night # 30 äíåé íî÷è # 01-001",
|
? req.body.extractionOptions
|
||||||
extension: ".cbz",
|
: {};
|
||||||
containedIn: "comics",
|
const foo = await extractArchive(req.body.extractionOptions);
|
||||||
isFile: true,
|
|
||||||
isLink: false,
|
|
||||||
};
|
|
||||||
const foo = await extractArchive(options);
|
|
||||||
// const foo = await extractMetadataFromImage(
|
// const foo = await extractMetadataFromImage(
|
||||||
// "./comics/covers/Ghosts and Ruins-001.jpg",
|
// "./comics/covers/Ghosts and Ruins-001.jpg",
|
||||||
// );
|
// );
|
||||||
|
|||||||
Reference in New Issue
Block a user