-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now saves all hashes,links to persistent csv file Now clears temporary files from disk after uploading to imgur and saving cache
- Loading branch information
1 parent
48a90fb
commit 0ed11a8
Showing
4 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ build/Release | |
node_modules | ||
|
||
target | ||
|
||
cache.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import fs from 'fs'; | ||
import {parse} from 'csv'; | ||
import {promisify} from 'bluebird'; | ||
|
||
let parseAsync = promisify(parse); | ||
|
||
export class Cache { | ||
constructor(file) { | ||
this.file = file; | ||
this.cache = new Map(); | ||
} | ||
|
||
static fromCsvFile(file) { | ||
let cacheInstance = new Cache(file); | ||
fs.readFileAsync('cache.csv', {flag: 'a+'}) | ||
.then(parseAsync) | ||
.then(parsed => { | ||
debugger; | ||
cacheInstance.cache = parsed.reduce((map, row) => map.set(row[0], row[1]), new Map()); | ||
return Promise.resolve(); | ||
}) | ||
.then(() => console.log('Cache is ready!')); | ||
return cacheInstance; | ||
} | ||
|
||
get(hash) { | ||
return this.cache.get(hash); | ||
} | ||
|
||
set(hash, link) { | ||
this.cache.set(hash, link); | ||
return fs.appendFileAsync(this.file, hash+","+link+"\n") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters