debug duplicate posts

This commit is contained in:
0xADB 2021-03-15 09:33:43 +01:00
parent 29eb393717
commit 1e25cba824
2 changed files with 7 additions and 6 deletions

View File

@ -16,9 +16,10 @@ export function loadData(path) {
} }
} }
export function getStat(path) { export function getStat(path) {
fs.stat(path, (err, stat) => { try {
if(err == null) return true; return fs.existsSync(path) === true;
if(err.code === 'ENOENT') return false; } catch(err) {
return err.code; console.error(err)
}); return false;
}
} }

View File

@ -20,7 +20,7 @@ export class mastodonMemeBot {
return; return;
} }
let filepath = `./media/${sub.url.split(/[/]+/).pop()}`; let filepath = `./media/${sub.url.split(/[/]+/).pop()}`;
if (getStat(filepath) === true) { if (getStat(filepath)) {
console.log("post already exists, fetching new sub"); console.log("post already exists, fetching new sub");
this.postRandomMeme(callback); this.postRandomMeme(callback);
return; return;