This commit is contained in:
Bryan Ashby 2023-01-06 13:49:13 -07:00
parent d615b53f1f
commit 848044bec6
No known key found for this signature in database
GPG Key ID: C2C1B501E4EFD994
3 changed files with 1012 additions and 998 deletions

View File

@ -49,18 +49,18 @@ class Route {
isValid() { isValid() {
return ( return (
(this.pathRegExp instanceof RegExp && (this.pathRegExp instanceof RegExp &&
-1 !== -1 !==
[ [
'GET', 'GET',
'HEAD', 'HEAD',
'POST', 'POST',
'PUT', 'PUT',
'DELETE', 'DELETE',
'CONNECT', 'CONNECT',
'OPTIONS', 'OPTIONS',
'TRACE', 'TRACE',
].indexOf(this.method)) || ].indexOf(this.method)) ||
!_.isFunction(this.handler) !_.isFunction(this.handler)
); );
} }
@ -96,13 +96,13 @@ exports.getModule = class WebServerModule extends ServerModule {
} }
buildUrl(pathAndQuery) { buildUrl(pathAndQuery) {
// //
// Create a URL such as // Create a URL such as
// https://l33t.codes:44512/ + |pathAndQuery| // https://l33t.codes:44512/ + |pathAndQuery|
// //
// Prefer HTTPS over HTTP. Be explicit about the port // Prefer HTTPS over HTTP. Be explicit about the port
// only if non-standard. Allow users to override full prefix in config. // only if non-standard. Allow users to override full prefix in config.
// //
const config = Config(); const config = Config();
if (_.isString(config.contentServers.web.overrideUrlPrefix)) { if (_.isString(config.contentServers.web.overrideUrlPrefix)) {
return `${config.contentServers.web.overrideUrlPrefix}${pathAndQuery}`; return `${config.contentServers.web.overrideUrlPrefix}${pathAndQuery}`;
@ -113,15 +113,15 @@ exports.getModule = class WebServerModule extends ServerModule {
if (config.contentServers.web.https.enabled) { if (config.contentServers.web.https.enabled) {
schema = 'https://'; schema = 'https://';
port = port =
443 === config.contentServers.web.https.port 443 === config.contentServers.web.https.port
? '' ? ''
: `:${config.contentServers.web.https.port}`; : `:${config.contentServers.web.https.port}`;
} else { } else {
schema = 'http://'; schema = 'http://';
port = port =
80 === config.contentServers.web.http.port 80 === config.contentServers.web.http.port
? '' ? ''
: `:${config.contentServers.web.http.port}`; : `:${config.contentServers.web.http.port}`;
} }
return `${schema}${config.contentServers.web.domain}${port}${pathAndQuery}`; return `${schema}${config.contentServers.web.domain}${port}${pathAndQuery}`;
@ -168,11 +168,17 @@ exports.getModule = class WebServerModule extends ServerModule {
try { try {
const normalizedName = _.camelCase(module.moduleInfo.name); const normalizedName = _.camelCase(module.moduleInfo.name);
if (!WebHandlerModule.isEnabled(normalizedName)) { if (!WebHandlerModule.isEnabled(normalizedName)) {
Log.info({ moduleName: normalizedName }, 'Skipping web handler module - not enabled.'); Log.info(
{ moduleName: normalizedName },
'Skipping web handler module - not enabled.'
);
return nextModule(null); return nextModule(null);
} }
Log.info({ moduleName: normalizedName }, 'Initializing web handler module.'); Log.info(
{ moduleName: normalizedName },
'Initializing web handler module.'
);
moduleInst.init(err => { moduleInst.init(err => {
return nextModule(err); return nextModule(err);
@ -329,8 +335,8 @@ exports.getModule = class WebServerModule extends ServerModule {
const headers = { const headers = {
'Content-Type': 'Content-Type':
mimeTypes.contentType(paths.basename(filePath)) || mimeTypes.contentType(paths.basename(filePath)) ||
mimeTypes.contentType('.bin'), mimeTypes.contentType('.bin'),
'Content-Length': stats.size, 'Content-Length': stats.size,
}; };
@ -362,8 +368,8 @@ exports.getModule = class WebServerModule extends ServerModule {
const headers = { const headers = {
'Content-Type': 'Content-Type':
mimeTypes.contentType(paths.basename(filePath)) || mimeTypes.contentType(paths.basename(filePath)) ||
mimeTypes.contentType('.bin'), mimeTypes.contentType('.bin'),
'Content-Length': stats.size, 'Content-Length': stats.size,
}; };

View File

@ -58,7 +58,10 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
userFromAccount(accountName, (err, user) => { userFromAccount(accountName, (err, user) => {
if (err) { if (err) {
Log.info({ accountName: accountName }, 'Unable to find user from account retrieving self url.'); Log.info(
{ accountName: accountName },
'Unable to find user from account retrieving self url.'
);
return this._notFound(resp); return this._notFound(resp);
} }
@ -71,23 +74,21 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
if (sendActor) { if (sendActor) {
return this._selfAsActorHandler(user, req, resp); return this._selfAsActorHandler(user, req, resp);
} } else {
else {
return this._standardSelfHandler(user, req, resp); return this._standardSelfHandler(user, req, resp);
} }
}); });
} }
_selfAsActorHandler(user, req, resp) { _selfAsActorHandler(user, req, resp) {
const selfUrl = selfUrl(this.webServer, user);
const sUrl = selfUrl(this.webServer, user);
const bodyJson = { const bodyJson = {
'@context': [ '@context': [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
], ],
id: sUrl, id: selfUrl,
type: 'Person', type: 'Person',
preferredUsername: user.username, preferredUsername: user.username,
name: user.getSanitizedName('real'), name: user.getSanitizedName('real'),
@ -105,11 +106,14 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule {
}; };
const publicKeyPem = user.getProperty(UserProps.PublicKeyMain); const publicKeyPem = user.getProperty(UserProps.PublicKeyMain);
if (!(_.isEmpty(publicKeyPem))) { if (!_.isEmpty(publicKeyPem)) {
bodyJson['publicKey'] = { id: sUrl + '#main-key', owner: sUrl, publicKeyPem: user.getProperty(UserProps.PublicKeyMain) }; bodyJson['publicKey'] = {
} id: selfUrl + '#main-key',
else { owner: sUrl,
Log.debug({ User: user.username }, 'User does not have a publickey.'); publicKeyPem: user.getProperty(UserProps.PublicKeyMain),
};
} else {
Log.debug({ username: user.username }, 'User does not have a publickey.');
} }
const body = JSON.stringify(bodyJson); const body = JSON.stringify(bodyJson);

File diff suppressed because it is too large Load Diff