WIP socket.io integration

This commit is contained in:
2021-05-18 21:38:28 -07:00
parent c6be5de396
commit a608bc5f51
2 changed files with 61 additions and 42 deletions

View File

@@ -30,45 +30,7 @@ export default class ApiService extends Service {
mergeParams: true,
autoAliases: true,
aliases: {
async "POST getComicCovers"(req, res) {
console.log(req.body);
try {
const { extractionOptions, walkedFolders } =
req.body;
switch (extractionOptions.extractionMode) {
case "bulk":
const extractedDataPromises = map(
walkedFolders,
async (folder) =>
await extractArchive(
extractionOptions,
folder
)
);
return Promise.all(
extractedDataPromises
).then((data) => flatten(data));
case "single":
return await extractArchive(
extractionOptions,
walkedFolders[0]
);
default:
console.log(
"Unknown extraction mode selected."
);
return {
message:
"Unknown extraction mode selected.",
errorCode: "90",
data: `${extractionOptions}`,
};
}
res.end();
} catch (error) {}
},
},
aliases: {},
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
callingOptions: {},
@@ -133,9 +95,15 @@ export default class ApiService extends Service {
);
this.broker
.call(action, params, opts)
.call("import." + action, params, opts)
.then((res) => {
if (done) done(res);
client.emit("hello", "world");
console.log(client);
console.log("DONE");
client.emit("comicBookCoverMetadata", res);
done(res);
})
.catch((err) => this.logger.error(err));
});

View File

@@ -3,7 +3,12 @@ import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
import fs from "fs";
import { DbMixin } from "../mixins/db.mixin";
import Comic from "../models/comic.model";
import { walkFolder, getCovers } from "../utils/uncompression.utils";
import { map, flatten } from "lodash";
import {
extractArchive,
getCovers,
walkFolder,
} from "../utils/uncompression.utils";
import {
IExtractionOptions,
IFolderData,
@@ -53,6 +58,52 @@ export default class ProductsService extends Service {
);
},
},
getComicCovers: {
rest: "POST /getComicCovers",
params: {
extractionOptions: "object",
walkedFolders: "array",
},
async handler(
ctx: Context<{
extractionOptions: IExtractionOptions;
walkedFolders: IFolderData[];
}>
) {
switch (
ctx.params.extractionOptions.extractionMode
) {
case "bulk":
const extractedDataPromises = map(
ctx.params.walkedFolders,
async (folder) =>
await extractArchive(
ctx.params
.extractionOptions,
folder
)
);
return Promise.all(
extractedDataPromises
).then((data) => flatten(data));
case "single":
return await extractArchive(
ctx.params.extractionOptions,
ctx.params.walkedFolders[0]
);
default:
console.log(
"Unknown extraction mode selected."
);
return {
message:
"Unknown extraction mode selected.",
errorCode: "90",
data: `${ctx.params.extractionOptions}`,
};
}
},
},
},
methods: {},
},