Skip to content

Commit

Permalink
Twitterのプロフィール画像へのポスト追加(要パッチ)
Browse files Browse the repository at this point in the history
コンテントタイプ推定追加(実装途中)
  • Loading branch information
to committed Jan 11, 2010
1 parent 0252842 commit 59da4ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
11 changes: 11 additions & 0 deletions patches/model.TwitterPicture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
models.register(update({}, Twitter, {
name : 'Twitter - Picture',

check : function(ps){
return ps.type == 'photo';
},

post : function(ps){
return this.changePicture(ps.itemUrl);
},
}));
19 changes: 17 additions & 2 deletions xpi/chrome/content/library/01_utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ function download(sourceURL, targetFile, useManger){
var d = new Deferred();
var sourceURI = createURI(sourceURL);

if(!targetFile){
if(!targetFile)
targetFile = getDownloadDir();

if(targetFile.isDirectory())
targetFile.append(sourceURI.fileName);
}

var targetURI = IOService.newFileURI(targetFile);

var p = WebBrowserPersist();
Expand Down Expand Up @@ -474,6 +476,7 @@ function request(url, opts){
]);
} else {
if(value.file instanceof IFile){
value.contentType = value.contentType || guessContentType(value.file);
value.fileName = value.file.leafName;
value.file = IOService.newChannelFromURI(createURI(value.file)).open();
}
Expand Down Expand Up @@ -614,6 +617,18 @@ function request(url, opts){
return d;
}

// FIXME: Firefox内の実装を探す
function guessContentType(ext){
if(ext instanceof IFile)
ext = ext.leafName.split('.').pop();

return {
mp3 : 'audio/mpeg',
m4a : 'audio/mp4',
png : 'image/png',
jpg : 'image/jpeg',
}[ext];
}

// ----[MochiKit]-------------------------------------------------
var StopProcess = {};
Expand Down
13 changes: 13 additions & 0 deletions xpi/chrome/content/library/20_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,19 @@ models.register({
});
},

changePicture : function(url){
var self = this;
return ((url instanceof IFile)? succeed(url) : download(url, getTempDir())).addCallback(function(file){
return Twitter.getToken().addCallback(function(token){
return request(self.URL + '/account/picture', {
sendContent : update(token, {
'profile_image[uploaded_data]' : file,
}),
});
});
});
},

remove : function(id){
var self = this;
return Twitter.getToken().addCallback(function(ps){
Expand Down

0 comments on commit 59da4ef

Please sign in to comment.