Skip to content

Commit

Permalink
refactor(plugins): allow temp file prefixes to be configured (#1299)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Mar 3, 2023
1 parent 50bb545 commit dde4fef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/plugins/pdf-to-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const parseString = require("../../utils/parse-string");
* for options.
* @param {string} options.tempDir - Directory for temporarily storing
* files during conversion.
* @param {string} [options.tempFilePrefix="docsmith_pdf-to-html"] - Prefix for temporary file names.
*/
async function plugin(server, options) {
const directory = path.normalizeTrim(options.tempDir);
Expand Down Expand Up @@ -89,6 +90,7 @@ async function plugin(server, options) {
outputEncoding: "UTF-8",
singlePage: true,
},
tempFilePrefix: "docsmith_pdf-to-html",
...options,
};

Expand All @@ -111,7 +113,7 @@ async function plugin(server, options) {
Object.assign(config.pdfToHtmlOptions, query);

// Build temporary file for Poppler to write to, and following plugins to read from
const id = `docsmith_pdf-to-html_${randomUUID()}`;
const id = `${config.tempFilePrefix}_${randomUUID()}`;
const tempFile = path.joinSafe(directory, id);
req.conversionResults.docLocation = {
directory,
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/pdf-to-txt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const parseString = require("../../utils/parse-string");
* for options.
* @param {string} options.tempDir - Directory for temporarily storing
* files during conversion. Required for OCR.
* @param {string} [options.tempFilePrefix="docsmith_pdf-to-txt"] - Prefix for temporary file names.
*/
async function plugin(server, options) {
const directory = path.normalizeTrim(options.tempDir);
Expand Down Expand Up @@ -105,6 +106,7 @@ async function plugin(server, options) {
// Define any default settings the plugin should have to get up and running
const config = {
pdfToTxtOptions: { outputEncoding: "UTF-8" },
tempFilePrefix: "docsmith_pdf-to-txt",
...options,
};

Expand Down Expand Up @@ -132,7 +134,7 @@ async function plugin(server, options) {
});

// Build temporary file for Poppler to write to, and following plugins to read from
const id = `docsmith_pdf-to-txt_${randomUUID()}`;
const id = `${config.tempFilePrefix}_${randomUUID()}`;
const tempFile = path.joinSafe(directory, id);
req.conversionResults.docLocation = {
directory,
Expand Down

0 comments on commit dde4fef

Please sign in to comment.