From 3918473e29ecd7f33e8235c0c60fbeaf4d845175 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 29 May 2023 17:03:20 +0000 Subject: [PATCH] wip --- .../server/api/endpoints/admin/show-user.ts | 5 +- packages/misskey-js/src/endpoints.ts | 101 +++++++++++++++++- packages/misskey-js/src/entities.ts | 2 +- packages/misskey-js/src/schemas.ts | 2 + .../misskey-js/src/schemas/notification.ts | 10 +- 5 files changed, 112 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/admin/show-user.ts b/packages/backend/src/server/api/endpoints/admin/show-user.ts index f49d2a096..9c00ab830 100644 --- a/packages/backend/src/server/api/endpoints/admin/show-user.ts +++ b/packages/backend/src/server/api/endpoints/admin/show-user.ts @@ -27,7 +27,8 @@ export const paramDef = { // eslint-disable-next-line import/no-default-export @Injectable() -export default class extends Endpoint { +export default class extends Endpoint<'admin/show-user'> { + name = 'admin/show-user' as const; constructor( @Inject(DI.usersRepository) private usersRepository: UsersRepository, @@ -41,7 +42,7 @@ export default class extends Endpoint { private roleService: RoleService, private roleEntityService: RoleEntityService, ) { - super(meta, paramDef, async (ps, me) => { + super(async (ps, me) => { const [user, profile] = await Promise.all([ this.usersRepository.findOneBy({ id: ps.userId }), this.userProfilesRepository.findOneBy({ userId: ps.userId }), diff --git a/packages/misskey-js/src/endpoints.ts b/packages/misskey-js/src/endpoints.ts index d6237b3dc..b60256856 100644 --- a/packages/misskey-js/src/endpoints.ts +++ b/packages/misskey-js/src/endpoints.ts @@ -1651,7 +1651,106 @@ export const endpoints = { }], }, 'admin/show-user': { - + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + defines: [{ + req: { + type: 'object', + properties: { + userId: { type: 'string', format: 'misskey:id' }, + }, + required: ['userId'], + }, + res: { + type: 'object', + properties: { + email: { type: ['string', 'null'] }, + emailVerified: { type: 'boolean' }, + autoAcceptFollowed: { type: 'boolean' }, + noCrawle: { type: 'boolean' }, + preventAiLearning: { type: 'boolean' }, + alwaysMarkNsfw: { type: 'boolean' }, + autoSensitive: { type: 'boolean' }, + carefulBot: { type: 'boolean' }, + injectFeaturedNote: { type: 'boolean' }, + receiveAnnouncementEmail: { type: 'boolean' }, + mutedWords: { + type: 'array', + items: { + type: 'array', + items: { + type: 'string', + }, + }, + }, + mutedInstances: { + type: 'array', + items: { + type: 'string', + }, + }, + mutingNotificationTypes: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/NotificationType', + }, + }, + isModerator: { type: 'boolean' }, + isSilenced: { type: 'boolean' }, + isSuspended: { type: 'boolean' }, + lastActiveDate: { + oneOf: [{ + type: 'string', + format: 'date-time', + }, { + type: 'null', + }], + }, + moderationNote: { type: 'string' }, + signins: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/SignIn', + } + }, + policies: { + type: 'object', + }, + roles: { + type: 'array', + items: { + $ref: 'https://misskey-hub.net/api/schemas/Role', + } + }, + }, + required: [ + 'email', + 'emailVerified', + 'autoAcceptFollowed', + 'noCrawle', + 'preventAiLearning', + 'alwaysMarkNsfw', + 'autoSensitive', + 'carefulBot', + 'injectFeaturedNote', + 'receiveAnnouncementEmail', + 'mutedWords', + 'mutedInstances', + 'mutingNotificationTypes', + 'isModerator', + 'isSilenced', + 'isSuspended', + 'lastActiveDate', + 'moderationNote', + 'signins', + 'policies', + 'roles', + ], + } + }], }, } as const satisfies { [x: string]: IEndpointMeta; }; diff --git a/packages/misskey-js/src/entities.ts b/packages/misskey-js/src/entities.ts index b1c6b7d6a..d71731cf5 100644 --- a/packages/misskey-js/src/entities.ts +++ b/packages/misskey-js/src/entities.ts @@ -107,7 +107,7 @@ export type DetailedInstanceMetadata = LiteInstanceMetadata & { export type InstanceMetadata = LiteInstanceMetadata | DetailedInstanceMetadata; -export type ServerInfo = Selialized>; +export type ServerInfo = Serialized>; export type Stats = { notesCount: number; diff --git a/packages/misskey-js/src/schemas.ts b/packages/misskey-js/src/schemas.ts index d4557df29..e7699fc2a 100644 --- a/packages/misskey-js/src/schemas.ts +++ b/packages/misskey-js/src/schemas.ts @@ -9,6 +9,7 @@ import { packedUserSchema, } from './schemas/user.js'; import { + notificationTypeSchema, packedNotificationSchema, packedNotificationStrictSchema, } from './schemas/notification.js'; @@ -74,6 +75,7 @@ export const refs = { Note: packedNoteSchema, NoteReaction: packedNoteReactionSchema, NoteFavorite: packedNoteFavoriteSchema, + NotificationType: notificationTypeSchema, Notification: packedNotificationSchema, NotificationStrict: packedNotificationStrictSchema, DriveFile: packedDriveFileSchema, diff --git a/packages/misskey-js/src/schemas/notification.ts b/packages/misskey-js/src/schemas/notification.ts index d01c8579c..5af92b3e9 100644 --- a/packages/misskey-js/src/schemas/notification.ts +++ b/packages/misskey-js/src/schemas/notification.ts @@ -1,6 +1,11 @@ import type { JSONSchema7Definition } from 'schema-type'; import { ACHIEVEMENT_TYPES, notificationTypes } from '../consts'; +export const notificationTypeSchema = { + $id: 'https://misskey-hub.net/api/schemas/NotificationTypes', + enum: [...notificationTypes], +} as const satisfies JSONSchema7Definition; + export const packedNotificationSchema = { $id: 'https://misskey-hub.net/api/schemas/Notification', type: 'object', @@ -10,10 +15,7 @@ export const packedNotificationSchema = { type: 'string', format: 'date-time', }, - type: { - type: 'string', - enum: [...notificationTypes], - }, + type: { $ref: 'https://misskey-hub.net/api/schemas/NotificationType' }, userId: { oneOf: [ { $ref: 'https://misskey-hub.net/api/schemas/Id' },