fix(core): update

This commit is contained in:
2021-11-29 16:29:15 +01:00
parent 19e3ba3362
commit 75ef50d072
8 changed files with 133 additions and 233 deletions

View File

@ -1,3 +1 @@
import * as plugins from './smartocr.plugins';
export let standardExport = 'Hi there! :) This is an exported string';
export * from './smartocr.classes.smartocr';

View 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
View 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');

View File

@ -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
}