Skip to content

Instantly share code, notes, and snippets.

@ailispaw
Last active January 6, 2020 13:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ailispaw/f0cf8e6db802b51a9790 to your computer and use it in GitHub Desktop.
Save ailispaw/f0cf8e6db802b51a9790 to your computer and use it in GitHub Desktop.
Fix Twitter.upload 2016.08
// ==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);
});
});
})();
@ailispaw
Copy link
Author

ailispaw commented Jun 3, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment