You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/09/12 20:14:46 UTC
[18/40] git commit: Add download count pushing to the registry
fetching.
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/ffos
Commit: cfa431bc0eca19398a3ca5e3ba79029e42d85104
Parents: 6e76e3a
Author: Braden Shepherdson <br...@gmail.com>
Authored: Wed Aug 28 16:23:54 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
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) {