Skip to content

Commit

Permalink
refactor: remove POPPLER_BINARY_PATH env variable
Browse files Browse the repository at this point in the history
node-poppler 7.2.0 now detects from path
  • Loading branch information
Fdawgs committed Mar 13, 2024
1 parent 19979b3 commit 93e3e11
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 26 deletions.
5 changes: 0 additions & 5 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ REQ_BODY_MAX_BYTES=
# Leaving empty will disable bearer token auth
AUTH_BEARER_TOKEN_ARRAY=

### BINARY PATHS ##########################################

# Mandatory for Linux deployments, Windows/macOS binaries already present in node-poppler module
POPPLER_BINARY_PATH=

### OCR ###################################################

# Expects true or false.
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ jobs:
HOMEBREW_NO_ANALYTICS: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1
POPPLER_BINARY_PATH: /usr/local/bin
run: |
brew install unrtf poppler
cp .env.template .env
Expand All @@ -135,8 +134,6 @@ jobs:
- name: Run Ubuntu tests
if: matrix.os == 'ubuntu-latest'
env:
POPPLER_BINARY_PATH: /usr/bin
run: |
sudo apt-get -y install poppler-data poppler-utils unrtf
cp .env.template .env
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ services:
LOG_ROTATION_FILENAME:
NODE_ENV: production
HOST: 0.0.0.0
POPPLER_BINARY_PATH: /usr/bin/
healthcheck:
test: curl "localhost:${PORT:-3000}/admin/healthcheck"
interval: 60s
Expand Down
6 changes: 0 additions & 6 deletions src/config/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ describe("Configuration", () => {
const OCR_ENABLED = "";
const OCR_LANGUAGES = "";
const OCR_WORKERS = "";
const POPPLER_BINARY_PATH = "";

Object.assign(process.env, {
HOST,
Expand All @@ -77,7 +76,6 @@ describe("Configuration", () => {
OCR_ENABLED,
OCR_LANGUAGES,
OCR_WORKERS,
POPPLER_BINARY_PATH,
});

const config = await getConfig();
Expand Down Expand Up @@ -135,7 +133,6 @@ describe("Configuration", () => {
});

expect(config.poppler).toStrictEqual({
binPath: POPPLER_BINARY_PATH,
tempDir,
});

Expand Down Expand Up @@ -213,7 +210,6 @@ describe("Configuration", () => {
const OCR_ENABLED = true;
const OCR_LANGUAGES = "cym";
const OCR_WORKERS = 1;
const POPPLER_BINARY_PATH = "/usr/bin";

Object.assign(process.env, {
HOST,
Expand All @@ -238,7 +234,6 @@ describe("Configuration", () => {
OCR_ENABLED,
OCR_LANGUAGES,
OCR_WORKERS,
POPPLER_BINARY_PATH,
});

const config = await getConfig();
Expand Down Expand Up @@ -301,7 +296,6 @@ describe("Configuration", () => {
});

expect(config.poppler).toStrictEqual({
binPath: POPPLER_BINARY_PATH,
tempDir,
});

Expand Down
8 changes: 1 addition & 7 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { getStream } = require("file-stream-rotator");
const S = require("fluent-json-schema").default;
const { stdSerializers, stdTimeFunctions } = require("pino");
const { parse: secureParse } = require("secure-json-parse");
const { dirname, joinSafe, normalizeSafe, normalizeTrim } = require("upath");
const { dirname, joinSafe, normalizeTrim } = require("upath");

const coreCount = require("../utils/core-count");
const { description, license, version } = require("../../package.json");
Expand Down Expand Up @@ -132,9 +132,6 @@ async function getConfig() {
S.anyOf([S.string().pattern(/^\[\{.*\}\]$/u), S.null()])
)

// Binary paths
.prop("POPPLER_BINARY_PATH", S.anyOf([S.string(), S.null()]))

// OCR
.prop("OCR_ENABLED", S.anyOf([S.boolean(), S.null()]))
.prop("OCR_LANGUAGES", S.anyOf([S.string(), S.null()]))
Expand Down Expand Up @@ -328,9 +325,6 @@ async function getConfig() {
},
},
poppler: {
binPath: env.POPPLER_BINARY_PATH
? normalizeSafe(env.POPPLER_BINARY_PATH)
: env.POPPLER_BINARY_PATH,
tempDir,
},
tesseract: {
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/pdf-to-html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const pdfToHtmlAcceptedParams = new Set([
* location and contents.
* @param {import("fastify").FastifyInstance} server - Fastify instance.
* @param {object} options - Plugin config values.
* @param {string} options.binPath - Path to Poppler binary.
* @param {object} [options.pdfToHtmlOptions] - Refer to
* https://github.com/Fdawgs/node-poppler/blob/main/API.md#Poppler+pdfToHtml
* for options.
Expand All @@ -48,7 +47,7 @@ const pdfToHtmlAcceptedParams = new Set([
*/
async function plugin(server, options) {
const directory = normalizeTrim(options.tempDir);
const poppler = new Poppler(options.binPath);
const poppler = new Poppler();

// Create temp directory if missing
await mkdir(directory, { recursive: true });
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/pdf-to-txt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const pdfToTxtAcceptedParams = new Set([
* `req` object is decorated with `conversionResults.body` holding the converted document.
* @param {import("fastify").FastifyInstance} server - Fastify instance.
* @param {object} options - Plugin config values.
* @param {string} options.binPath - Path to Poppler binary.
* @param {object} [options.pdfToTxtOptions] - Refer to
* https://github.com/Fdawgs/node-poppler/blob/main/API.md#Poppler+pdfToText
* for options.
Expand All @@ -61,7 +60,7 @@ const pdfToTxtAcceptedParams = new Set([
*/
async function plugin(server, options) {
const directory = normalizeTrim(options.tempDir);
const poppler = new Poppler(options.binPath);
const poppler = new Poppler();

// Create temp directory if missing
await mkdir(directory, { recursive: true });
Expand Down

0 comments on commit 93e3e11

Please sign in to comment.