rpc/downloads.mg investigated

NimaiNimai Registered Users Posts: 564 Major grins
I'm trying to create a hack that adds Download buttons to my galleries (when I'm logged in as the owner, of course). I started digging into the Tools menu within a gallery and seeing how the "Download All" menu item works. I got as far finding that it calls this (if it's non-Ajax):

/rpc/downloads.mg?action=create&content=???

Also, from Firebug's Net panel, I can see the Post when I request a download. I saw it passing the following post parameters.

action=create&content=YToxOntzOjc6IkFsYnVtSUQiO3M6ODoiMjA5NjIwMzQiO30=

That content string sure looks like a base64 encoded string, and indeed it was:

a:1:{s:7:"AlbumID";s:8:"29962034";}

And, that sure looks like a PHP serialized object! But, whatever it is, I just need to put the gallery id in there where that 299... number is, and I should be able to make my own Download All button.

Here's what I ended up with. It get's a successful response and everything, but I never receive any email that a download is ready.
var createDownloadParams = function(albumId) {
  var albumIdLength = albumId.toString(10).length;
  var params = 'a:1:{s:7:"AlbumID";s:'+albumIdLength+':"'+albumId+'";}';
  params = SM.util.base64_encode( params );
  return params;
}

var callback = {
  'success': function (o) {
    var response = YAHOO.lang.JSON.parse(o.responseText);
    if (response.status !== 'success') {
      status_title = 'Whoops!';
      status_msg = response.msg[0];
    } else {
      status_title = 'Processing';
      if (response.msg[0]) {
        status_msg = response.msg[0];
      } else {
        status_msg = 'Preparing zip file.';
      }
    }
    SM.util.notice(status_title, status_msg);
  },
  'failure': function (o) {
    SM.util.notice('Whoops!', 'Something went wrong...');
    return false;
  }
};

var params = createDownloadParams(21391159);
var request = YAHOO.util.Connect.asyncRequest('POST', '/rpc/downloads.mg',
  callback, 'action=create&'+params);
Has anyone else probed into this? Or, would anyone at SmugMug care to make a suggestion?

Thanks, and happy hacking!
Nimai
Sign In or Register to comment.