Last active
January 6, 2020 13:10
-
-
Save ailispaw/f0cf8e6db802b51a9790 to your computer and use it in GitHub Desktop.
Fix Twitter.upload 2016.08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==Taberareloo== | |
// { | |
// "name" : "Fix Twitter.upload 2016.08" | |
// , "description" : "Fix Twitter.upload 2016.08" | |
// , "include" : ["background"] | |
// , "version" : "0.3.1" | |
// , "downloadURL" : "https://gist.githubusercontent.com/ailispaw/f0cf8e6db802b51a9790/raw/patch.fix.twitter.upload.tbrl.js" | |
// } | |
// ==/Taberareloo== | |
(function() { | |
addAround(Models['Twitter'], 'upload', function (proceed, args, target, methodName) { | |
var self = target; | |
self.UPLOAD_URL = 'https://upload.twitter.com/i/media/upload.json'; | |
var ps = args[0]; | |
var status = args[1]; | |
var file = args[2]; | |
self.addBeforeSendHeader(); | |
return request(self.UPLOAD_URL, { | |
method : 'POST', | |
responseType : 'json', | |
queryString : { | |
command : 'INIT', | |
total_bytes : file.size, | |
media_type : file.type, | |
media_category : 'tweet_image' | |
} | |
}).then(function (res) { | |
var media_id = res.response.media_id_string; | |
return request(self.UPLOAD_URL, { | |
method : 'POST', | |
queryString : { | |
command : 'APPEND', | |
media_id : media_id, | |
segment_index : 0 | |
}, | |
sendContent : { | |
media : file | |
} | |
}).then(function (res) { | |
return request(self.UPLOAD_URL, { | |
method : 'POST', | |
responseType : 'json', | |
queryString : { | |
command : 'FINALIZE', | |
media_id : media_id | |
} | |
}).then(function (res) { | |
self.removeBeforeSendHeader(); | |
return self.update(status, media_id); | |
}).catch(function (res) { | |
self.removeBeforeSendHeader(); | |
var message = res.response ? res.response.error : res.message; | |
throw new Error(message); | |
}); | |
}).catch(function (res) { | |
self.removeBeforeSendHeader(); | |
var message = res.response ? res.response.error : res.message; | |
throw new Error(message); | |
}); | |
}).catch(function (res) { | |
self.removeBeforeSendHeader(); | |
var message = res.response ? res.response.error : res.message; | |
throw new Error(message); | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tombfix/core@1bc1ce2