🧩 Comlink funkiness

This commit is contained in:
2021-04-26 13:46:05 -07:00
parent 857f0ffe4f
commit 0701ef19f8
8 changed files with 40 additions and 44 deletions

15
.vscode/launch.json vendored Normal file
View 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}"
}
]
}

View File

@@ -33,7 +33,3 @@ export async function extractCoverFromComicBookArchive(
},
});
}
export async function foo() {
return { as: "af" };
}

View File

@@ -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<IProps, IState> {
});
}
public async startFolderWalk(): Promise<void> {
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 (
<div>

View 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);

View File

@@ -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;

View File

@@ -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");

View File

@@ -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,
});
});

View File

@@ -10,7 +10,8 @@
"outDir": "./dist/",
"skipLibCheck": true,
"lib": [
"DOM"
"DOM",
"webworker"
]
},
"settings": {