Updated Branches: refs/heads/master 6e76e3a5b -> cfa431bc0
Add download count pushing to the registry fetching. Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/cfa431bc Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/cfa431bc Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/cfa431bc Branch: refs/heads/master Commit: cfa431bc0eca19398a3ca5e3ba79029e42d85104 Parents: 6e76e3a Author: Braden Shepherdson <[email protected]> Authored: Wed Aug 28 16:23:54 2013 -0400 Committer: Braden Shepherdson <[email protected]> Committed: Wed Aug 28 16:23:54 2013 -0400 ---------------------------------------------------------------------- src/registry/registry.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/cfa431bc/src/registry/registry.js ---------------------------------------------------------------------- diff --git a/src/registry/registry.js b/src/registry/registry.js index 34e566c..1ab5de1 100644 --- a/src/registry/registry.js +++ b/src/registry/registry.js @@ -1,6 +1,7 @@ var npm = require('npm'), path = require('path'), http = require('http'), + url = require('url'), targz = require('tar.gz'), fs = require('fs'), manifest = require('./manifest'), @@ -71,6 +72,27 @@ function fetchPackage(info, cb) { if (cb) cb(err); else throw err; } else { + // Update the download count for this plugin. + // Fingers crossed that the timestamps are unique, and that no plugin is downloaded + // twice in a single millisecond. + // + // This is acceptable, because the failure mode is Couch gracefully rejecting the second one + // (for lacking a _rev), and dropped a download count is not important. + var now = new Date(); + var pkgId = info._id.substring(0, info._id.indexOf('@')); + var id = pkgId + '_' + now.toISOString(); + var uri = url.parse(module.exports.settings.registry); + // Overriding the path to point at /downloads. + uri.path = '/downloads/' + id; + uri.method = 'PUT'; + var dlcReq = http.request(uri); + + dlcReq.write(JSON.stringify({ + day: now.getUTCFullYear() + '-' + (now.getUTCMonth()+1) + '-' + now.getUTCDate(), + pkg: pkgId + })); + dlcReq.end(); + res.pipe(filestream); filestream.on('finish', function() { var decompress = new targz().extract(filename, target, function(err) {
