cozy-proxy
Version:
Cozy Proxy redirects requests properly to the right application of the Cozy platform depending on given path. It also handles authentication to the Cozy for users and devices.
60 lines (51 loc) • 1.36 kB
JavaScript
// Generated by CoffeeScript 1.10.0
var CozyInstance, cozydb, resetKey;
cozydb = require('cozydb');
module.exports = CozyInstance = cozydb.getModel('CozyInstance', {
id: {
type: String
},
domain: {
type: String
},
locale: {
type: String
}
});
CozyInstance.first = function(callback) {
return CozyInstance.request('all', function(err, instances) {
if (err) {
return callback(err);
} else if (!instances || instances.length === 0) {
return callback(null, null);
} else {
return callback(null, instances[0]);
}
});
};
CozyInstance.getLocale = function(callback) {
return CozyInstance.first(function(err, instance) {
return callback(err, (instance != null ? instance.locale : void 0) || null);
});
};
CozyInstance.createOrUpdate = function(instanceData, callback) {
return CozyInstance.first(function(err, instance) {
if (err != null) {
return callback(err);
} else if (instance != null) {
return instance.updateAttributes(instanceData, callback);
} else {
return CozyInstance.create(instanceData, callback);
}
});
};
resetKey = null;
CozyInstance.getResetKey = function() {
return resetKey;
};
CozyInstance.setResetKey = function(key) {
resetKey = key;
return setTimeout(function() {
return resetKey = null;
}, 1 * 60 * 60 * 1000);
};