move owners store out to own object
This commit is contained in:
parent
c7627faffd
commit
f2b05ee7af
90
lib/app.js
90
lib/app.js
|
@ -55,54 +55,56 @@ module.exports = function (deps, conf, overrideHttp) {
|
|||
var scmp = require('scmp');
|
||||
request = request || PromiseA.promisify(require('request'));
|
||||
|
||||
var owners = {
|
||||
all: function () {
|
||||
var owners;
|
||||
try {
|
||||
owners = require(ownersPath);
|
||||
} catch(e) {
|
||||
owners = {};
|
||||
}
|
||||
|
||||
return PromiseA.resolve(Object.keys(owners).map(function (key) {
|
||||
var owner = owners[key];
|
||||
owner.id = key;
|
||||
return owner;
|
||||
}));
|
||||
}
|
||||
, get: function (id) {
|
||||
var me = this;
|
||||
|
||||
return me.all().then(function (owners) {
|
||||
return owners.filter(function (owner) {
|
||||
return scmp(id, owner.id);
|
||||
})[0];
|
||||
});
|
||||
}
|
||||
, exists: function (id) {
|
||||
var me = this;
|
||||
|
||||
return me.get(id).then(function (owner) {
|
||||
return !!owner;
|
||||
});
|
||||
}
|
||||
, set: function (id, obj) {
|
||||
var owners;
|
||||
try {
|
||||
owners = require(ownersPath);
|
||||
} catch(e) {
|
||||
owners = {};
|
||||
}
|
||||
obj.id = id;
|
||||
owners[id] = obj;
|
||||
|
||||
return fs.writeFileAsync(ownersPath, JSON.stringify(owners), 'utf8');
|
||||
}
|
||||
};
|
||||
|
||||
return require('../packages/apis/com.daplie.goldilocks').create({
|
||||
PromiseA: PromiseA
|
||||
, OAUTH3: OAUTH3
|
||||
, storage: {
|
||||
owners: {
|
||||
all: function () {
|
||||
var owners;
|
||||
try {
|
||||
owners = require(ownersPath);
|
||||
} catch(e) {
|
||||
owners = {};
|
||||
}
|
||||
|
||||
return PromiseA.resolve(Object.keys(owners).map(function (key) {
|
||||
var owner = owners[key];
|
||||
owner.id = key;
|
||||
return owner;
|
||||
}));
|
||||
}
|
||||
, get: function (id) {
|
||||
var me = this;
|
||||
|
||||
return me.all().then(function (owners) {
|
||||
return owners.filter(function (owner) {
|
||||
return scmp(id, owner.id);
|
||||
})[0];
|
||||
});
|
||||
}
|
||||
, exists: function (id) {
|
||||
var me = this;
|
||||
|
||||
return me.get(id).then(function (owner) {
|
||||
return !!owner;
|
||||
});
|
||||
}
|
||||
, set: function (id, obj) {
|
||||
var owners;
|
||||
try {
|
||||
owners = require(ownersPath);
|
||||
} catch(e) {
|
||||
owners = {};
|
||||
}
|
||||
obj.id = id;
|
||||
owners[id] = obj;
|
||||
|
||||
return fs.writeFileAsync(ownersPath, JSON.stringify(owners), 'utf8');
|
||||
}
|
||||
}
|
||||
owners: owners
|
||||
}
|
||||
, recase: require('recase').create({})
|
||||
, request: request
|
||||
|
|
Loading…
Reference in New Issue