Skip to content

Instantly share code, notes, and snippets.

@YungSang
Created October 23, 2013 13:27
Show Gist options
  • Save YungSang/7118756 to your computer and use it in GitHub Desktop.
Save YungSang/7118756 to your computer and use it in GitHub Desktop.
[Deprecated] Taberareloo 用パッチ:一部のサイトから Tumblr への画像ポストがエラーになる場合の対策。 Taberareloo v3.0.6 で対策されました。
// ==Taberareloo==
// {
// "name" : "Tumblr Post Patch"
// , "description" : "Patch the post function for Tumblr"
// , "include" : ["background"]
// , "version" : "0.1.0"
// , "downloadURL" : "https://gist.github.com/YungSang/7118756/raw/patch.model.tumblr.post.tbrl.js"
// }
// ==/Taberareloo==
(function() {
update(Models['Tumblr'], {
post : function (ps) {
var self = this;
if(TBRL.Config.post['tumblr_default_quote']){
ps = update({}, ps);
ps.flavors = update({}, ps.flavors);
delete ps['flavors']['html'];
}
var endpoint = Tumblr.TUMBLR_URL + 'new/' + ps.type;
return this.postForm(function(){
return self.getForm(endpoint).addCallback(function postUpdate(form){
var type;
type = ps.type.capitalize();
return Tumblr[type].convertToForm(ps).addCallback(function(form2){
// merging forms
update(form, form2);
self.appendTags(form, ps);
if (TBRL.Config.post.multi_tumblelogs && !Tumblr.blogs.some(function(id){ return id === form.channel_id; })) {
throw new Error(chrome.i18n.getMessage('error_notLoggedin', form.channel_id));
}
return (function () {
if (type === 'Photo') {
if (form['photo[]']) {
return request(Tumblr.TUMBLR_URL + 'svc/post/upload_photo', {
sendContent: form
}).addCallback(function(res){
var response = JSON.parse(res.response);
if (response.meta && response.meta.msg === 'OK' && response.meta.status === 200) {
delete form['photo[]'];
form['images[o1]'] = response.response[0].url;
form['post[photoset_layout]'] = '1';
form['post[photoset_order]'] = 'o1';
return request(Tumblr.TUMBLR_URL + 'svc/post/update', {
headers: {'Content-Type': 'application/json'},
sendContent: JSON.stringify(form)
});
}
return res;
});
} else {
form['images[o1]'] = form['photo_src[]'];
form['post[photoset_layout]'] = '1';
form['post[photoset_order]'] = 'o1';
}
}
return request(Tumblr.TUMBLR_URL + 'svc/post/update', {
headers: {'Content-Type': 'application/json'},
sendContent: JSON.stringify(form)
});
}()).addErrback(function(err){
if (self.retry) {
throw err;
}
Tumblr.form_key = Tumblr.channel_id = null;
self.retry = true;
return self.getForm(endpoint).addCallback(postUpdate);
});
});
});
});
}
});
})();
@YungSang
Copy link
Author

57行目、本体 models.js 130行目

                  form['images[o1]'] = '';

                  form['images[o1]'] = form['photo_src[]'];

ここだけ変更。
これが正しい対策かはよくわかりません。

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