import Mastodon from "mastodon-api"; import fs from "fs"; export class MastodonHandler extends Mastodon{ postStatus(status){ this.post('statuses', {status: status}).then((resp) => { console.log("status posted => "); console.log(resp.data); }); } postMedia(status, mediaPath, retry, onError, callback){ if (retry <= 0){ onError(); return; } this.post('media', { file: fs.createReadStream(mediaPath) }).then(resp => { if (!resp.data.id){ this.postMedia(status, mediaPath, --retry, onError); console.log("issue while uploading, retry") return; } let id = resp.data.id; console.log("media uploaded => "); console.log(resp.data); this.post('statuses', { status: status, media_ids: [id] }).then((resp) => { console.log("media posted => "); console.log(resp.data); callback(); }); }); } }