separated out the upload functions of clip-it-good

This commit is contained in:
Brett Slatkin 2010-12-01 19:51:14 -08:00
parent 69e839efbb
commit 10b8cc9f82
1 changed files with 31 additions and 20 deletions

View File

@ -77,7 +77,7 @@
contexts: ['image'], contexts: ['image'],
onclick: function(data, tab) { onclick: function(data, tab) {
return handleMenuClick( return handleMenuClick(
albumDict.name, albumDict.id, data, tab) albumType, albumDict.name, albumDict.id, data, tab)
} }
}); });
}); });
@ -85,7 +85,33 @@
}); });
} }
function handleMenuClick(albumName, albumId, data, tab) { // Upload actions
var ALBUM_TYPE_UPLOAD_FUNC = {
'picasa': function(albumId, albumName, dataSrcUrl, dataBlob, xhrDone) {
OAUTH.authorize(function() {
OAUTH.sendSignedRequest(
'http://picasaweb.google.com/data/feed/api/' +
'user/default/albumid/' + albumId,
xhrDone,
{
method: 'POST',
headers: {
'Content-Type': 'image/png',
'Slug': dataSrcUrl
},
parameters: {
alt: 'json'
},
body: dataBlob
}
);
});
}
};
function handleMenuClick(albumType, albumName, albumId, data, tab) {
chrome.pageAction.setTitle({ chrome.pageAction.setTitle({
tabId: tab.id, tabId: tab.id,
title: 'Clip It Good: Uploading (' + data.srcUrl.substr(0, 100) + ')' title: 'Clip It Good: Uploading (' + data.srcUrl.substr(0, 100) + ')'
@ -113,24 +139,9 @@
} }
} // end complete } // end complete
OAUTH.authorize(function() { var uploadFunc = ALBUM_TYPE_UPLOAD_FUNC[albumType];
OAUTH.sendSignedRequest( uploadFunc(albumId, albumName, data.srcUrl,
'http://picasaweb.google.com/data/feed/api/' + builder.getBlob('image/png'), complete);
'user/default/albumid/' + albumId,
complete,
{
method: 'POST',
headers: {
'Content-Type': 'image/png',
'Slug': data.srcUrl
},
parameters: {
alt: 'json'
},
body: builder.getBlob('image/png')
}
);
});
} // end onload } // end onload
img.src = data.srcUrl; img.src = data.srcUrl;