Removal of the function that creates the accounts
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
const ExcelJS = require('exceljs');
|
const ExcelJS = require('exceljs');
|
||||||
const { PDFParse } = require('pdf-parse');
|
const { PDFParse } = require('pdf-parse');
|
||||||
const { PDFDocument } = require('pdf-lib');
|
const { PDFDocument } = require('pdf-lib');
|
||||||
const readline = require('node:readline/promises');
|
|
||||||
const { stdin: input, stdout: output } = require('node:process');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
@@ -51,13 +49,13 @@ function escapeSoql(str) {
|
|||||||
// the pdf files contain the identifying ids of the users such as 'Codice Fiscale' (CF) and we use them to attach
|
// the pdf files contain the identifying ids of the users such as 'Codice Fiscale' (CF) and we use them to attach
|
||||||
// the page/pages to the specific account that has that id. If CFs are not available we search based on the
|
// the page/pages to the specific account that has that id. If CFs are not available we search based on the
|
||||||
// name an lastname of the user
|
// name an lastname of the user
|
||||||
async function attachPdfToAccount(sfdc, temFiles) {
|
async function attachPdfToAccount(sfdc, tempFiles) {
|
||||||
let parser;
|
let parser;
|
||||||
try {
|
try {
|
||||||
let contentVersion;
|
let contentVersion;
|
||||||
for (let i = 0; i < temFiles.length; i++) {
|
for (let i = 0; i < tempFiles.length; i++) {
|
||||||
// 1. Read the local PDF file and convert it to Base64
|
// 1. Read the local PDF file and convert it to Base64
|
||||||
const pdfBuffer = fs.readFileSync(temFiles[i]);
|
const pdfBuffer = fs.readFileSync(tempFiles[i]);
|
||||||
const base64Pdf = pdfBuffer.toString('base64');
|
const base64Pdf = pdfBuffer.toString('base64');
|
||||||
parser = new PDFParse({ data: pdfBuffer });
|
parser = new PDFParse({ data: pdfBuffer });
|
||||||
try {
|
try {
|
||||||
@@ -238,7 +236,6 @@ async function splitPDF(numRows, inputFile, tempFiles) {
|
|||||||
let parser;
|
let parser;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// 1. we use pdfParse to read and extract the content of a pdf file
|
// 1. we use pdfParse to read and extract the content of a pdf file
|
||||||
const existingPdfBytes = fs.readFileSync(inputFile);
|
const existingPdfBytes = fs.readFileSync(inputFile);
|
||||||
parser = new PDFParse({ data: existingPdfBytes });
|
parser = new PDFParse({ data: existingPdfBytes });
|
||||||
@@ -264,12 +261,10 @@ async function splitPDF(numRows, inputFile, tempFiles) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (let i = 0; i < pagesNumber; i++) {
|
for (let i = 0; i < pagesNumber; i++) {
|
||||||
/*console.log(`--- PAGE ${i + 1} ---`);
|
|
||||||
console.log(result.pages[i].text);
|
|
||||||
console.log("\n");*/
|
|
||||||
await processPage(srcPdf, i, tempFiles); // Pass 0-based index i
|
await processPage(srcPdf, i, tempFiles); // Pass 0-based index i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tempFiles;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error(`Error processing the pdf file: `, error);
|
console.error(`Error processing the pdf file: `, error);
|
||||||
@@ -301,35 +296,13 @@ async function main() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tempFilePath = []; // contains the temp files
|
const tempFilePath = []; // contains the temporary files
|
||||||
let resultExcel;
|
let resultExcel, resultPdf;
|
||||||
try {
|
try {
|
||||||
resultExcel = await splitExcelFile(excelFile);
|
resultExcel = await splitExcelFile(excelFile);
|
||||||
await splitPDF(resultExcel.numRows, pdfFile, tempFilePath);
|
resultPdf = await splitPDF(resultExcel.numRows, pdfFile, tempFilePath);
|
||||||
const rl = readline.createInterface({ input, output });
|
|
||||||
let reply = '';
|
|
||||||
|
|
||||||
try {
|
|
||||||
while(!reply) {
|
|
||||||
const response = await rl.question('Do you want to create accounts or upload pages (accounts/pages)? ');
|
|
||||||
reply = response.trim();
|
|
||||||
|
|
||||||
if (!reply) {
|
|
||||||
console.log('Please try again!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reply === 'accounts') {
|
|
||||||
await uploadUserAccount(resultExcel.data);
|
|
||||||
}
|
|
||||||
else if (reply === 'pages') {
|
|
||||||
await initializeSalesforceConnection();
|
await initializeSalesforceConnection();
|
||||||
await attachPdfToAccount(sfdc, tempFilePath);
|
await attachPdfToAccount(sfdc, resultPdf);
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
rl.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error('An error occurred in main: ', err);
|
console.error('An error occurred in main: ', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user