🪛 Data transferring over sockets!
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
import { IncomingMessage } from "http";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { Service, ServiceBroker, Context } from "moleculer";
|
||||
import ApiGateway from "moleculer-web";
|
||||
import { getCovers, extractArchive } from "../utils/uncompression.utils";
|
||||
import { map, flatten } from "lodash";
|
||||
import JSONStream from "JSONStream";
|
||||
import { extractArchive } from "../utils/uncompression.utils";
|
||||
import { map } from "lodash";
|
||||
const IO = require("socket.io")();
|
||||
const ss = require("socket.io-stream");
|
||||
const JsonStreamStringify = require("json-stream-stringify");
|
||||
import axios from "axios";
|
||||
const { Writable, Readable } = require("stream");
|
||||
|
||||
export default class ApiService extends Service {
|
||||
public constructor(broker: ServiceBroker) {
|
||||
@@ -34,12 +26,7 @@ export default class ApiService extends Service {
|
||||
mergeParams: true,
|
||||
autoAliases: true,
|
||||
|
||||
aliases: {
|
||||
async "POST getComicCovers"(req, res) {
|
||||
const { extractionOptions, walkedFolders } =
|
||||
req.body;
|
||||
},
|
||||
},
|
||||
aliases: {},
|
||||
|
||||
// Calling options. More info: https://moleculer.services/docs/0.14/moleculer-web.html#Calling-options
|
||||
callingOptions: {},
|
||||
@@ -105,25 +92,20 @@ export default class ApiService extends Service {
|
||||
params
|
||||
);
|
||||
const { extractionOptions, walkedFolders } = params;
|
||||
const stream = ss.createStream();
|
||||
switch (extractionOptions.extractionMode) {
|
||||
case "bulk":
|
||||
map(walkedFolders, async (folder, idx) => {
|
||||
let foo = await extractArchive(
|
||||
extractionOptions,
|
||||
folder
|
||||
);
|
||||
|
||||
let fo = new JsonStreamStringify({
|
||||
foo,
|
||||
});
|
||||
let comicBookCoverMetadata =
|
||||
await extractArchive(
|
||||
extractionOptions,
|
||||
folder
|
||||
);
|
||||
|
||||
client.emit("comicBookCoverMetadata", {
|
||||
data: foo,
|
||||
data: comicBookCoverMetadata,
|
||||
status: "Done!",
|
||||
});
|
||||
});
|
||||
// res.end();
|
||||
|
||||
case "single":
|
||||
return await extractArchive(
|
||||
@@ -141,13 +123,6 @@ export default class ApiService extends Service {
|
||||
data: `${extractionOptions}`,
|
||||
};
|
||||
}
|
||||
|
||||
// this.broker
|
||||
// .call("import." + action, params, opts)
|
||||
// .then((resp) => {
|
||||
// // client.emit("comicBookCoverMetadata", resp);
|
||||
// })
|
||||
// .catch((err) => this.logger.error(err));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -1,33 +1,8 @@
|
||||
"use strict";
|
||||
import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
|
||||
import fs from "fs";
|
||||
import { DbMixin } from "../mixins/db.mixin";
|
||||
import Comic from "../models/comic.model";
|
||||
import { map, flatten, isUndefined } from "lodash";
|
||||
import {
|
||||
extractArchive,
|
||||
getCovers,
|
||||
walkFolder,
|
||||
} from "../utils/uncompression.utils";
|
||||
import {
|
||||
IExtractionOptions,
|
||||
IExtractedComicBookCoverFile,
|
||||
IFolderData,
|
||||
} from "../interfaces/folder.interface";
|
||||
import axios from "axios";
|
||||
import { Readable } from "stream";
|
||||
import through2 from "through2";
|
||||
import oboe from "oboe";
|
||||
import H from "highland";
|
||||
import { stringify } from "highland-json";
|
||||
const JsonStreamStringify = require("json-stream-stringify");
|
||||
const IO = require("socket.io")();
|
||||
const { chain } = require("stream-chain");
|
||||
const { parser } = require("stream-json");
|
||||
const { pick } = require("stream-json/filters/Pick");
|
||||
const { ignore } = require("stream-json/filters/Ignore");
|
||||
const { streamValues } = require("stream-json/streamers/StreamValues");
|
||||
const StreamArray = require("stream-json/streamers/StreamArray");
|
||||
import { walkFolder } from "../utils/uncompression.utils";
|
||||
|
||||
export default class ProductsService extends Service {
|
||||
// @ts-ignore
|
||||
@@ -66,57 +41,6 @@ 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":
|
||||
// map(
|
||||
// ctx.params.walkedFolders,
|
||||
// async (folder, idx) => {
|
||||
// let foo = await extractArchive(
|
||||
// ctx.params
|
||||
// .extractionOptions,
|
||||
// folder
|
||||
// );
|
||||
// // console.log("levar", foo);
|
||||
// let jsonStream =
|
||||
// new JsonStreamStringify({
|
||||
// foo,
|
||||
// });
|
||||
// return jsonStream;
|
||||
// }
|
||||
// );
|
||||
//
|
||||
// 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: {},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user