Skip to content

Commit

Permalink
Fix/nsk mrz (#210)
Browse files Browse the repository at this point in the history
* fix: nsk hos-000

* ver

* 18
  • Loading branch information
hajonsoft authored Feb 27, 2024
1 parent 1982d28 commit 8802f50
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hajonsoft-eagle",
"version": "2.6.16",
"version": "2.6.18",
"description": "HAJonSoft node app to submit passengers to visa systems",
"main": "index.js",
"scripts": {
Expand Down
53 changes: 52 additions & 1 deletion src/nsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const gmail = require("./lib/gmail");
const { fetchNusukIMAPOTP } = require("./lib/imap");
const { nusukNationalities: nationalities } = require("./data/nationalities");
const childProcess = require("child_process");
const sharp = require("sharp");


let page;
let data;
Expand Down Expand Up @@ -645,7 +647,7 @@ async function pageContentHandler(currentConfig) {
arabicTitle: "تحميل عينات",
name: "uploadDocumentsCommander",
action: async () => {
await uploadFakePassport();
await pasteSimulatedPassport();
},
},
});
Expand Down Expand Up @@ -1130,6 +1132,55 @@ async function uploadDocuments(selectedTraveler) {
}
}

async function pasteSimulatedPassport() {
const passenger = data.travellers[util.getSelectedTraveler()];
await util.downloadImage(
passenger.images.passport,
getPath(`${passenger.passportNumber}.jpg`)
);
const fontName = "OCRB";
// Text to be added at the bottom
const textLine1 = passenger.codeline.split("\n")[0];
const textLine2 = passenger.codeline.split("\n")[1];
const encodedTextLine1 = textLine1.replace(/</g, "&lt;");
const encodedTextLine2 = textLine2.replace(/</g, "&lt;");

const height = 100;
const mrzImage = `
<svg width="600" height="${height}" xmlns="http://www.w3.org/2000/svg">
<!-- Background rectangle -->
<rect fill="white" x="0" y="0" width="600" height="${height}" />
<text x="40" y="50" font-family="${fontName}" font-size="16" fill="black">
${encodedTextLine1}
</text>
<text x="40" y="75" font-family="${fontName}" font-size="16" fill="black">
${encodedTextLine2}
</text>
</svg>
`;

const passportPathMrz = path.join(
util.passportsFolder,
`${passenger.passportNumber}_mrz.png`
);
const mrzBuffer = Buffer.from(mrzImage);
await sharp(getPath(`${passenger.passportNumber}.jpg`))
.resize(600, 400)
.grayscale()
.composite([
{
input: mrzBuffer,
top: 300,
left: 0,
},
])
.png()
.toFile(passportPathMrz);

await util.commitFile("#passportPhoto", passportPathMrz);

}

async function uploadFakePassport() {
await page.waitForSelector("#personalPhoto");
const blankPhotoPath = path.join(__dirname, "dummy-nusuk-hajj-photo.jpg");
Expand Down

0 comments on commit 8802f50

Please sign in to comment.