Commit 260771ae by zCaesar

add unsub

parent 3d0afcba
......@@ -13,6 +13,7 @@ var auth_on_subscribe = require('./auth_on_subscribe')({ debug: auth_on_subscrib
var on_publish = require('./on_publish')({ debug: on_publish_debug });
var on_deliver = require('./on_deliver').on_deliver
var signRole = require('./checkClientRole').signRole
var on_unsubscribe = require('./on_unsubscribe').on_unsubscribe
const server = restify.createServer({
name: 'authhook',
......@@ -39,6 +40,7 @@ server.post('/onsub', (req,res,next) => {
console.log(req.body)
res.send('')
})
server.post('/onunsub', on_unsubscribe)
server.post('/ondeliver', on_deliver)
server.post('/onpub', on_publish)
server.post('/signRole', signRole)
......
......@@ -19,6 +19,7 @@ function hasGroup(topics) {
}
else return false
}
module.exports.hasGroup = hasGroup
function beDesireTopic(topics) {
if (hasGroup(topics)) {
......@@ -26,8 +27,10 @@ function beDesireTopic(topics) {
}
else return topics
}
module.exports.beDesireTopic = beDesireTopic
function joinTopic(topics) {
var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length)
}
\ No newline at end of file
}
module.exports.joinTopic = joinTopic
\ No newline at end of file
function on_unsubscribe(req, res, next) {
console.log('------on unsubscribe-------')
console.log(req.body)
var topic = req.body.topics[0];
// checkRole
var checkRealDB = require('./checkClientRole').checkRealDB
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _ftopic = require('./utils/getTopic').getTopic(topic, _id) // get topic where concat with groupID
var response = {
"result": "ok",
"topics": [_ftopic]
}
console.log(response)
res.send(response);
})
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
}
console.log(response)
res.send(response);
}
}
})
}
module.exports.on_unsubscribe = on_unsubscribe
\ No newline at end of file
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