👮🏼♂️ chokidar support
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { Service, ServiceBroker, Context } from "moleculer";
|
||||
import ApiGateway from "moleculer-web";
|
||||
import chokidar from "chokidar";
|
||||
import { logger } from "../utils/logger.utils";
|
||||
import path from "path";
|
||||
import { IExtractionOptions, IFolderData } from "threetwo-ui-typings";
|
||||
export default class ApiService extends Service {
|
||||
public constructor(broker: ServiceBroker) {
|
||||
super(broker);
|
||||
@@ -72,12 +76,50 @@ export default class ApiService extends Service {
|
||||
options: {},
|
||||
},
|
||||
},
|
||||
events: {
|
||||
|
||||
},
|
||||
events: {},
|
||||
|
||||
methods: {},
|
||||
started(): any {
|
||||
const fileWatcher = chokidar.watch(path.resolve("./comics"), {
|
||||
ignored: /(^|[\/\\])\../, // ignore dotfiles
|
||||
persistent: true,
|
||||
ignoreInitial: true,
|
||||
atomic: true,
|
||||
awaitWriteFinish: {
|
||||
stabilityThreshold: 2000,
|
||||
pollInterval: 100,
|
||||
},
|
||||
});
|
||||
fileWatcher
|
||||
.on("add", async (path, stats) => {
|
||||
logger.info(
|
||||
`File ${path} has been added with stats: ${JSON.stringify(
|
||||
stats
|
||||
)}`
|
||||
);
|
||||
const walkedFolders:IFolderData = await broker.call("import.walkFolders", {basePathToWalk: path});
|
||||
const extractionOptions: IExtractionOptions = {
|
||||
extractTarget: "cover",
|
||||
targetExtractionFolder: "./userdata/covers",
|
||||
extractionMode: "single",
|
||||
paginationOptions: {
|
||||
pageLimit: 25,
|
||||
page: 1,
|
||||
},
|
||||
};
|
||||
this.broker.call("import.importComicsToDb", {walkedFolders, extractionOptions });
|
||||
})
|
||||
.on("change", (path, stats) =>
|
||||
logger.info(
|
||||
`File ${path} has been changed. Stats: ${stats}`
|
||||
)
|
||||
)
|
||||
.on("unlink", (path) =>
|
||||
logger.info(`File ${path} has been removed`)
|
||||
)
|
||||
.on("addDir", (path) =>
|
||||
logger.info(`Directory ${path} has been added`)
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { walkFolder } from "../utils/file.utils";
|
||||
import { convertXMLToJSON } from "../utils/xml.utils";
|
||||
import https from "https";
|
||||
import { logger } from "../utils/logger.utils";
|
||||
import { sendRabbitMQ } from "../queue/importQueue";
|
||||
import { sendToRabbitMQ } from "../queue/importQueue";
|
||||
import {
|
||||
IExtractComicBookCoverErrorResponse,
|
||||
IExtractedComicBookCoverFile,
|
||||
@@ -126,7 +126,7 @@ export default class ImportService extends Service {
|
||||
{}
|
||||
);
|
||||
// 3. Send to the queue
|
||||
sendRabbitMQ(
|
||||
sendToRabbitMQ(
|
||||
"comicBookCovers",
|
||||
JSON.stringify({
|
||||
comicBookCoverMetadata,
|
||||
@@ -312,6 +312,14 @@ export default class ImportService extends Service {
|
||||
return await Comic.findById(ctx.params.id);
|
||||
},
|
||||
},
|
||||
axn: {
|
||||
rest: "GET /axn",
|
||||
params: {},
|
||||
async handler(ctx: Context<{path, stats}>) {
|
||||
logger.info(ctx.params);
|
||||
return {"pandurang": "hari"};
|
||||
}
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
getComicVineVolumeMetadata: (apiDetailURL) =>
|
||||
|
||||
Reference in New Issue
Block a user