retry media upload
This commit is contained in:
parent
2be41af60d
commit
5ea7cae63f
@ -21,7 +21,7 @@ await tokenHandler.getAccessToken((accessToken) => {
|
|||||||
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()}`;
|
||||||
memeHandler.downloadMedia(sub.url, filepath, () => {
|
memeHandler.downloadMedia(sub.url, filepath, () => {
|
||||||
client.postMedia(status, filepath);
|
client.postMedia(status, filepath, 5, () => postRandomMeme());
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
console.log("no valid media, fetching new sub")
|
console.log("no valid media, fetching new sub")
|
||||||
|
@ -8,8 +8,17 @@ export class MastodonHandler extends Mastodon{
|
|||||||
console.log(resp.data);
|
console.log(resp.data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
postMedia(status, mediaPath){
|
postMedia(status, mediaPath, retry, onError){
|
||||||
this.post('media', { file: fs.createReadStream(mediaPath) }).then(resp => {
|
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;
|
let id = resp.data.id;
|
||||||
console.log("media uploaded => ");
|
console.log("media uploaded => ");
|
||||||
console.log(resp.data);
|
console.log(resp.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user