🚶🏽 Added walkFolder endpoint

Signed-off-by: Rishi Ghan <rishi.ghan@gmail.com>
This commit is contained in:
2021-05-09 11:57:00 -07:00
parent 94bd9bd1a6
commit 6c12700957

View File

@@ -1,24 +1,20 @@
"use strict"; "use strict";
import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer"; import { Context, Service, ServiceBroker, ServiceSchema } from "moleculer";
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 { import {
walkFolder, walkFolder,
extractArchive,
getCovers, getCovers,
} from "../utils/uncompression.utils"; } from "../utils/uncompression.utils";
import { import {
IExtractionOptions, IExtractionOptions,
IFolderData, IFolderData,
IFolderResponse,
} from "../interfaces/folder.interface"; } from "../interfaces/folder.interface";
export default class ProductsService extends Service { export default class ProductsService extends Service {
// @ts-ignore // @ts-ignore
public constructor(public broker: ServiceBroker, schema: ServiceSchema<{}> = {}) { public constructor(public broker: ServiceBroker, schema: ServiceSchema<{}> = {}) {
super(broker); super(broker);
console.log(DbMixin);
this.parseServiceSchema( this.parseServiceSchema(
Service.mergeSchemas( Service.mergeSchemas(
{ {
@@ -36,17 +32,14 @@ export default class ProductsService extends Service {
}, },
hooks: {}, hooks: {},
actions: { actions: {
hello: { walkFolders: {
rest: "POST /hello", rest: "POST /walkFolders",
params: { params: {
id: "string", basePathToWalk: "string",
},
/** @param {Context} ctx */
async handler(
ctx: Context<{ id: string; value: number }>
) {
return { koo: "loo" };
}, },
async handler(ctx: Context<{ basePathToWalk: string}>) {
return await walkFolder(ctx.params.basePathToWalk);
}
}, },
getComicCovers: { getComicCovers: {
rest: "POST /getComicCovers", rest: "POST /getComicCovers",
@@ -55,19 +48,17 @@ export default class ProductsService extends Service {
walkedFolders: "array", walkedFolders: "array",
}, },
async handler( async handler(
ctx: Context<{ ctx: Context<{
extractionOptions: IExtractionOptions; extractionOptions: IExtractionOptions;
walkedFolders: IFolderData[]; walkedFolders: IFolderData[];
}> }>
) { ) {
console.log(ctx.params); return await getCovers(
const foo = await getCovers(
ctx.params.extractionOptions, ctx.params.extractionOptions,
ctx.params.walkedFolders ctx.params.walkedFolders
); );
return foo;
}, },
}, },
}, },