mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 20:45:58 +01:00
feat: management of API tokens via ACP
This commit is contained in:
@@ -10,6 +10,8 @@ const request = require('request-promise-native');
|
||||
|
||||
const user = require('../user');
|
||||
const posts = require('../posts');
|
||||
const utils = require('../utils');
|
||||
|
||||
const { pluginNamePattern, themeNamePattern, paths } = require('../constants');
|
||||
|
||||
var app;
|
||||
@@ -121,6 +123,7 @@ Plugins.reload = async function () {
|
||||
console.log('');
|
||||
}
|
||||
|
||||
// Possibly put these in a different file...
|
||||
Plugins.registerHook('core', {
|
||||
hook: 'filter:parse.post',
|
||||
method: async (data) => {
|
||||
@@ -147,6 +150,26 @@ Plugins.reload = async function () {
|
||||
},
|
||||
});
|
||||
|
||||
Plugins.registerHook('core', {
|
||||
hook: 'filter:settings.set',
|
||||
method: async ({ plugin, settings, quiet }) => {
|
||||
if (plugin === 'core.api' && Array.isArray(settings.tokens)) {
|
||||
// Generate tokens if not present already
|
||||
settings.tokens.forEach((set) => {
|
||||
if (set.token === '') {
|
||||
set.token = utils.generateUUID();
|
||||
}
|
||||
|
||||
if (isNaN(parseInt(set.uid, 10))) {
|
||||
set.uid = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return { plugin, settings, quiet };
|
||||
},
|
||||
});
|
||||
|
||||
// Lower priority runs earlier
|
||||
Object.keys(Plugins.loadedHooks).forEach(function (hook) {
|
||||
Plugins.loadedHooks[hook].sort((a, b) => a.priority - b.priority);
|
||||
|
||||
Reference in New Issue
Block a user