0
0
mirror of https://github.com/openwrt/luci.git synced 2025-02-07 02:19:53 +00:00
George Sapkin f32d9204a7 luci-app-example: rewrite RPC side using ucode
Signed-off-by: George Sapkin <george@sapk.in>
2025-02-03 15:07:18 +01:00

49 lines
949 B
Ucode
Executable File

#!/usr/bin/env ucode
'use strict';
import { cursor } from 'uci';
// Rather than parse files in /etc/config, we can use `cursor`.
const uci = cursor();
const methods = {
get_sample1: {
call: function() {
const num_cats = uci.get('example', 'animals', 'num_cats');
const num_dogs = uci.get('example', 'animals', 'num_dogs');
const num_parakeets = uci.get('example', 'animals', 'num_parakeets');
const result = {
num_cats,
num_dogs,
num_parakeets,
is_this_real: false,
not_found: null,
};
uci.unload();
return result;
}
},
get_sample2: {
call: function() {
const result = {
option_one: {
name: "Some string value",
value: "A value string",
parakeets: ["one", "two", "three"],
},
option_two: {
name: "Another string value",
value: "And another value",
parakeets: [3, 4, 5],
},
};
return result;
}
}
};
return { 'luci.example': methods };