node/deps/npm/node_modules/npm-registry-client/lib/star.js

28 lines
799 B
JavaScript
Raw Normal View History

2012-06-12 00:30:44 +08:00
module.exports = star
2014-08-01 00:05:30 +08:00
function star (uri, starred, cb) {
2012-08-22 06:29:03 +08:00
if (!this.conf.get('username')) return cb(new Error(
2012-06-12 00:30:44 +08:00
"Must be logged in to star/unstar packages"))
2014-08-01 00:05:30 +08:00
this.request("GET", uri+"?write=true", null, function (er, fullData) {
2012-06-12 00:30:44 +08:00
if (er) return cb(er)
fullData = { _id: fullData._id
, _rev: fullData._rev
, users: fullData.users || {} }
if (starred) {
this.log.info("starring", fullData._id)
2012-08-22 06:29:03 +08:00
fullData.users[this.conf.get('username')] = true
2012-06-12 00:30:44 +08:00
this.log.verbose("starring", fullData)
} else {
2012-08-22 06:29:03 +08:00
delete fullData.users[this.conf.get('username')]
2012-06-12 00:30:44 +08:00
this.log.info("unstarring", fullData._id)
this.log.verbose("unstarring", fullData)
}
2014-08-01 00:05:30 +08:00
return this.request("PUT", uri, { body : fullData }, cb)
2012-06-12 00:30:44 +08:00
}.bind(this))
}