retry media upload

master
adb 4 years ago
parent 2be41af60d
commit 5ea7cae63f

@ -21,7 +21,7 @@ await tokenHandler.getAccessToken((accessToken) => {
if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){
let filepath = `./media/${sub.url.split(/[/]+/).pop()}`;
memeHandler.downloadMedia(sub.url, filepath, () => {
client.postMedia(status, filepath);
client.postMedia(status, filepath, 5, () => postRandomMeme());
})
}else{
console.log("no valid media, fetching new sub")

@ -8,8 +8,17 @@ export class MastodonHandler extends Mastodon{
console.log(resp.data);
});
}
postMedia(status, mediaPath){
postMedia(status, mediaPath, retry, onError){
this.post('media', { file: fs.createReadStream(mediaPath) }).then(resp => {
if (retry <= 0){
onError();
return;
}
if (!resp.data.id){
this.postMedia(status, mediaPath, --retry);
console.log("issue while uploading, retry")
return;
}
let id = resp.data.id;
console.log("media uploaded => ");
console.log(resp.data);

Loading…
Cancel
Save