mirror of
https://github.com/unraid/api.git
synced 2026-01-28 19:49:08 -06:00
fix: add plugin support back and disable release needing test/lint
This commit is contained in:
@@ -13,8 +13,8 @@ import gql from 'graphql-tag';
|
||||
import { typeDefs, resolvers } from './schema';
|
||||
import { increaseWsConectionCount, decreaseWsConectionCount } from '../ws';
|
||||
|
||||
const { apiManager, errors, log, states, config } = core;
|
||||
const { AppError, FatalAppError } = errors;
|
||||
const { apiManager, errors, log, states, config, pluginManager } = core;
|
||||
const { AppError, FatalAppError, PluginError } = errors;
|
||||
const { usersState } = states;
|
||||
|
||||
const baseTypes = [gql`
|
||||
@@ -135,6 +135,26 @@ const types = mergeTypes([
|
||||
typeDefs
|
||||
]);
|
||||
|
||||
const getCoreModule = (moduleName) => {
|
||||
if (!Object.keys(core.modules).includes(moduleName)) {
|
||||
throw new FatalAppError(`"${moduleName}" is not a valid core module.`);
|
||||
}
|
||||
|
||||
return core.modules[moduleName];
|
||||
};
|
||||
|
||||
const getPluginModule = (pluginName, pluginModuleName) => {
|
||||
if (!pluginManager.isInstalled(pluginName, pluginModuleName)) {
|
||||
throw new PluginError('Plugin not installed.');
|
||||
}
|
||||
|
||||
if (!pluginManager.isActive(pluginName, pluginModuleName)) {
|
||||
throw new PluginError('Plugin disabled.');
|
||||
}
|
||||
|
||||
return pluginManager.get(pluginName, pluginModuleName);
|
||||
};
|
||||
|
||||
/**
|
||||
* Func directive
|
||||
*
|
||||
@@ -171,24 +191,6 @@ class FuncDirective extends SchemaDirectiveVisitor {
|
||||
...directiveArgs.data,
|
||||
...(operationType === 'mutation' ? input : {})
|
||||
};
|
||||
// let funcPath = path.join(coreCwd, moduleName + '.js');
|
||||
|
||||
// If we're looking for a plugin verify it's installed and active first
|
||||
// if (pluginName) {
|
||||
// if (!PluginManager.isInstalled(pluginName, pluginModuleName)) {
|
||||
// throw new PluginError('Plugin not installed.');
|
||||
// }
|
||||
|
||||
// if (!PluginManager.isActive(pluginName, pluginModuleName)) {
|
||||
// throw new PluginError('Plugin disabled.');
|
||||
// }
|
||||
|
||||
// const pluginModule = PluginManager.get(pluginName, pluginModuleName);
|
||||
// // Update plugin funcPath
|
||||
// funcPath = pluginModule.filePath;
|
||||
// }
|
||||
|
||||
// Create func context
|
||||
// If query @func(param_1, param_2, input: query?)
|
||||
// If mutation @func(param_1, param_2, input: data)
|
||||
const context = {
|
||||
@@ -201,15 +203,15 @@ class FuncDirective extends SchemaDirectiveVisitor {
|
||||
// Resolve func
|
||||
let func;
|
||||
|
||||
if (!Object.keys(core.modules).includes(moduleName)) {
|
||||
throw new FatalAppError(`"${moduleName}" is not a valid core module.`);
|
||||
}
|
||||
|
||||
try {
|
||||
func = core.modules[moduleName]
|
||||
} catch (error_) {
|
||||
if (pluginName) {
|
||||
func = getPluginModule(pluginName, pluginModuleName);
|
||||
} else {
|
||||
func = getCoreModule(moduleName);
|
||||
}
|
||||
} catch (error) {
|
||||
// Rethrow clean error message about module being missing
|
||||
if (error_.code === 'MODULE_NOT_FOUND') {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
throw new AppError(`Cannot find ${pluginName ? 'Plugin: "' + pluginName + '" ' : ''}Module: "${pluginName ? pluginModuleName : moduleName}"`);
|
||||
}
|
||||
|
||||
@@ -219,14 +221,14 @@ class FuncDirective extends SchemaDirectiveVisitor {
|
||||
}
|
||||
|
||||
// Otherwise re-throw actual error
|
||||
throw error_;
|
||||
throw error;
|
||||
}
|
||||
|
||||
const pluginOrModule = pluginName ? 'Plugin:' : 'Module:';
|
||||
const pluginOrModuleName = pluginModuleName || moduleName;
|
||||
|
||||
// Run function
|
||||
let [error, result] = await Promise.resolve(func(context))
|
||||
let [error, result] = await Promise.resolve(func(context, core))
|
||||
.then(result => [undefined, result])
|
||||
.catch(error_ => {
|
||||
// Ensure we aren't leaking anything in production
|
||||
|
||||
@@ -18,7 +18,7 @@ type InfoCpu {
|
||||
# ''
|
||||
revision: String!
|
||||
# ''
|
||||
voltage: Float
|
||||
voltage: String
|
||||
# '2.27'
|
||||
speed: Float!
|
||||
# '1.60'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CoreResult } from '@unraid/core/interfaces';
|
||||
import { CoreResult } from '@unraid/core/dist/interfaces';
|
||||
import * as core from '@unraid/core'
|
||||
import { getWsConectionCount } from './ws';
|
||||
|
||||
@@ -43,7 +43,6 @@ export const run = async (channel: string, mutation: string, options: RunOptions
|
||||
const {
|
||||
node,
|
||||
moduleToRun,
|
||||
// moduleToRun,
|
||||
// filePath,
|
||||
context
|
||||
} = options;
|
||||
@@ -63,11 +62,6 @@ export const run = async (channel: string, mutation: string, options: RunOptions
|
||||
return resolve(moduleToRun(context));
|
||||
});
|
||||
|
||||
// if (filePath) {
|
||||
// const [pluginName, moduleName] = channel.split('/');
|
||||
// log.debug('Plugin:', pluginName, 'Module:', moduleName, 'Result:', result);
|
||||
// }
|
||||
|
||||
log.debug('Module:', moduleToRun.name, 'Result:', result.json);
|
||||
|
||||
// Update pubsub channel
|
||||
|
||||
Reference in New Issue
Block a user