Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validateImageFormat function in createWorker.js #974

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/createWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const { log } = require('./utils/log');
const getId = require('./utils/getId');
const OEM = require('./constants/OEM');
const { FORMATS } = require('../tests/constants');
const {
defaultOptions,
spawnWorker,
Expand All @@ -13,6 +14,13 @@
send,
} = require('./worker/node');

const validateImageFormat = (imagePath) => {
const format = imagePath.split('.').pop().toLowerCase();
if (!FORMATS.includes(format)) {
throw new Error(`Unsupported image format: ${format}. Tesseract.js supports: ${FORMATS.join(', ')}`);
}
};

let workerCounter = 0;

module.exports = async (langs = 'eng', oem = OEM.LSTM_ONLY, _options = {}, config = {}) => {
Expand Down Expand Up @@ -185,6 +193,7 @@
const recognize = async (image, opts = {}, output = {
blocks: true, text: true, hocr: true, tsv: true,
}, jobId) => (
validateImageFormat(image),

Check failure on line 196 in src/createWorker.js

View workflow job for this annotation

GitHub Actions / build (14.x)

Unexpected use of comma operator

Check failure on line 196 in src/createWorker.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected use of comma operator

Check failure on line 196 in src/createWorker.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected use of comma operator

Check failure on line 196 in src/createWorker.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected use of comma operator
startJob(createJob({
id: jobId,
action: 'recognize',
Expand Down
Loading