🧩 Comlink funkiness
This commit is contained in:
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@@ -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}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -33,7 +33,3 @@ export async function extractCoverFromComicBookArchive(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function foo() {
|
|
||||||
return { as: "af" };
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { hot } from "react-hot-loader";
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import axios from "axios";
|
|
||||||
import { withRouter } from "react-router-dom";
|
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { comicinfoAPICall } from "../actions/comicinfo.actions";
|
|
||||||
import { IFolderData } from "../shared/interfaces/comicinfo.interfaces";
|
|
||||||
import * as Comlink from "comlink";
|
import * as Comlink from "comlink";
|
||||||
import WorkerAdd from "../workers/extractCovers.worker";
|
import { wrap, proxy } from "comlink";
|
||||||
interface IProps {
|
interface IProps {
|
||||||
matches: unknown;
|
matches: unknown;
|
||||||
}
|
}
|
||||||
@@ -31,14 +26,16 @@ class Import extends React.Component<IProps, IState> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async startFolderWalk(): Promise<void> {
|
public async startFolderWalk() {
|
||||||
const { importComicBooks } = Comlink.wrap(new WorkerAdd());
|
const multiply = wrap(
|
||||||
const folderWalkResults = await importComicBooks;
|
new Worker(
|
||||||
this.setState({
|
"http://localhost:3000/src/client/workers/extractCovers.worker.js",
|
||||||
folderWalkResults,
|
{ type: "module" },
|
||||||
});
|
),
|
||||||
|
);
|
||||||
|
const sutarfeni = await proxy(multiply);
|
||||||
|
console.log("foo", sutarfeni());
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
10
src/client/workers/extractCovers.worker.js
Normal file
10
src/client/workers/extractCovers.worker.js
Normal file
@@ -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);
|
||||||
@@ -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<IFolderData[]> {
|
|
||||||
// 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;
|
|
||||||
@@ -15,6 +15,7 @@ const port: number = Number(process.env.PORT) || 8050; // set our port
|
|||||||
|
|
||||||
// Send index.html on root request
|
// Send index.html on root request
|
||||||
app.use(express.static("dist"));
|
app.use(express.static("dist"));
|
||||||
|
app.use(express.static("src/client/workers"));
|
||||||
app.get("/", (req: Request, res: Response) => {
|
app.get("/", (req: Request, res: Response) => {
|
||||||
console.log("sending index.html");
|
console.log("sending index.html");
|
||||||
res.sendFile("/dist/index.html");
|
res.sendFile("/dist/index.html");
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ router.route("/getComicCovers").post(async (req: Request, res: Response) => {
|
|||||||
typeof req.body.extractionOptions === "object"
|
typeof req.body.extractionOptions === "object"
|
||||||
? req.body.extractionOptions
|
? req.body.extractionOptions
|
||||||
: {};
|
: {};
|
||||||
const foo = await extractArchive(req.body.extractionOptions);
|
const extractedData = await extractArchive(req.body.extractionOptions);
|
||||||
// const foo = await extractMetadataFromImage(
|
// const foo = await extractMetadataFromImage(
|
||||||
// "./comics/covers/Ghosts and Ruins-001.jpg",
|
// "./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 = await unzip("asd");
|
||||||
// const foo = explodePath("Chapter Three/HELLBOY - The Chained Coffin - 069.jpg");
|
// const foo = explodePath("Chapter Three/HELLBOY - The Chained Coffin - 069.jpg");
|
||||||
res.json({
|
res.json({
|
||||||
jagan: "trupti",
|
extractedData,
|
||||||
foo,
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
"outDir": "./dist/",
|
"outDir": "./dist/",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"lib": [
|
"lib": [
|
||||||
"DOM"
|
"DOM",
|
||||||
|
"webworker"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"settings": {
|
"settings": {
|
||||||
|
|||||||
Reference in New Issue
Block a user