From 1e25cba824134c1615194f369a22a2c7f6891511 Mon Sep 17 00:00:00 2001 From: adb Date: Mon, 15 Mar 2021 09:33:43 +0100 Subject: [PATCH] debug duplicate posts --- node_app/JSONdataStore.js | 11 ++++++----- node_app/mastodonMemeBot.js | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/node_app/JSONdataStore.js b/node_app/JSONdataStore.js index 0db9b74..0f313f0 100644 --- a/node_app/JSONdataStore.js +++ b/node_app/JSONdataStore.js @@ -16,9 +16,10 @@ export function loadData(path) { } } export function getStat(path) { - fs.stat(path, (err, stat) => { - if(err == null) return true; - if(err.code === 'ENOENT') return false; - return err.code; - }); + try { + return fs.existsSync(path) === true; + } catch(err) { + console.error(err) + return false; + } } \ No newline at end of file diff --git a/node_app/mastodonMemeBot.js b/node_app/mastodonMemeBot.js index 5036179..09ea7d6 100644 --- a/node_app/mastodonMemeBot.js +++ b/node_app/mastodonMemeBot.js @@ -20,7 +20,7 @@ export class mastodonMemeBot { return; } let filepath = `./media/${sub.url.split(/[/]+/).pop()}`; - if (getStat(filepath) === true) { + if (getStat(filepath)) { console.log("post already exists, fetching new sub"); this.postRandomMeme(callback); return;