add ActivityPub representation to admin-user.vue

This commit is contained in:
Hazelnoot 2025-06-07 18:49:37 -04:00
parent c71f816be2
commit 73eeabc118
6 changed files with 111 additions and 13 deletions

12
locales/index.d.ts vendored
View file

@ -13245,6 +13245,18 @@ export interface Locale extends ILocale {
* Note controls * Note controls
*/ */
"noteFooterLabel": string; "noteFooterLabel": string;
/**
* Packed user data in its raw form. Most of these fields are public and visible to all users.
*/
"rawUserDescription": string;
/**
* Extended user data in its raw form. These fields are private and can only be accessed by moderators.
*/
"rawInfoDescription": string;
/**
* ActivityPub user data in its raw form. These fields are public and accessible to other instances.
*/
"rawApDescription": string;
} }
declare const locales: { declare const locales: {
[lang: string]: Locale; [lang: string]: Locale;

View file

@ -17,6 +17,7 @@ import { DebounceLoader } from '@/misc/loader.js';
import { IdService } from '@/core/IdService.js'; import { IdService } from '@/core/IdService.js';
import { ReactionsBufferingService } from '@/core/ReactionsBufferingService.js'; import { ReactionsBufferingService } from '@/core/ReactionsBufferingService.js';
import { isPackedPureRenote } from '@/misc/is-renote.js'; import { isPackedPureRenote } from '@/misc/is-renote.js';
import type { Config } from '@/config.js';
import type { OnModuleInit } from '@nestjs/common'; import type { OnModuleInit } from '@nestjs/common';
import type { CacheService } from '../CacheService.js'; import type { CacheService } from '../CacheService.js';
import type { CustomEmojiService } from '../CustomEmojiService.js'; import type { CustomEmojiService } from '../CustomEmojiService.js';
@ -92,6 +93,9 @@ export class NoteEntityService implements OnModuleInit {
@Inject(DI.channelsRepository) @Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository, private channelsRepository: ChannelsRepository,
@Inject(DI.config)
private readonly config: Config
//private userEntityService: UserEntityService, //private userEntityService: UserEntityService,
//private driveFileEntityService: DriveFileEntityService, //private driveFileEntityService: DriveFileEntityService,
//private customEmojiService: CustomEmojiService, //private customEmojiService: CustomEmojiService,
@ -680,4 +684,9 @@ export class NoteEntityService implements OnModuleInit {
return map; return map;
}, {} as Record<string, string | undefined>); }, {} as Record<string, string | undefined>);
} }
@bindThis
public genLocalNoteUri(noteId: string): string {
return `${this.config.url}/notes/${noteId}`;
}
} }

View file

@ -3,11 +3,17 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { Injectable } from '@nestjs/common'; import { Inject, Injectable } from '@nestjs/common';
import ms from 'ms'; import ms from 'ms';
import { Endpoint } from '@/server/api/endpoint-base.js'; import { Endpoint } from '@/server/api/endpoint-base.js';
import { ApResolverService } from '@/core/activitypub/ApResolverService.js'; import { ApResolverService } from '@/core/activitypub/ApResolverService.js';
import { isCollectionOrOrderedCollection, isOrderedCollection, isOrderedCollectionPage } from '@/core/activitypub/type.js'; import { isCollectionOrOrderedCollection, isOrderedCollection, isOrderedCollectionPage } from '@/core/activitypub/type.js';
import { ApiError } from '@/server/api/error.js';
import { CacheService } from '@/core/CacheService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DI } from '@/di-symbols.js';
import type { NotesRepository } from '@/models/_.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
export const meta = { export const meta = {
tags: ['federation'], tags: ['federation'],
@ -22,6 +28,16 @@ export const meta = {
}, },
errors: { errors: {
noInputSpecified: {
message: 'uri, userId, or noteId must be specified.',
code: 'NO_INPUT_SPECIFIED',
id: 'b43ff2a7-e7a2-4237-ad7f-7b079563c09e',
},
multipleInputsSpecified: {
message: 'Only one of uri, userId, or noteId can be specified',
code: 'MULTIPLE_INPUTS_SPECIFIED',
id: 'f1aa27ed-8f20-44f3-a92a-fe073c8ca52b',
},
}, },
res: { res: {
@ -33,22 +49,46 @@ export const meta = {
export const paramDef = { export const paramDef = {
type: 'object', type: 'object',
properties: { properties: {
uri: { type: 'string' }, uri: { type: 'string', nullable: true },
userId: { type: 'string', format: 'misskey:id', nullable: true },
noteId: { type: 'string', format: 'misskey:id', nullable: true },
expandCollectionItems: { type: 'boolean' }, expandCollectionItems: { type: 'boolean' },
expandCollectionLimit: { type: 'integer', nullable: true }, expandCollectionLimit: { type: 'integer', nullable: true },
allowAnonymous: { type: 'boolean' }, allowAnonymous: { type: 'boolean' },
}, },
required: ['uri'],
} as const; } as const;
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor( constructor(
@Inject(DI.notesRepository)
private readonly notesRepository: NotesRepository,
private readonly cacheService: CacheService,
private readonly userEntityService: UserEntityService,
private readonly noteEntityService: NoteEntityService,
private apResolverService: ApResolverService, private apResolverService: ApResolverService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps) => {
if (ps.uri && ps.userId && ps.noteId) {
throw new ApiError(meta.errors.multipleInputsSpecified);
}
let uri: string;
if (ps.uri) {
uri = ps.uri;
} else if (ps.userId) {
const user = await this.cacheService.findUserById(ps.userId);
uri = user.uri ?? this.userEntityService.genLocalUserUri(ps.userId);
} else if (ps.noteId) {
const note = await this.notesRepository.findOneByOrFail({ id: ps.noteId });
uri = note.uri ?? this.noteEntityService.genLocalNoteUri(ps.noteId);
} else {
throw new ApiError(meta.errors.noInputSpecified);
}
const resolver = this.apResolverService.createResolver(); const resolver = this.apResolverService.createResolver();
const object = await resolver.resolve(ps.uri, ps.allowAnonymous ?? false); const object = await resolver.resolve(uri, ps.allowAnonymous ?? false);
if (ps.expandCollectionItems && isCollectionOrOrderedCollection(object)) { if (ps.expandCollectionItems && isCollectionOrOrderedCollection(object)) {
const items = await resolver.resolveCollectionItems(object, ps.expandCollectionLimit, ps.allowAnonymous ?? false); const items = await resolver.resolveCollectionItems(object, ps.expandCollectionLimit, ps.allowAnonymous ?? false);

View file

@ -231,6 +231,12 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder :sticky="false" :defaultOpen="true"> <MkFolder :sticky="false" :defaultOpen="true">
<template #icon><i class="ph-user-circle ph-bold ph-lg"></i></template> <template #icon><i class="ph-user-circle ph-bold ph-lg"></i></template>
<template #label>{{ i18n.ts.user }}</template> <template #label>{{ i18n.ts.user }}</template>
<template #header>
<div :class="$style.rawFolderHeader">
<span>{{ i18n.ts.rawUserDescription }}</span>
<button class="_textButton" @click="copyToClipboard(JSON.stringify(user, null, 4))"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</button>
</div>
</template>
<MkObjectView tall :value="user"/> <MkObjectView tall :value="user"/>
</MkFolder> </MkFolder>
@ -238,6 +244,12 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder :sticky="false"> <MkFolder :sticky="false">
<template #icon><i class="ti ti-info-circle"></i></template> <template #icon><i class="ti ti-info-circle"></i></template>
<template #label>{{ i18n.ts.details }}</template> <template #label>{{ i18n.ts.details }}</template>
<template #header>
<div :class="$style.rawFolderHeader">
<span>{{ i18n.ts.rawInfoDescription }}</span>
<button class="_textButton" @click="copyToClipboard(JSON.stringify(info, null, 4))"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</button>
</div>
</template>
<MkObjectView tall :value="info"/> <MkObjectView tall :value="info"/>
</MkFolder> </MkFolder>
@ -245,7 +257,12 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkFolder v-if="ap" :sticky="false"> <MkFolder v-if="ap" :sticky="false">
<template #icon><i class="ph-globe ph-bold ph-lg"></i></template> <template #icon><i class="ph-globe ph-bold ph-lg"></i></template>
<template #label>{{ i18n.ts.activityPub }}</template> <template #label>{{ i18n.ts.activityPub }}</template>
<template #header>
<div :class="$style.rawFolderHeader">
<span>{{ i18n.ts.rawApDescription }}</span>
<button class="_textButton" @click="copyToClipboard(JSON.stringify(ap, null, 4))"><i class="ti ti-copy"></i> {{ i18n.ts.copy }}</button>
</div>
</template>
<MkObjectView tall :value="ap"/> <MkObjectView tall :value="ap"/>
</MkFolder> </MkFolder>
</div> </div>
@ -437,12 +454,15 @@ function createFetcher(withHint = true) {
(withHint && props.infoHint) ? props.infoHint : misskeyApi('admin/show-user', { (withHint && props.infoHint) ? props.infoHint : misskeyApi('admin/show-user', {
userId: props.userId, userId: props.userId,
}), }),
(withHint && props.ipsHint) ? props.ipsHint : misskeyApi('admin/get-user-ips', { iAmAdmin
userId: props.userId, ? (withHint && props.ipsHint) ? props.ipsHint : misskeyApi('admin/get-user-ips', {
}), userId: props.userId,
(withHint && props.apHint) ? props.apHint : misskeyApi('ap/get', { })
userId: props.userId, : null,
}).catch(() => null)], iAmAdmin
? (withHint && props.apHint) ? props.apHint : misskeyApi('ap/get', {
userId: props.userId,
}).catch(() => null) : null],
).then(async ([_user, _info, _ips, _ap]) => { ).then(async ([_user, _info, _ips, _ap]) => {
user.value = _user; user.value = _user;
info.value = _info; info.value = _info;
@ -902,4 +922,13 @@ definePage(() => ({
margin: calc(var(--MI-margin) / 2); margin: calc(var(--MI-margin) / 2);
} }
} }
.rawFolderHeader {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-start;
padding: var(--MI-marginHalf);
gap: var(--MI-marginHalf);
}
</style> </style>

View file

@ -12922,7 +12922,11 @@ export type operations = {
requestBody: { requestBody: {
content: { content: {
'application/json': { 'application/json': {
uri: string; uri?: string | null;
/** Format: misskey:id */
userId?: string | null;
/** Format: misskey:id */
noteId?: string | null;
expandCollectionItems?: boolean; expandCollectionItems?: boolean;
expandCollectionLimit?: number | null; expandCollectionLimit?: number | null;
allowAnonymous?: boolean; allowAnonymous?: boolean;

View file

@ -624,3 +624,7 @@ keepCwEnabled: "Enabled (copy CWs verbatim)"
keepCwPrependRe: "Enabled (copy CW and prepend \"RE:\")" keepCwPrependRe: "Enabled (copy CW and prepend \"RE:\")"
noteFooterLabel: "Note controls" noteFooterLabel: "Note controls"
rawUserDescription: "Packed user data in its raw form. Most of these fields are public and visible to all users."
rawInfoDescription: "Extended user data in its raw form. These fields are private and can only be accessed by moderators."
rawApDescription: "ActivityPub user data in its raw form. These fields are public and accessible to other instances."