mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fixed initializing ActivityPub webhooks when enabled after boot
ref https://linear.app/ghost/issue/AP-644/fix-enabling-activitypub-service-when-flag-is-enabled - right now, we only set up the ActivityPub webhooks if the service is initialized at boot - so if the flag is enabled after boot, the webhooks aren't setup - this changes that to allow initializing the service either at boot, or when the labs setting is changed (and ActivityPub flag is enabled)
This commit is contained in:
parent
2cc1e28eca
commit
1d2e7c2000
1 changed files with 18 additions and 13 deletions
|
@ -4,30 +4,27 @@ module.exports = class ActivityPubServiceWrapper {
|
||||||
/** @type ActivityPubService */
|
/** @type ActivityPubService */
|
||||||
static instance;
|
static instance;
|
||||||
|
|
||||||
|
static initialised = false;
|
||||||
|
|
||||||
static async init() {
|
static async init() {
|
||||||
if (ActivityPubServiceWrapper.instance) {
|
if (ActivityPubServiceWrapper.instance) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const labs = require('../../../shared/labs');
|
|
||||||
|
|
||||||
if (!labs.isSet('ActivityPub')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const urlUtils = require('../../../shared/url-utils');
|
|
||||||
const siteUrl = new URL(urlUtils.getSiteUrl());
|
|
||||||
|
|
||||||
const db = require('../../data/db');
|
|
||||||
const knex = db.knex;
|
|
||||||
|
|
||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
|
const events = require('../../lib/common/events');
|
||||||
|
const {knex} = require('../../data/db');
|
||||||
|
const labs = require('../../../shared/labs');
|
||||||
|
const urlUtils = require('../../../shared/url-utils');
|
||||||
const IdentityTokenServiceWrapper = require('../identity-tokens');
|
const IdentityTokenServiceWrapper = require('../identity-tokens');
|
||||||
|
|
||||||
if (!IdentityTokenServiceWrapper.instance) {
|
if (!IdentityTokenServiceWrapper.instance) {
|
||||||
logging.error(`IdentityTokenService needs to be initialised before ActivityPubService`);
|
logging.error(`IdentityTokenService needs to be initialised before ActivityPubService`);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const siteUrl = new URL(urlUtils.getSiteUrl());
|
||||||
|
|
||||||
ActivityPubServiceWrapper.instance = new ActivityPubService(
|
ActivityPubServiceWrapper.instance = new ActivityPubService(
|
||||||
knex,
|
knex,
|
||||||
siteUrl,
|
siteUrl,
|
||||||
|
@ -35,8 +32,16 @@ module.exports = class ActivityPubServiceWrapper {
|
||||||
IdentityTokenServiceWrapper.instance
|
IdentityTokenServiceWrapper.instance
|
||||||
);
|
);
|
||||||
|
|
||||||
if (labs.isSet('ActivityPub') && IdentityTokenServiceWrapper.instance) {
|
if (labs.isSet('ActivityPub')) {
|
||||||
await ActivityPubServiceWrapper.instance.initialiseWebhooks();
|
await ActivityPubServiceWrapper.instance.initialiseWebhooks();
|
||||||
|
ActivityPubServiceWrapper.initialised = true;
|
||||||
|
} else {
|
||||||
|
events.on('settings.labs.edited', async () => {
|
||||||
|
if (labs.isSet('ActivityPub') && !ActivityPubServiceWrapper.initialised) {
|
||||||
|
await ActivityPubServiceWrapper.instance.initialiseWebhooks();
|
||||||
|
ActivityPubServiceWrapper.initialised = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue