no duplicate posts

master
adb 4 years ago
parent ef17b4467c
commit 5f0af3d66f

@ -15,3 +15,10 @@ export function loadData(path) {
return false 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;
});
}

@ -1,6 +1,7 @@
import {MastodonHandler} from "./mastodonHandler.js"; import {MastodonHandler} from "./mastodonHandler.js";
import {MastodonTokenHandler} from "./mastodonTokenHandler.js"; import {MastodonTokenHandler} from "./mastodonTokenHandler.js";
import {MemeHandler} from "./memeHandler.js"; import {MemeHandler} from "./memeHandler.js";
import {getStat} from "./JSONdataStore";
const baseUrl = "https://social.cybre.town"; const baseUrl = "https://social.cybre.town";
const memeAPI = "http://redditapi.adb.sh/api/v1/"; 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}`; let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`;
if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){ if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){
let filepath = `./media/${sub.url.split(/[/]+/).pop()}`; let filepath = `./media/${sub.url.split(/[/]+/).pop()}`;
if (getStat(filepath)===true){ postRandomMeme(); return; }
memeHandler.downloadMedia(sub.url, filepath, () => { memeHandler.downloadMedia(sub.url, filepath, () => {
client.postMedia(status, filepath, 5, () => postRandomMeme()); client.postMedia(status, filepath, 5, () => postRandomMeme());
}) })

Loading…
Cancel
Save