From 5f0af3d66fc140a78d664b4b04327c47dff75f6f Mon Sep 17 00:00:00 2001 From: adb Date: Fri, 26 Feb 2021 09:11:03 +0100 Subject: [PATCH] no duplicate posts --- node_app/JSONdataStore.js | 7 +++++++ node_app/main.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/node_app/JSONdataStore.js b/node_app/JSONdataStore.js index 138172f..27d3529 100644 --- a/node_app/JSONdataStore.js +++ b/node_app/JSONdataStore.js @@ -14,4 +14,11 @@ export function loadData(path) { console.error(err) return false } +} +export function getStat(path) { + fs.stat(path, (err, stat) => { + if(err == null) return true; + else if(err.code === 'ENOENT') return false; + else return err.code; + }); } \ No newline at end of file diff --git a/node_app/main.js b/node_app/main.js index eb706a0..7936415 100644 --- a/node_app/main.js +++ b/node_app/main.js @@ -1,6 +1,7 @@ import {MastodonHandler} from "./mastodonHandler.js"; import {MastodonTokenHandler} from "./mastodonTokenHandler.js"; import {MemeHandler} from "./memeHandler.js"; +import {getStat} from "./JSONdataStore"; const baseUrl = "https://social.cybre.town"; const memeAPI = "http://redditapi.adb.sh/api/v1/"; @@ -20,6 +21,7 @@ await tokenHandler.getAccessToken((accessToken) => { let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`; if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){ let filepath = `./media/${sub.url.split(/[/]+/).pop()}`; + if (getStat(filepath)===true){ postRandomMeme(); return; } memeHandler.downloadMedia(sub.url, filepath, () => { client.postMedia(status, filepath, 5, () => postRandomMeme()); })