fix(core): update
This commit is contained in:
parent
19e3ba3362
commit
75ef50d072
276
package-lock.json
generated
276
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,12 @@
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartfile": "^8.0.10",
|
||||
"@pushrocks/smartpromise": "^3.1.6",
|
||||
"@pushrocks/smartshell": "^2.0.30",
|
||||
"@pushrocks/smartunique": "^3.0.3"
|
||||
},
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
|
BIN
test/demo_without_textlayer.pdf
Normal file
BIN
test/demo_without_textlayer.pdf
Normal file
Binary file not shown.
14
test/test.ts
14
test/test.ts
@ -1,8 +1,18 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartocr from '../ts/index';
|
||||
|
||||
tap.test('first test', async () => {
|
||||
console.log(smartocr.standardExport);
|
||||
let testOcrInstance: smartocr.SmartOcr;
|
||||
|
||||
tap.test('should create a valid instance of Smartocr', async () => {
|
||||
testOcrInstance = await smartocr.SmartOcr.createAndInit();
|
||||
expect(testOcrInstance).to.be.instanceOf(smartocr.SmartOcr);
|
||||
});
|
||||
|
||||
tap.test('should ocr a pdfBuffer', async () => {
|
||||
const smartfile = await import('@pushrocks/smartfile');
|
||||
const pdfBuffer = (await smartfile.Smartfile.fromFilePath('./test/demo_without_textlayer.pdf'))
|
||||
.contentBuffer;
|
||||
testOcrInstance.processPdfBuffer(pdfBuffer);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,3 +1 @@
|
||||
import * as plugins from './smartocr.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
||||
export * from './smartocr.classes.smartocr';
|
||||
|
40
ts/smartocr.classes.smartocr.ts
Normal file
40
ts/smartocr.classes.smartocr.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import * as plugins from './smartocr.plugins';
|
||||
import * as paths from './smartocr.paths';
|
||||
|
||||
export class SmartOcr {
|
||||
// STATIC
|
||||
public static async createAndInit() {
|
||||
const smartocrInstance = new SmartOcr();
|
||||
await smartocrInstance.init();
|
||||
return smartocrInstance;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
|
||||
public readyDeferred = plugins.smartpromise.defer();
|
||||
public smartshellInstance: plugins.smartshell.Smartshell;
|
||||
|
||||
public async processPdfBuffer (pdfBufferArg: Buffer): Promise<Buffer> {
|
||||
const uniqueString = plugins.smartunique.uni('doc_');
|
||||
const originalPath = plugins.path.join(paths.noGitDir, `${uniqueString}.pdf`);
|
||||
const processedPath = plugins.path.join(paths.noGitDir, `${uniqueString}_processed.pdf`);
|
||||
const originalSmartfile = await plugins.smartfile.Smartfile.fromBuffer(originalPath, pdfBufferArg);
|
||||
await originalSmartfile.write();
|
||||
await this.smartshellInstance.exec(`ocrmypdf --rotate-pages ${originalPath} ${processedPath}`);
|
||||
const processedSmartfile = await plugins.smartfile.Smartfile.fromFilePath(processedPath);
|
||||
await plugins.smartfile.fs.remove(originalPath);
|
||||
await plugins.smartfile.fs.remove(processedPath);
|
||||
return processedSmartfile.contentBuffer;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
||||
executor: 'bash'
|
||||
});
|
||||
}
|
||||
|
||||
public async init() {
|
||||
await plugins.smartfile.fs.ensureDir(paths.noGitDir);
|
||||
const result = await plugins.smartshell.which('ocrmypdf');
|
||||
}
|
||||
}
|
4
ts/smartocr.paths.ts
Normal file
4
ts/smartocr.paths.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import * as plugins from './smartocr.plugins';
|
||||
|
||||
export const packageDir = plugins.path.join(__dirname, '../');
|
||||
export const noGitDir = plugins.path.join(packageDir, './.nogit');
|
@ -1,2 +1,19 @@
|
||||
const removeme = {};
|
||||
export { removeme };
|
||||
// node native
|
||||
import * as path from 'path';
|
||||
|
||||
export {
|
||||
path
|
||||
}
|
||||
|
||||
// @pushrocks scope
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
import * as smartshell from '@pushrocks/smartshell';
|
||||
import * as smartunique from '@pushrocks/smartunique';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
smartfile,
|
||||
smartshell,
|
||||
smartunique,
|
||||
smartpromise
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user