Skip to content

Commit

Permalink
Merge pull request #46 from dills122/file-cleanup
Browse files Browse the repository at this point in the history
Added file clean up to remove all tmp files generated
  • Loading branch information
dills122 authored Jun 15, 2019
2 parents f47a7e7 + dc083c3 commit 944a264
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mtg-card-analyzer",
"version": "0.1.6",
"version": "0.1.8",
"description": "a mtg ocr app for documenting a collection",
"main": "index.js",
"scripts": {
Expand All @@ -27,6 +27,7 @@
"nedb": "^1.8.0",
"request": "^2.88.0",
"request-promise-native": "^1.0.7",
"rimraf": "^2.6.3",
"string-similarity": "^3.0.0",
"temp-dir": "^2.0.0",
"tesseract.js": "^1.0.19",
Expand Down
4 changes: 2 additions & 2 deletions src/back-filler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ let GetNames = promisify(GetBulkNames);
let HashImage = promisify(Hash.HashImage);

async function BackFillImageHashes() {
let start = 13501;
let stop = 14500;
let start = 18501;
let stop = 19350;

let names = await GetNames();
let nameSlice = names.slice(start, stop);
Expand Down
14 changes: 13 additions & 1 deletion src/file-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
} = require('util');
const uuid = require('uuid/v4');
const tempDirectory = require('temp-dir');
const rimraf = require('rimraf');

const writeFile = promisify(fs.writeFile);
const unlinkFile = promisify(fs.unlink);
Expand All @@ -23,8 +24,19 @@ async function CreateDirectory() {
return dirPath;
}

function CleanUpFiles(directory, callback) {
rimraf(directory, (err) => {
console.log(`Removed Directory: ${directory}`)
if(err) {
return callback(err);
}
return callback();
})
}

module.exports = {
WriteToFile,
DeleteFile,
CreateDirectory
CreateDirectory,
CleanUpFiles
}
18 changes: 17 additions & 1 deletion src/processor/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
} = require('util');
const {
WriteToFile,
CreateDirectory
CreateDirectory,
CleanUpFiles
} = require('../file-io');
const {
ProcessResults
Expand All @@ -29,6 +30,7 @@ const dependencies = {
}

const Scan = promisify(textExtraction.ScanImage);
const CleanFilesUp = promisify(CleanUpFiles);

function SingleProcessor(params) {
_.bindAll(this, Object.keys(SingleProcessor.prototype));
Expand Down Expand Up @@ -62,6 +64,8 @@ SingleProcessor.prototype._processCard = function (path, callback) {
}).then(() => {
console.log(`Fuzzy Matches Processed: ${JSON.stringify(this.matches,null,4)}`);
return this._processResults();
}).then(() => {
return this._CleanUpFiles();
}).then(() => {
console.log(`Results Processed: Finished`);
textExtraction.ShutDown();
Expand Down Expand Up @@ -204,6 +208,18 @@ SingleProcessor.prototype._getBase64Images = async function () {
return await Base64.StringfyImagesNDAtn(this.imagePaths);
}

SingleProcessor.prototype._CleanUpFiles = async function() {
try {
console.log("_CleanUpFiles:: Beginning Clean Up");
await CleanFilesUp(this.directory);
console.log("_CleanUpFiles:: Finished Clean Up");
return this.directory;
} catch(err) {
console.log(err);
return '';
}
};

module.exports = {
create: function (params) {
return new SingleProcessor(params);
Expand Down
2 changes: 1 addition & 1 deletion src/rds/card-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function GetHashes(name, cb) {
if(err) {
return cb(err);
}
connection.query('SELECT CardHash as cardHash, SetName as setName, IsFoil as isFoil, IsPromo as isPromo FROM Card_Hashes WHERE Name=?', [name], (error, results) => {
connection.query('SELECT CardHash as cardHash, SetName as setName, IsFoil as isFoil, IsPromo as isPromo FROM Card_Hashes WHERE CardName=?', [name], (error, results) => {
if (error) {
console.log(error);
connection.end();
Expand Down

0 comments on commit 944a264

Please sign in to comment.