mirror of
https://github.com/unraid/api.git
synced 2026-01-07 17:19:52 -06:00
add log for ws dis/connect and fix publish for non-plugin modules
Signed-off-by: Alexis Tyler <xo@wvvw.me>
This commit is contained in:
@@ -277,22 +277,31 @@ module.exports = function (
|
||||
throw new AppError('Invalid apikey.');
|
||||
}
|
||||
};
|
||||
|
||||
// Connected ws clients
|
||||
const clients = new Map();
|
||||
|
||||
return {
|
||||
schema,
|
||||
types,
|
||||
resolvers,
|
||||
subscriptions: {
|
||||
onConnect: connectionParams => {
|
||||
console.log(`Subscription client connected using Apollo server's built-in SubscriptionServer.`)
|
||||
onConnect: (connectionParams, webSocket) => {
|
||||
const apiKey = connectionParams['x-api-key'];
|
||||
ensureApiKey(apiKey);
|
||||
|
||||
const user = Users.findOne({ apiKey }) || { name: 'guest', apiKey, role: 'guest' };
|
||||
|
||||
log.debug(`<ws> ${user.name} connected.`);
|
||||
clients.set(webSocket, user);
|
||||
|
||||
return {
|
||||
user
|
||||
};
|
||||
},
|
||||
onDisconnect: webSocket => {
|
||||
const user = clients.get(webSocket);
|
||||
log.debug(`<ws> ${user.name} disconnected.`);
|
||||
}
|
||||
},
|
||||
context: ({ req, connection }) => {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Written by: Alexis Tyler
|
||||
*/
|
||||
|
||||
module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pubsub, setIntervalAsync, PluginManager) {
|
||||
module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pubsub, setIntervalAsync, PluginManager, log) {
|
||||
const publish = (channel, mutation, {
|
||||
node = undefined,
|
||||
moduleToRun = undefined,
|
||||
@@ -34,15 +34,29 @@ module.exports = function ($injector, GraphQLJSON, GraphQLLong, GraphQLUUID, pub
|
||||
result = result();
|
||||
}
|
||||
|
||||
if (filePath) {
|
||||
const [pluginName, moduleName] = channel.split('/');
|
||||
log.debug('Plugin:', pluginName, 'Module:', moduleName, 'Result:', result);
|
||||
} else {
|
||||
log.debug('Module:', channel, 'Result:', result);
|
||||
}
|
||||
|
||||
// Update "node"
|
||||
pubsub.publish(channel, {
|
||||
pluginModule: {
|
||||
[filePath ? 'pluginModule' : channel]: {
|
||||
mutation,
|
||||
node: result.json
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
// Ensure we aren't leaking anything in production
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
log.debug('Error:', error.message);
|
||||
}
|
||||
|
||||
const logger = log[error.status && error.status >= 400 ? 'error' : 'warn'];
|
||||
logger('Error:', error.message);
|
||||
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, interval);
|
||||
|
||||
Reference in New Issue
Block a user