Skip to content

Commit

Permalink
Merge pull request #1680 from Fdawgs/perf/toot-toot
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Oct 1, 2023
2 parents caff920 + 27245e0 commit c6c0965
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/plugins/embed-html-images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function plugin(server, options) {

await Promise.all(
Array.from(images, (image) => {
const imgForm = extname(image.src).substring(1);
const imgForm = extname(image.src).slice(1);

return readFile(joinSafe(directory, image.src), "base64").then(
(imageAsBase64) =>
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/pdf-to-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function plugin(server, options) {
// Create temp directory if missing
await mkdir(directory, { recursive: true });

const pdfToHtmlAcceptedParams = [
const pdfToHtmlAcceptedParams = new Set([
"exchangePdfLinks",
"extractHidden",
"firstPageToConvert",
Expand All @@ -51,7 +51,7 @@ async function plugin(server, options) {
"userPassword",
"wordBreakThreshold",
"zoom",
];
]);

server
.decorateRequest("conversionResults", null)
Expand Down Expand Up @@ -97,7 +97,7 @@ async function plugin(server, options) {
*/
const query = { ...req.query };
Object.keys(query).forEach((value) => {
if (!pdfToHtmlAcceptedParams.includes(value)) {
if (!pdfToHtmlAcceptedParams.has(value)) {
delete query[value];
} else {
/**
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/pdf-to-txt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ async function plugin(server, options) {
// Create temp directory if missing
await mkdir(directory, { recursive: true });

const pdfToCairoAcceptedParams = [
const pdfToCairoAcceptedParams = new Set([
"cropHeight",
"cropWidth",
"cropXAxis",
"cropYAxis",
"firstPageToConvert",
"lastPageToConvert",
];
]);

const pdfToTxtAcceptedParams = [
const pdfToTxtAcceptedParams = new Set([
"boundingBoxXhtml",
"boundingBoxXhtmlLayout",
"cropHeight",
Expand All @@ -64,7 +64,7 @@ async function plugin(server, options) {
"ownerPassword",
"rawLayout",
"userPassword",
];
]);

server
.decorateRequest("conversionResults", null)
Expand Down Expand Up @@ -128,7 +128,7 @@ async function plugin(server, options) {
if (query.ocr === true && server.tesseract) {
// Prune params that pdfToCairo cannot accept
Object.keys(query).forEach((value) => {
if (!pdfToCairoAcceptedParams.includes(value)) {
if (!pdfToCairoAcceptedParams.has(value)) {
delete query[value];
}
});
Expand Down Expand Up @@ -186,7 +186,7 @@ async function plugin(server, options) {
} else {
// Prune params that pdfToTxt cannot accept
Object.keys(query).forEach((value) => {
if (!pdfToTxtAcceptedParams.includes(value)) {
if (!pdfToTxtAcceptedParams.has(value)) {
delete query[value];
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/tidy-css/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function plugin(server) {
);
}

if (styleRule.selectorText.substring(0, 3) === "div") {
if (styleRule.selectorText.slice(0, 3) === "div") {
/**
* Stop pages overrunning the next page, leading to overlapping text.
* "page-break-inside" is a legacy property, replaced by "break-inside".
Expand Down
10 changes: 3 additions & 7 deletions src/routes/pdf/txt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ async function route(server, options) {
}
},
handler: async (req) => {
let result;
if (
const result =
req.query.boundingBoxXhtml ||
req.query.boundingBoxXhtmlLayout ||
req.query.generateHtmlMetaFile
) {
result = await server.tidyHtml(req.conversionResults.body);
} else {
result = req.conversionResults.body;
}
? await server.tidyHtml(req.conversionResults.body)
: req.conversionResults.body;
return result;
},
});
Expand Down

0 comments on commit c6c0965

Please sign in to comment.