Skip to content

Feature/secure print - #1836

Open
wayngo wants to merge 22 commits into
devfrom
feature/secure-print
Open

Feature/secure print#1836
wayngo wants to merge 22 commits into
devfrom
feature/secure-print

Conversation

@wayngo

@wayngo wayngo commented Jul 28, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

Comment on lines +208 to +216
if(!user){
throw new Error('user not found'); // checks user
}
if(!Number.isInteger(pagesToPrint) || pagesToPrint <= 0){
throw new Error('invalid number');
}
if (user.pagesPrinted < pagesToPrint) {
throw new Error('no pages remaining');
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of throwing an error just do logger.error here and return early, we dont have to return anything

Comment thread api/main_endpoints/routes/Printer.js Outdated
Comment on lines +121 to +126
const stream = await fs.promises.readFile(assembledPdfFromChunks); // buffer
const pdfDoc = await PDFDocument.load(stream); // load PDF
const numpages = pdfDoc.getPages().length; // get number of pages
const copiesInt = parseInt(copies || 1, 10);
const totalPages = numpages * copiesInt;
await subtractUserPages(user.id, totalPages); // updates users printcount

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this code in the existing try block in axios.post(PRINTER_URL ...

@efar301 efar301 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants