Commit a74eabbd by Chavee Issariyapat

update api

parent e8a395fd
......@@ -30,6 +30,12 @@ module.exports = function (options = {}) {
if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { result: {error: 'not allowed'} }
if (options.debug) {
console.log('response:');
console.log(req.body);
}
res.send(response);
next();
}
......
......@@ -12,7 +12,10 @@ function getGroupID(token, client_id, callback) {
}
else {
doDB(client_id, function(group) {
callback(group);
if (group) callback(group);
else callback(client_id); // fake group to isolate device
});
}
}
......
......@@ -7,37 +7,67 @@ function rewriteTopic(topic, op, groupid, clientid, output) {
return modify.insertWordIntoTopic(topic, '!'+groupid, 1);
case '@shadow' :
if (chunk[1] == 'set' || chunk[1] == 'overset' || chunk[1] == 'get') {
output.verb = chunk[1];
return modify.insertWordIntoTopic(topic, ''+clientid, 2);
if (chunk[1] == 'data') {
if (chunk[2]=='get' || chunk[2]=='update' || chunk[2].startsWith('get:') || chunk[2].startsWith('update:')) {
return modify.insertWordIntoTopic(topic, clientid, 3);
}
else if (chunk[1] == 'write' || chunk[1] == 'overwrite' || chunk[1] == 'read') {
output.verb = chunk[1];
return modify.insertWordIntoTopic(topic, groupid, 2);
else if (chunk[2]=='updated' ) {
return modify.insertWordIntoTopic(topic, '!'+clientid, 3);
}
else if (chunk[1] == 'changed') {
if (op == 'pub') {
if ( chunk.length > 2 )
return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
else if ( chunk.length == 2 )
return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
else return "";
else if ( chunk[2].startsWith('updated:')) {
return modify.insertWordIntoTopic(topic, '!'+groupid, 3);
}
else {
if ( chunk.length > 2 )
return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
else if ( chunk.length == 2 )
return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
else return "";
return topic;
}
}
else if (chunk[1] == 'state') {
if (chunk[2]=='get' || chunk[2]=='update' || chunk[2].startsWith('get:') || chunk[2].startsWith('update:')) {
return modify.insertWordIntoTopic(topic, clientid, 3);
}
else if (chunk[2]=='updated' || chunk[2]=='mismatched' ) {
return modify.insertWordIntoTopic(topic, '!'+clientid, 3);
}
else if ( chunk[2].startsWith('updated:') || chunk[2].startsWith('mismatched:')) {
return modify.insertWordIntoTopic(topic, '!'+groupid, 3);
}
else {
return topic;
}
}
else return "";
break;
// if (chunk[1] == 'set' || chunk[1] == 'overset' || chunk[1] == 'get') {
// output.verb = chunk[1];
// return modify.insertWordIntoTopic(topic, ''+clientid, 2);
// }
// else if (chunk[1] == 'write' || chunk[1] == 'overwrite' || chunk[1] == 'read') {
// output.verb = chunk[1];
// return modify.insertWordIntoTopic(topic, groupid, 2);
// }
// else if (chunk[1] == 'changed') {
// if (op == 'pub') {
// if ( chunk.length > 2 )
// return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
// else if ( chunk.length == 2 )
// return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
// else return "";
// }
// else {
// if ( chunk.length > 2 )
// return modify.insertWordIntoTopic(topic, '!'+groupid, 2);
// else if ( chunk.length == 2 )
// return modify.insertWordIntoTopic(topic, '!'+clientid, 2);
// else return "";
// }
// }
// else return "";
case '@private' :
console.log(modify.insertWordIntoTopic(topic, '!'+clientid, 1));
return modify.insertWordIntoTopic(topic, '!'+clientid, 1);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment