53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
|
const _ = require("lodash");
|
||
|
|
||
|
module.exports = {
|
||
|
name: 'api.conf',
|
||
|
dependencies: ["conf"],
|
||
|
settings: {
|
||
|
rest: "conf/",
|
||
|
},
|
||
|
actions: {
|
||
|
all: {
|
||
|
rest: "GET /",
|
||
|
handler(ctx) {
|
||
|
return this.broker.call("conf.all");
|
||
|
}
|
||
|
},
|
||
|
getPath: {
|
||
|
rest: "GET /:path",
|
||
|
handler(ctx) {
|
||
|
return this.broker.call("conf.get", ctx.params);
|
||
|
}
|
||
|
},
|
||
|
getKey: {
|
||
|
rest: "GET /:path/:key",
|
||
|
handler(ctx) {
|
||
|
return this.broker.call("conf.get", ctx.params);
|
||
|
}
|
||
|
},
|
||
|
set: {
|
||
|
rest: "POST /:path/:key",
|
||
|
handler(ctx) {
|
||
|
let value = _.clone(ctx.params);
|
||
|
_.unset(value, "path");
|
||
|
_.unset(value, "key");
|
||
|
return this.broker.mcall([
|
||
|
{action: "conf.set", params: {path: ctx.params.path, key: ctx.params.key, value}},
|
||
|
{action: "conf.save"}]).then(rs => {
|
||
|
return rs[0];
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
unset: {
|
||
|
rest: "DELETE /:path/:key",
|
||
|
handler(ctx) {
|
||
|
return this.broker.mcall([
|
||
|
{action: "conf.unset", params: ctx.params},
|
||
|
{action: "conf.save"}]).then(rs => {
|
||
|
return rs[0];
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|