mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-07 23:54:22 +01:00
Implement frontend configurations
This commit is contained in:
@@ -1,7 +1,46 @@
|
||||
import { type AppController } from '@/app.ts';
|
||||
import * as eventsDB from '@/db/events.ts';
|
||||
import { z } from '@/deps.ts';
|
||||
import { configSchema, elixirTupleSchema } from '@/schemas/pleroma-api.ts';
|
||||
import { createAdminEvent } from '@/utils/web.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
|
||||
const frontendConfigController: AppController = async (c) => {
|
||||
const [event] = await eventsDB.getFilters(
|
||||
[{ kinds: [30078], authors: [Conf.pubkey], limit: 1 }],
|
||||
);
|
||||
|
||||
if (event) {
|
||||
const data = JSON.parse(event.content);
|
||||
return c.json(data);
|
||||
}
|
||||
|
||||
const frontendConfigController: AppController = (c) => {
|
||||
return c.json({});
|
||||
};
|
||||
|
||||
export { frontendConfigController };
|
||||
/** Pleroma admin config controller. */
|
||||
const updateConfigController: AppController = async (c) => {
|
||||
const json = await c.req.json();
|
||||
const { configs } = z.object({ configs: z.array(configSchema) }).parse(json);
|
||||
|
||||
for (const { group, key, value } of configs) {
|
||||
if (group === ':pleroma' && key === ':frontend_configurations') {
|
||||
const schema = elixirTupleSchema.transform(({ tuple }) => tuple).array();
|
||||
|
||||
const data = schema.parse(value).reduce<Record<string, unknown>>((result, [name, data]) => {
|
||||
result[name.replace(/^:/, '')] = data;
|
||||
return result;
|
||||
}, {});
|
||||
|
||||
await createAdminEvent({
|
||||
kind: 30078,
|
||||
content: JSON.stringify(data),
|
||||
tags: [['d', 'pub.ditto.frontendConfig']],
|
||||
}, c);
|
||||
}
|
||||
}
|
||||
|
||||
return c.json([]);
|
||||
};
|
||||
|
||||
export { frontendConfigController, updateConfigController };
|
||||
|
||||
Reference in New Issue
Block a user