Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###
- Creates a new bucket for a user using the given parameters (if not already above the user's limit)
- @param {Object} user the document of the authenticated user
- @param {String} name to be used for the bucket
- @param {Number} limit to be used for the bucket (in Byte)
- @param {Function} callback gets two parameters - error object (if an error occured) and the new bucket document if successful.
- @api public
- ###
- Buckets::create = (user, name, limit, callback) ->
- this.list user, (err, info) =>
- return callback(err) if err
- # check the bucket name (for already taken)
- for bucket in info.buckets
- if bucket.name == name
- return callback(message: "The name \"#{name}\" is already taken.")
- # check the userlimit
- if user.limit and (info.totalSize + limit) > user.limit
- max = user.limit - info.totalSize
- return callback(message: "The desired limit of #{limit} exceeds the total limit of #{user.limit} by #{limit-max}. The maximum limit is #{max}.")
- bucket =
- name: name
- owner: user._id.toHexString()
- limit: limit
- size: 0
- this.collection.insert bucket, {safe:true}, (err, docs) ->
- return callback err if err
- return callback null, docs[0]
Add Comment
Please, Sign In to add comment