Central check for enable/disabled web handlers, added some utility functions, etc.

This commit is contained in:
Bryan Ashby 2023-01-03 15:10:39 -07:00
parent 99e9ebbec9
commit 127e9794ee
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
3 changed files with 20 additions and 11 deletions

9
core/activitypub_util.js Normal file
View File

@ -0,0 +1,9 @@
const { WellKnownLocations } = require('./servers/content/web');
exports.buildSelfUrl = buildSelfUrl;
function buildSelfUrl(webServer, user, relPrefix) {
return webServer.buildUrl(
WellKnownLocations.Internal + `${relPrefix}${user.username}`
);
}

View File

@ -5,7 +5,9 @@
const Log = require('../../logger.js').log;
const ServerModule = require('../../server_module.js').ServerModule;
const Config = require('../../config.js').get;
const { Errors } = require('../../enig_error.js');
const { Errors, ErrorReasons } = require('../../enig_error.js');
const { loadModulesForCategory, moduleCategories } = require('../../module_util');
const WebHandlerModule = require('../../web_handler_module');
// deps
const http = require('http');
@ -17,8 +19,6 @@ const mimeTypes = require('mime-types');
const forEachSeries = require('async/forEachSeries');
const findSeries = require('async/findSeries');
const { loadModulesForCategory, moduleCategories } = require('../../module_util');
const ModuleInfo = (exports.moduleInfo = {
name: 'Web',
desc: 'Web Server',
@ -166,6 +166,11 @@ exports.getModule = class WebServerModule extends ServerModule {
(module, nextModule) => {
const moduleInst = new module.getModule();
try {
const normalizedName = _.camelCase(module.moduleInfo.name);
if (!WebHandlerModule.isEnabled(normalizedName)) {
return nextModule(null);
}
moduleInst.init(err => {
return nextModule(err);
});

View File

@ -2,6 +2,7 @@ const WebHandlerModule = require('../../../web_handler_module');
const Config = require('../../../config').get;
const { Errors, ErrorReasons } = require('../../../enig_error');
const { WellKnownLocations } = require('../web');
const { buildSelfUrl } = require('../../../activitypub_util');
const _ = require('lodash');
const User = require('../../../user');
@ -17,7 +18,7 @@ exports.moduleInfo = {
name: 'WebFinger',
desc: 'A simple WebFinger Handler.',
author: 'NuSkooler, CognitiveGears',
packageName: 'codes.l33t.enigma.web.handler.finger',
packageName: 'codes.l33t.enigma.web.handler.webfinger',
};
// :TODO: more info in default
@ -41,10 +42,6 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
init(cb) {
const config = Config();
if (!WebHandlerModule.isEnabled('webFinger')) {
return cb(null);
}
// we rely on the web server
this.webServer = WebHandlerModule.getWebServer();
if (!this.webServer || !this.webServer.isEnabled()) {
@ -251,9 +248,7 @@ exports.getModule = class WebFingerWebHandler extends WebHandlerModule {
}
_selfUrl(user) {
return this.webServer.buildUrl(
WellKnownLocations.Internal + `/ap/users/${user.username}`
);
return buildSelfUrl(this.webServer, user, '/ap/users/');
}
// :TODO: only if ActivityPub is enabled