Skip to content

Instantly share code, notes, and snippets.

@pwmckenna
Created November 20, 2012 20:45
Show Gist options
  • Save pwmckenna/4120963 to your computer and use it in GitHub Desktop.
Save pwmckenna/4120963 to your computer and use it in GitHub Desktop.
btapp.get('os').browse_for_files(function(files) {
console.log(JSON.stringify(files, null, 4));
/**
OLD RETURN VALUES
["/Users/pwmckenna/Documents/caitlin/humerus anteriorl view.jpg", ...]
NEW RETURN VALUES
[
{
"handle": 812535217,
"path": "/Users/pwmckenna/Documents/caitlin/humerus anteriorl view.jpg",
"size": 144414
},
{
"handle": 430880846,
"path": "/Users/pwmckenna/Documents/caitlin/humerus medial view.jpg",
"size": 141329
},
{
"handle": 499521038,
"path": "/Users/pwmckenna/Documents/caitlin/humerus talk image 2.jpg",
"size": 245483
},
{
"handle": 936509543,
"path": "/Users/pwmckenna/Documents/caitlin/humerus talk image 2.psd",
"size": 1316389
},
{
"handle": 1008240338,
"path": "/Users/pwmckenna/Documents/caitlin/humerus talk image.psd",
"size": 4436061
}
]
**/
//handle both the new and old return values
var paths = files;
if(paths.length > 0 && _.isObject(paths[0])) {
paths = _.pluck(files, 'path');
}
var torrent_name = generate_torrent_name(paths);
//hopefully that remains backwards compatible
btapp.get('torrent').generate({
name: torrent_name,
files: files, //or _.pluck(files, 'path'), or _.pluck(files, 'handle')
callback: function(res) { console.log('success', res); },
progress: function(res) { console.log('progress', res); },
error: function(res) { console.log('progress', res); }
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment