Commit a74eabbd by Chavee Issariyapat

update api

parent e8a395fd
...@@ -30,6 +30,12 @@ module.exports = function (options = {}) { ...@@ -30,6 +30,12 @@ module.exports = function (options = {}) {
if (decoded) { if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' } if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { result: {error: 'not allowed'} } else response = { result: {error: 'not allowed'} }
if (options.debug) {
console.log('response:');
console.log(req.body);
}
res.send(response); res.send(response);
next(); next();
} }
......
...@@ -12,7 +12,10 @@ function getGroupID(token, client_id, callback) { ...@@ -12,7 +12,10 @@ function getGroupID(token, client_id, callback) {
} }
else { else {
doDB(client_id, function(group) { 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) { ...@@ -7,37 +7,67 @@ function rewriteTopic(topic, op, groupid, clientid, output) {
return modify.insertWordIntoTopic(topic, '!'+groupid, 1); return modify.insertWordIntoTopic(topic, '!'+groupid, 1);
case '@shadow' : case '@shadow' :
if (chunk[1] == 'set' || chunk[1] == 'overset' || chunk[1] == 'get') { if (chunk[1] == 'data') {
output.verb = chunk[1]; if (chunk[2]=='get' || chunk[2]=='update' || chunk[2].startsWith('get:') || chunk[2].startsWith('update:')) {
return modify.insertWordIntoTopic(topic, ''+clientid, 2); return modify.insertWordIntoTopic(topic, clientid, 3);
} }
else if (chunk[1] == 'write' || chunk[1] == 'overwrite' || chunk[1] == 'read') { else if (chunk[2]=='updated' ) {
output.verb = chunk[1]; return modify.insertWordIntoTopic(topic, '!'+clientid, 3);
return modify.insertWordIntoTopic(topic, groupid, 2);
} }
else if (chunk[1] == 'changed') { else if ( chunk[2].startsWith('updated:')) {
return modify.insertWordIntoTopic(topic, '!'+groupid, 3);
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 { else {
if ( chunk.length > 2 ) return topic;
return modify.insertWordIntoTopic(topic, '!'+groupid, 2); }
else if ( chunk.length == 2 ) }
return modify.insertWordIntoTopic(topic, '!'+clientid, 2); else if (chunk[1] == 'state') {
else return ""; 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' : case '@private' :
console.log(modify.insertWordIntoTopic(topic, '!'+clientid, 1));
return 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