Implement Pleroma config GET controller
This commit is contained in:
parent
8c972dbabd
commit
db3ee13baa
|
@ -44,7 +44,7 @@ import { instanceController } from './controllers/api/instance.ts';
|
||||||
import { mediaController } from './controllers/api/media.ts';
|
import { mediaController } from './controllers/api/media.ts';
|
||||||
import { notificationsController } from './controllers/api/notifications.ts';
|
import { notificationsController } from './controllers/api/notifications.ts';
|
||||||
import { createTokenController, oauthAuthorizeController, oauthController } from './controllers/api/oauth.ts';
|
import { createTokenController, oauthAuthorizeController, oauthController } from './controllers/api/oauth.ts';
|
||||||
import { frontendConfigController, updateConfigController } from './controllers/api/pleroma.ts';
|
import { configController, frontendConfigController, updateConfigController } from './controllers/api/pleroma.ts';
|
||||||
import { preferencesController } from './controllers/api/preferences.ts';
|
import { preferencesController } from './controllers/api/preferences.ts';
|
||||||
import { relayController } from './controllers/nostr/relay.ts';
|
import { relayController } from './controllers/nostr/relay.ts';
|
||||||
import { searchController } from './controllers/api/search.ts';
|
import { searchController } from './controllers/api/search.ts';
|
||||||
|
@ -187,6 +187,7 @@ app.get('/api/v1/bookmarks', requirePubkey, bookmarksController);
|
||||||
app.get('/api/v1/blocks', requirePubkey, blocksController);
|
app.get('/api/v1/blocks', requirePubkey, blocksController);
|
||||||
|
|
||||||
app.get('/api/v1/admin/accounts', adminAccountsController);
|
app.get('/api/v1/admin/accounts', adminAccountsController);
|
||||||
|
app.get('/api/v1/pleroma/admin/config', requireRole('admin'), configController);
|
||||||
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
app.post('/api/v1/pleroma/admin/config', requireRole('admin'), updateConfigController);
|
||||||
|
|
||||||
// Not (yet) implemented.
|
// Not (yet) implemented.
|
||||||
|
|
|
@ -15,8 +15,8 @@ const frontendConfigController: AppController = async (c) => {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
const configs = jsonSchema.pipe(z.array(configSchema)).parse(
|
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
||||||
event?.content ? await decryptAdmin(Conf.pubkey, event.content) : [],
|
event?.content ? await decryptAdmin(Conf.pubkey, event.content) : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
const frontendConfig = configs.find(({ group, key }) => group === ':pleroma' && key === ':frontend_configurations');
|
const frontendConfig = configs.find(({ group, key }) => group === ':pleroma' && key === ':frontend_configurations');
|
||||||
|
@ -33,6 +33,23 @@ const frontendConfigController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const configController: AppController = async (c) => {
|
||||||
|
const { pubkey } = Conf;
|
||||||
|
|
||||||
|
const [event] = await eventsDB.filter([{
|
||||||
|
kinds: [30078],
|
||||||
|
authors: [pubkey],
|
||||||
|
'#d': ['pub.ditto.pleroma.config'],
|
||||||
|
limit: 1,
|
||||||
|
}]);
|
||||||
|
|
||||||
|
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
||||||
|
event?.content ? await decryptAdmin(pubkey, event.content) : '',
|
||||||
|
);
|
||||||
|
|
||||||
|
return c.json({ configs, need_reboot: false });
|
||||||
|
};
|
||||||
|
|
||||||
/** Pleroma admin config controller. */
|
/** Pleroma admin config controller. */
|
||||||
const updateConfigController: AppController = async (c) => {
|
const updateConfigController: AppController = async (c) => {
|
||||||
const { pubkey } = Conf;
|
const { pubkey } = Conf;
|
||||||
|
@ -44,8 +61,8 @@ const updateConfigController: AppController = async (c) => {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
const configs = jsonSchema.pipe(z.array(configSchema)).parse(
|
const configs = jsonSchema.pipe(z.array(configSchema)).catch([]).parse(
|
||||||
event?.content ? await decryptAdmin(pubkey, event.content) : [],
|
event?.content ? await decryptAdmin(pubkey, event.content) : '',
|
||||||
);
|
);
|
||||||
|
|
||||||
const { configs: newConfigs } = z.object({ configs: z.array(configSchema) }).parse(await c.req.json());
|
const { configs: newConfigs } = z.object({ configs: z.array(configSchema) }).parse(await c.req.json());
|
||||||
|
@ -68,4 +85,4 @@ const updateConfigController: AppController = async (c) => {
|
||||||
return c.json({ configs: newConfigs, need_reboot: false });
|
return c.json({ configs: newConfigs, need_reboot: false });
|
||||||
};
|
};
|
||||||
|
|
||||||
export { frontendConfigController, updateConfigController };
|
export { configController, frontendConfigController, updateConfigController };
|
||||||
|
|
Loading…
Reference in New Issue