From 733328e99bc0286250b76ed4c00353ea4f2fd810 Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Mon, 3 Oct 2016 03:22:52 -0400 Subject: [PATCH] moving things to shared --- src/{worker => shared}/circularize.js | 0 src/{worker => shared}/desaturate.js | 0 src/{worker => shared}/dump.js | 0 src/{worker => shared}/fileSizes.js | 0 src/worker/detect.js | 2 +- src/worker/index.js | 4 ++-- src/worker/loadLanguage.js | 4 ++-- src/worker/recognize.js | 8 ++++---- webpack.config.dev.js | 12 ++++++------ 9 files changed, 15 insertions(+), 15 deletions(-) rename src/{worker => shared}/circularize.js (100%) rename src/{worker => shared}/desaturate.js (100%) rename src/{worker => shared}/dump.js (100%) rename src/{worker => shared}/fileSizes.js (100%) diff --git a/src/worker/circularize.js b/src/shared/circularize.js similarity index 100% rename from src/worker/circularize.js rename to src/shared/circularize.js diff --git a/src/worker/desaturate.js b/src/shared/desaturate.js similarity index 100% rename from src/worker/desaturate.js rename to src/shared/desaturate.js diff --git a/src/worker/dump.js b/src/shared/dump.js similarity index 100% rename from src/worker/dump.js rename to src/shared/dump.js diff --git a/src/worker/fileSizes.js b/src/shared/fileSizes.js similarity index 100% rename from src/worker/fileSizes.js rename to src/shared/fileSizes.js diff --git a/src/worker/detect.js b/src/worker/detect.js index 7d3c150..902097f 100644 --- a/src/worker/detect.js +++ b/src/worker/detect.js @@ -1,4 +1,4 @@ -import desaturate from './desaturate' +import desaturate from '../shared/desaturate' import loadLanguage from './loadLanguage' export default function detect(jobId, image, cb){ diff --git a/src/worker/index.js b/src/worker/index.js index eea86aa..9f4971f 100644 --- a/src/worker/index.js +++ b/src/worker/index.js @@ -29,9 +29,9 @@ onmessage = function(e) { } else if(action === 'recognize'){ var {image, options} = args recognize(jobId, image, options, - (error, result) => postMessage({jobId, error, result})) + (error, result) => postMessage({jobId, error: error.message, result})) } else if(action === 'detect'){ detect(jobId, args.image, - (error, result) => postMessage({jobId, error, result})) + (error, result) => postMessage({jobId, error: error.message, result})) } } \ No newline at end of file diff --git a/src/worker/loadLanguage.js b/src/worker/loadLanguage.js index 6e424fd..2272dfb 100644 --- a/src/worker/loadLanguage.js +++ b/src/worker/loadLanguage.js @@ -1,11 +1,11 @@ import {ungzip} from 'pako' import db from './db' -import fileSizes from './fileSizes' +import fileSizes from '../shared/fileSizes' function getLanguageData(lang, progress, cb){ var xhr = new XMLHttpRequest(); xhr.responseType = 'arraybuffer'; - xhr.open('GET', self.LANG_URL + lang + '.traineddata.gz', true); + xhr.open('GET', self.langUrl + lang + '.traineddata.gz', true); xhr.onerror = e => { xhr.onprogress = xhr.onload = null cb(xhr, null) diff --git a/src/worker/recognize.js b/src/worker/recognize.js index 8765cb3..e9acc52 100644 --- a/src/worker/recognize.js +++ b/src/worker/recognize.js @@ -1,7 +1,7 @@ -import desaturate from './desaturate' +import desaturate from '../shared/desaturate' import loadLanguage from './loadLanguage' -import circularize from './circularize' -import dump from './dump' +import circularize from '../shared/circularize' +import dump from '../shared/dump' var loaded_langs = [] @@ -22,7 +22,7 @@ export default function recognize(jobId, image, options, cb){ self.base.Init(null, lang) postMessage({ - jobId, + jobId, 'progress': { 'initialized_with_lang': lang } diff --git a/webpack.config.dev.js b/webpack.config.dev.js index 9869350..5fc7a9e 100644 --- a/webpack.config.dev.js +++ b/webpack.config.dev.js @@ -1,11 +1,11 @@ var path = require('path'); var webpack = require('webpack'); -function config({entry, output, include}) { +function config(opt) { return { devtool: 'cheap-module-eval-source-map', - entry, - output: Object.assign({}, output, { + entry: opt.entry, + output: Object.assign({}, opt.output, { path: path.join(__dirname, 'build'), publicPath: '/tesseract/', }), @@ -16,7 +16,7 @@ function config({entry, output, include}) { loaders: [{ test: /\.js$/, loaders: ['babel'], - include + include: opt.include }] }, node: { @@ -32,11 +32,11 @@ module.exports = [{ library: "Tesseract", libraryTarget: "umd" }, - include: [path.join(__dirname, 'src/browser')] + include: [path.join(__dirname, 'src/browser'), path.join(__dirname, 'src/shared')] }, { entry: './src/worker/index.js', output: { filename: 'tesseract.worker.js', }, - include: [path.join(__dirname, 'src/worker')] + include: [path.join(__dirname, 'src/worker'), path.join(__dirname, 'src/shared')] }].map(config); \ No newline at end of file