Created
May 21, 2012 20:52
-
-
Save piatra/2764609 to your computer and use it in GitHub Desktop.
getting gist from github in an archive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request') | |
, express = require('express') | |
, app = express.createServer().listen(8000) | |
, slides = [] | |
, data = '' | |
, zip = require("node-native-zip") | |
; | |
app.get('/', function(req, res){ | |
// what needs to be done: fetch files from github, concatenate, arhive and send to user | |
// issues: i have no idea how many files I have to fetch, could be 1 could be 20 | |
request.get({url:'https://api.github.com/users/piatra/gists', json:true}, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
for (var i = 0; i < body.length; i++) { | |
if(body[i].description === 'reveal.js') { | |
var files = body[i].files; | |
for(var prop in files) { | |
// could not parse object in any other way | |
if(files.hasOwnProperty(prop)) { | |
request(files[prop].raw_url, function(err, response, body){ | |
// problems with closures | |
// files[prop].filename always the same file | |
slides.push({ | |
name : parseInt(files[prop].filename), | |
content: body | |
}) | |
}) | |
} | |
} | |
} | |
} | |
//concatenate all files in a large one called _data_ | |
//zip it and send it to the user | |
// var archive = new zip(); | |
// archive.add('slides.html', new Buffer(data, "utf8")); | |
// var buffer = archive.toBuffer(); | |
// res.attachment('hello.zip') | |
// res.send(buffer) | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for the late response, I just saw your twitter message now. Take a look at this: http://cjohansen.no/talks/2012/sdc-functional/#68
Apart from that you just need to gzip the resulting file.
P.S. Send me an email next time so I get your msg right away.