Skip to content

Commit

Permalink
Loaded cached list, resolves #1
Browse files Browse the repository at this point in the history
  • Loading branch information
eoussama committed Jul 17, 2020
1 parent 19a2e64 commit 02c5a1c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class AnusicScrapper {
}

// Loading the dump file
this.loadDump();
this.loadDump().catch(err => console.log({ err }));
}

//#endregion
Expand Down Expand Up @@ -102,17 +102,20 @@ export default class AnusicScrapper {
writeFileSync(path, JSON.stringify(dump, null, 2));
}

async loadDump(): Promise<void> {
async loadDump(): Promise<any> {
return new Promise((res, rej) => {

// Constructing the dump file path
const path = resolve(this.dumpLocation, 'dump.json');

// Checking if the dump file exists
if (existsSync(path) && path) {
// res(readFileSync(path).toJSON());
console.log(readFileSync(path));
res();

// Parting the data
const result = JSON.parse(readFileSync(path).toString());
this.anime = result.anime;

res(result);
} else {
rej();
}
Expand All @@ -122,5 +125,5 @@ export default class AnusicScrapper {
//#endregion
}

const client = new AnusicScrapper();
const client = new AnusicScrapper({ dumpLocation: 'dir1/dir2' });
console.log({ anime: client.anime[0] });

0 comments on commit 02c5a1c

Please sign in to comment.