container.js | |
/* Crypton Server, Copyright 2013 SpiderOak, Inc.
*
* This file is part of Crypton Server.
*
* Crypton Server is free software: you can redistribute it and/or modify it
* under the terms of the Affero GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Crypton Server is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Affero GNU General Public
* License for more details.
*
* You should have received a copy of the Affero GNU General Public License
* along with Crypton Server. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';
var app = require('../app');
var db = app.datastore; | |
¶ Container()
| var Container = module.exports = function Container () {}; |
¶ get(containerNameHmac, callback)Retrieve all container records from the database for the specified Adds records to container object and calls back without error if successful Calls back with error if unsuccessful Params containerNameHmacString callbackFunction | Container.prototype.get = function (containerNameHmac, callback) {
app.log('debug', 'getting container');
var that = this;
db.getContainerRecords(containerNameHmac, function (err, records) {
if (err) {
callback(err);
return;
}
if (!records.length) {
app.log('debug', 'container does not exist');
callback('Container does not exist');
return;
}
that.update('records', records);
callback(null);
});
}; |
¶ update()Update one or a set of keys in the parent container object Params keyString valueObject Or inputObject | // TODO add field validation and callback
Container.prototype.update = function () {
// update({ key: 'value' });
if (typeof arguments[0] == 'object') {
for (var key in arguments[0]) {
this[key] = arguments[0][key];
}
}
// update('key', 'value')
else if (typeof arguments[0] == 'string' && typeof arguments[1] != 'undefined') {
this[arguments[0]] = arguments[1];
}
};
|