WIP socket.io integration
This commit is contained in:
@@ -30,45 +30,7 @@ export default class ApiService extends Service {
|
|||||||
mergeParams: true,
|
mergeParams: true,
|
||||||
autoAliases: true,
|
autoAliases: true,
|
||||||
|
|
||||||
aliases: {
|
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) {}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
|
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
|
||||||
callingOptions: {},
|
callingOptions: {},
|
||||||
@@ -133,9 +95,15 @@ export default class ApiService extends Service {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.broker
|
this.broker
|
||||||
.call(action, params, opts)
|
.call("import." + action, params, opts)
|
||||||
.then((res) => {
|
.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));
|
.catch((err) => this.logger.error(err));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { DbMixin } from "../mixins/db.mixin";
|
import { DbMixin } from "../mixins/db.mixin";
|
||||||
import Comic from "../models/comic.model";
|
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 {
|
import {
|
||||||
IExtractionOptions,
|
IExtractionOptions,
|
||||||
IFolderData,
|
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: {},
|
methods: {},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user