diff --git a/README.md b/README.md index 3a47467..acab490 100644 --- a/README.md +++ b/README.md @@ -42,21 +42,22 @@ This Package uses [viu](https://github.com/atanunq/viu), A rust module uses iter We use that for displaying captcha images on command line for login and bookings as to make your booking flow in a seamless way. -Hence you are required to download the viu executable file related to your OS and Processor Architecture from the [viu release Assets](https://github.com/atanunq/viu/releases/latest) then add the folder where the `viu` is stored to your environment variables. +`irctc-api` automatically installs `viu` binary based on your os and processor architecture, If we could not find your viu binary related to your processor and os, you are required to install `viu` through their standard installation. -Remeber to add the folder path and not the viu.exe file path in your environment variables. +Then provide `viu` binary path in params as + +```json +{ + "train_number": "11020", + "viu":"path/to/binary/viu | path/to/binary/viu.exe" +} +``` ### Notes - Currently this project is designed to accept only UPI Collect request as payment option and other payment modes are not supported as of now. When the payment request is initiated, The command line will display the payment request details such that you need to complete the payment from your UPI mobile App. -- We request to verify whether viu is working or not by giving the below command - -```shell -viu example.jpeg -t -``` - ### Import This Package exports a class named `IRCTC` which contains three functions. diff --git a/docs/api_reference.md b/docs/api_reference.md index 6c85dcb..5212f0b 100644 --- a/docs/api_reference.md +++ b/docs/api_reference.md @@ -120,10 +120,15 @@ console.log(response); - log - Can be any one of the boolean values such as `true | false` - Default value - `false` +- viu + - If you want your custom viu to be executed for captcha image, you can specify your path here + - Default - irctc-api will install viu binary package based on your os and processor architecture + The example input is as follows ```js +// some_book.mjs { "UPI": "9876543210@ybl", "class": "2S", @@ -152,7 +157,8 @@ The example input is as follows } ], "coach":"D1", - "log":true + "log":true, + "viu":"path/to/viu | path/to/viu.exe" }; ``` diff --git a/lib/workings.mjs b/lib/workings.mjs index 9bee929..e0e5a27 100644 --- a/lib/workings.mjs +++ b/lib/workings.mjs @@ -5,7 +5,7 @@ import { writeFileSync,readdirSync } from 'node:fs'; import {dirname,join} from "node:path"; import * as cheerio from 'cheerio'; import querystring from 'querystring'; -import { execFile } from 'node:child_process'; +import { execFileSync } from 'node:child_process'; import { URL,fileURLToPath } from 'node:url'; import {verify_booking_params, initialize_booking_variables, input, base64DecodeUnicode} from './utils.mjs'; import { psg_input_wait, sleep_for_login, sleep_for_availability_check} from "./time_work.mjs"; @@ -72,25 +72,8 @@ class IRCTC{ let imagePath = 'captcha.jpg'; this.log_data("Proceeding for Captcha Answering"); writeFileSync("./"+imagePath, this.captchaQuestion, 'base64'); - const __filename = fileURLToPath(import.meta.url); - const __dirname = dirname(__filename); - const path_l = join(__dirname, "..","bin"); - const files = readdirSync(path_l); - let path_n = ""; - if (files.length === 0) { - throw new Error("Platform not supported, Request you to manually download the viu binary file from rust standard installation page and place it inside this bin folder located in. "+path_l) - } - else{ - path_n = files[0]; - } - const binaryPath = join(path_l, path_n); - execFile(binaryPath, [imagePath,"-t"], (error, stdout, stderr) => { - console.log(`${stdout}\nEnter the Captcha Answer below in this terminal`); - console.log(stderr); - if (error !== null) { - console.log(`exec error: ${error}`); - } - }); + const stdout = execFileSync(this.binaryPath, [imagePath,"-t"]); + console.log(stdout+" \nPlease type the above text and press enter"); this.captcha_answer = await input(''); this.log_data("Received Captcha Answer Input"); await this.send_login(); @@ -708,6 +691,23 @@ class IRCTC{ } async book(params){ this.log_file = new LOG(params.log); + if (params.viu && typeof params.viu === "string"){ + this.binaryPath = params.viu; + } + else{ + const __filename = fileURLToPath(import.meta.url); + const __dirname = dirname(__filename); + const path_l = join(__dirname, "..","bin"); + const files = readdirSync(path_l); + let path_n = ""; + if (files.length === 0) { + throw new Error("Platform not supported, Request you to manually download the viu binary file from rust standard installation page and then after installing\nOption 1: Place the binary file inside this bin folder located in. "+path_l+"\nOption 2: Give viu binary path location in the params as 'viu':'path/to/viu | path/to/viu.exe'") + } + else{ + path_n = files[0]; + } + this.binaryPath = join(path_l, path_n); + } this.logging = params.log; this.params = params; await verify_booking_params(this.params); diff --git a/package-lock.json b/package-lock.json index a8c3544..9b7db49 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "irctc-api", - "version": "2.0.12", + "version": "2.0.13", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "irctc-api", - "version": "2.0.12", + "version": "2.0.13", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { @@ -15,9 +15,6 @@ "cheerio": "^1.0.0-rc.12", "tough-cookie": "^4.1.4" }, - "bin": { - "viu": "bin/viu" - }, "engines": { "node": ">20.0.0", "npm": ">10.0.0" diff --git a/package.json b/package.json index 783c8e3..5670329 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "irctc-api", "description": "An exclusive NodeJs only package built on top of IRCTC Website APIs to book train tickets, managing user profile faster and simpler from anywhere in the world", - "version": "2.0.12", + "version": "2.0.13", "scripts": { "postinstall": "node ./lib/postinstall.mjs", "test": "echo \"Error: no test specified\" && exit 1"