diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7a9dfa0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/src/client/actions/fileops.actions.tsx b/src/client/actions/fileops.actions.tsx index c625517..6b0a216 100644 --- a/src/client/actions/fileops.actions.tsx +++ b/src/client/actions/fileops.actions.tsx @@ -33,7 +33,3 @@ export async function extractCoverFromComicBookArchive( }, }); } - -export async function foo() { - return { as: "af" }; -} diff --git a/src/client/components/Import.tsx b/src/client/components/Import.tsx index 7bc0717..68af12c 100644 --- a/src/client/components/Import.tsx +++ b/src/client/components/Import.tsx @@ -1,13 +1,8 @@ import * as React from "react"; -import { hot } from "react-hot-loader"; import _ from "lodash"; -import axios from "axios"; -import { withRouter } from "react-router-dom"; import { connect } from "react-redux"; -import { comicinfoAPICall } from "../actions/comicinfo.actions"; -import { IFolderData } from "../shared/interfaces/comicinfo.interfaces"; import * as Comlink from "comlink"; -import WorkerAdd from "../workers/extractCovers.worker"; +import { wrap, proxy } from "comlink"; interface IProps { matches: unknown; } @@ -31,14 +26,16 @@ class Import extends React.Component { }); } - public async startFolderWalk(): Promise { - const { importComicBooks } = Comlink.wrap(new WorkerAdd()); - const folderWalkResults = await importComicBooks; - this.setState({ - folderWalkResults, - }); + public async startFolderWalk() { + const multiply = wrap( + new Worker( + "http://localhost:3000/src/client/workers/extractCovers.worker.js", + { type: "module" }, + ), + ); + const sutarfeni = await proxy(multiply); + console.log("foo", sutarfeni()); } - public render() { return (
diff --git a/src/client/workers/extractCovers.worker.js b/src/client/workers/extractCovers.worker.js new file mode 100644 index 0000000..c66d552 --- /dev/null +++ b/src/client/workers/extractCovers.worker.js @@ -0,0 +1,10 @@ +import * as Comlink from "comlink"; +// importScripts("../../../node_modules/comlink/dist/umd/comlink.js"); +// import { walkFolder } from "../actions/fileops.actions"; +console.log("asdad"); +const comicBookImportProcessor = () => { + // console.log(walkFolder); + return "foo"; +}; + +Comlink.expose(comicBookImportProcessor); diff --git a/src/client/workers/extractCovers.worker.ts b/src/client/workers/extractCovers.worker.ts deleted file mode 100644 index 53838f7..0000000 --- a/src/client/workers/extractCovers.worker.ts +++ /dev/null @@ -1,23 +0,0 @@ -import * as Comlink from "comlink"; -import { walkFolder } from "../actions/fileops.actions"; -import { IExtractionOptions } from "../../server/interfaces/folder.interface"; -import { IFolderData } from "../shared/interfaces/comicinfo.interfaces"; - -async function importComicBooks(): Promise { - // 1. Walk the folder structure - // 2. Scan for .cbz, .cbr - // 3. extract cover image - // 4. Calculate image hash - // 5. Get metadata, add to data model - // 5. Save cover to disk - // 6. Save model to mongo - - const fileObjects = await walkFolder("./comics"); - return fileObjects; -} - -Comlink.expose({ - importComicBooks, -}); - -export default null as any; diff --git a/src/server/index.ts b/src/server/index.ts index dc36b90..c0c61fd 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -15,6 +15,7 @@ const port: number = Number(process.env.PORT) || 8050; // set our port // Send index.html on root request app.use(express.static("dist")); +app.use(express.static("src/client/workers")); app.get("/", (req: Request, res: Response) => { console.log("sending index.html"); res.sendFile("/dist/index.html"); diff --git a/src/server/route/routes/importComics.routes.ts b/src/server/route/routes/importComics.routes.ts index 8201da7..e810f21 100644 --- a/src/server/route/routes/importComics.routes.ts +++ b/src/server/route/routes/importComics.routes.ts @@ -14,7 +14,7 @@ router.route("/getComicCovers").post(async (req: Request, res: Response) => { typeof req.body.extractionOptions === "object" ? req.body.extractionOptions : {}; - const foo = await extractArchive(req.body.extractionOptions); + const extractedData = await extractArchive(req.body.extractionOptions); // const foo = await extractMetadataFromImage( // "./comics/covers/Ghosts and Ruins-001.jpg", // ); @@ -22,8 +22,7 @@ router.route("/getComicCovers").post(async (req: Request, res: Response) => { // const foo = await unzip("asd"); // const foo = explodePath("Chapter Three/HELLBOY - The Chained Coffin - 069.jpg"); res.json({ - jagan: "trupti", - foo, + extractedData, }); }); diff --git a/tsconfig.json b/tsconfig.json index 582a32b..d01a1d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "outDir": "./dist/", "skipLibCheck": true, "lib": [ - "DOM" + "DOM", + "webworker" ] }, "settings": {