Support Pleroma admin tags
This commit is contained in:
parent
284ae9aab7
commit
d2238e80f9
|
@ -42,6 +42,8 @@ import {
|
||||||
configController,
|
configController,
|
||||||
frontendConfigController,
|
frontendConfigController,
|
||||||
pleromaAdminDeleteStatusController,
|
pleromaAdminDeleteStatusController,
|
||||||
|
pleromaAdminTagController,
|
||||||
|
pleromaAdminUntagController,
|
||||||
updateConfigController,
|
updateConfigController,
|
||||||
} from '@/controllers/api/pleroma.ts';
|
} from '@/controllers/api/pleroma.ts';
|
||||||
import { preferencesController } from '@/controllers/api/preferences.ts';
|
import { preferencesController } from '@/controllers/api/preferences.ts';
|
||||||
|
@ -253,6 +255,9 @@ app.post(
|
||||||
|
|
||||||
app.post('/api/v1/admin/accounts/:id{[0-9a-f]{64}}/action', requireSigner, requireRole('admin'), adminActionController);
|
app.post('/api/v1/admin/accounts/:id{[0-9a-f]{64}}/action', requireSigner, requireRole('admin'), adminActionController);
|
||||||
|
|
||||||
|
app.put('/api/v1/pleroma/admin/users/tag', requireRole('admin'), pleromaAdminTagController);
|
||||||
|
app.delete('/api/v1/pleroma/admin/users/tag', requireRole('admin'), pleromaAdminUntagController);
|
||||||
|
|
||||||
// Not (yet) implemented.
|
// Not (yet) implemented.
|
||||||
app.get('/api/v1/custom_emojis', emptyArrayController);
|
app.get('/api/v1/custom_emojis', emptyArrayController);
|
||||||
app.get('/api/v1/filters', emptyArrayController);
|
app.get('/api/v1/filters', emptyArrayController);
|
||||||
|
|
|
@ -6,7 +6,8 @@ import { Conf } from '@/config.ts';
|
||||||
import { configSchema, elixirTupleSchema, type PleromaConfig } from '@/schemas/pleroma-api.ts';
|
import { configSchema, elixirTupleSchema, type PleromaConfig } from '@/schemas/pleroma-api.ts';
|
||||||
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||||
import { Storages } from '@/storages.ts';
|
import { Storages } from '@/storages.ts';
|
||||||
import { createAdminEvent } from '@/utils/api.ts';
|
import { createAdminEvent, updateAdminEvent } from '@/utils/api.ts';
|
||||||
|
import { lookupPubkey } from '@/utils/lookup.ts';
|
||||||
|
|
||||||
const frontendConfigController: AppController = async (c) => {
|
const frontendConfigController: AppController = async (c) => {
|
||||||
const store = await Storages.db();
|
const store = await Storages.db();
|
||||||
|
@ -87,4 +88,70 @@ async function getConfigs(store: NStore, signal: AbortSignal): Promise<PleromaCo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { configController, frontendConfigController, pleromaAdminDeleteStatusController, updateConfigController };
|
const pleromaAdminTagsSchema = z.object({
|
||||||
|
nicknames: z.string().array(),
|
||||||
|
tags: z.string().array(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const pleromaAdminTagController: AppController = async (c) => {
|
||||||
|
const params = pleromaAdminTagsSchema.parse(await c.req.json());
|
||||||
|
|
||||||
|
for (const nickname of params.nicknames) {
|
||||||
|
const pubkey = await lookupPubkey(nickname);
|
||||||
|
if (!pubkey) continue;
|
||||||
|
|
||||||
|
await updateAdminEvent(
|
||||||
|
{ kinds: [30382], authors: [Conf.pubkey], '#d': [pubkey], limit: 1 },
|
||||||
|
(prev) => {
|
||||||
|
const tags = prev?.tags ?? [['d', pubkey]];
|
||||||
|
|
||||||
|
for (const tag of params.tags) {
|
||||||
|
const existing = prev?.tags.some(([name, value]) => name === 't' && value === tag);
|
||||||
|
if (!existing) {
|
||||||
|
tags.push(['t', tag]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
kind: 30382,
|
||||||
|
content: prev?.content ?? '',
|
||||||
|
tags,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
c,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(null, { status: 204 });
|
||||||
|
};
|
||||||
|
|
||||||
|
const pleromaAdminUntagController: AppController = async (c) => {
|
||||||
|
const params = pleromaAdminTagsSchema.parse(await c.req.json());
|
||||||
|
|
||||||
|
for (const nickname of params.nicknames) {
|
||||||
|
const pubkey = await lookupPubkey(nickname);
|
||||||
|
if (!pubkey) continue;
|
||||||
|
|
||||||
|
await updateAdminEvent(
|
||||||
|
{ kinds: [30382], authors: [Conf.pubkey], '#d': [pubkey], limit: 1 },
|
||||||
|
(prev) => ({
|
||||||
|
kind: 30382,
|
||||||
|
content: prev?.content ?? '',
|
||||||
|
tags: (prev?.tags ?? [['d', pubkey]])
|
||||||
|
.filter(([name, value]) => !(name === 't' && params.tags.includes(value))),
|
||||||
|
}),
|
||||||
|
c,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Response(null, { status: 204 });
|
||||||
|
};
|
||||||
|
|
||||||
|
export {
|
||||||
|
configController,
|
||||||
|
frontendConfigController,
|
||||||
|
pleromaAdminDeleteStatusController,
|
||||||
|
pleromaAdminTagController,
|
||||||
|
pleromaAdminUntagController,
|
||||||
|
updateConfigController,
|
||||||
|
};
|
||||||
|
|
|
@ -73,6 +73,8 @@ function updateListEvent(
|
||||||
async function createAdminEvent(t: EventStub, c: AppContext): Promise<NostrEvent> {
|
async function createAdminEvent(t: EventStub, c: AppContext): Promise<NostrEvent> {
|
||||||
const signer = new AdminSigner();
|
const signer = new AdminSigner();
|
||||||
|
|
||||||
|
console.log(t);
|
||||||
|
|
||||||
const event = await signer.signEvent({
|
const event = await signer.signEvent({
|
||||||
content: '',
|
content: '',
|
||||||
created_at: nostrNow(),
|
created_at: nostrNow(),
|
||||||
|
@ -125,7 +127,7 @@ async function updateUser(pubkey: string, n: Record<string, boolean>, c: AppCont
|
||||||
|
|
||||||
return {
|
return {
|
||||||
kind: 30382,
|
kind: 30382,
|
||||||
content: prev?.content,
|
content: prev?.content ?? '',
|
||||||
tags: [
|
tags: [
|
||||||
['d', pubkey],
|
['d', pubkey],
|
||||||
...nTags,
|
...nTags,
|
||||||
|
@ -294,6 +296,7 @@ export {
|
||||||
type PaginationParams,
|
type PaginationParams,
|
||||||
paginationSchema,
|
paginationSchema,
|
||||||
parseBody,
|
parseBody,
|
||||||
|
updateAdminEvent,
|
||||||
updateEvent,
|
updateEvent,
|
||||||
updateListAdminEvent,
|
updateListAdminEvent,
|
||||||
updateListEvent,
|
updateListEvent,
|
||||||
|
|
|
@ -81,6 +81,7 @@ async function renderAccount(
|
||||||
is_moderator: roles.has('admin') || roles.has('moderator'),
|
is_moderator: roles.has('admin') || roles.has('moderator'),
|
||||||
is_local: parsed05?.domain === Conf.url.host,
|
is_local: parsed05?.domain === Conf.url.host,
|
||||||
settings_store: undefined as unknown,
|
settings_store: undefined as unknown,
|
||||||
|
tags: [...getTagSet(event.user?.tags ?? [], 't')],
|
||||||
},
|
},
|
||||||
nostr: {
|
nostr: {
|
||||||
pubkey,
|
pubkey,
|
||||||
|
|
Loading…
Reference in New Issue