wip
This commit is contained in:
parent
53ad4b18e5
commit
5268a55996
|
@ -3,29 +3,15 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { ModerationLogService } from '@/core/ModerationLogService.js';
|
||||
import { QueueService } from '@/core/QueueService.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { type: 'string', enum: ['deliver', 'inbox'] },
|
||||
},
|
||||
required: ['type'],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
export default class extends Endpoint<'admin/queue/promote'> {
|
||||
name = 'admin/queue/promote' as const;
|
||||
constructor(
|
||||
private moderationLogService: ModerationLogService,
|
||||
private queueService: QueueService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
let delayedQueues;
|
||||
|
||||
switch (ps.type) {
|
||||
|
|
|
@ -2,45 +2,10 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, SystemQueue, WebhookDeliverQueue } from '@/core/QueueModule.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
res: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
deliver: {
|
||||
optional: false, nullable: false,
|
||||
ref: 'QueueCount',
|
||||
},
|
||||
inbox: {
|
||||
optional: false, nullable: false,
|
||||
ref: 'QueueCount',
|
||||
},
|
||||
db: {
|
||||
optional: false, nullable: false,
|
||||
ref: 'QueueCount',
|
||||
},
|
||||
objectStorage: {
|
||||
optional: false, nullable: false,
|
||||
ref: 'QueueCount',
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
export default class extends Endpoint<'admin/queue/stats'> {
|
||||
name = 'admin/queue/stats' as const;
|
||||
constructor(
|
||||
@Inject('queue:system') public systemQueue: SystemQueue,
|
||||
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
|
||||
|
@ -50,7 +15,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
@Inject('queue:objectStorage') public objectStorageQueue: ObjectStorageQueue,
|
||||
@Inject('queue:webhookDeliver') public webhookDeliverQueue: WebhookDeliverQueue,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const deliverJobCounts = await this.deliverQueue.getJobCounts();
|
||||
const inboxJobCounts = await this.inboxQueue.getJobCounts();
|
||||
const dbJobCounts = await this.dbQueue.getJobCounts();
|
||||
|
|
|
@ -4,48 +4,6 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { RelayService } from '@/core/RelayService.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
errors: {
|
||||
invalidUrl: {
|
||||
message: 'Invalid URL',
|
||||
code: 'INVALID_URL',
|
||||
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
|
||||
},
|
||||
},
|
||||
|
||||
res: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'id',
|
||||
},
|
||||
inbox: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'url',
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
default: 'requesting',
|
||||
enum: [
|
||||
'requesting',
|
||||
'accepted',
|
||||
'rejected',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
|
@ -56,15 +14,16 @@ export const paramDef = {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
export default class extends Endpoint<'admin/relays/add'> {
|
||||
name = 'admin/relays/add' as const;
|
||||
constructor(
|
||||
private relayService: RelayService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
try {
|
||||
if (new URL(ps.inbox).protocol !== 'https:') throw 'https only';
|
||||
} catch {
|
||||
throw new ApiError(meta.errors.invalidUrl);
|
||||
throw new ApiError(this.meta.errors.invalidUrl);
|
||||
}
|
||||
|
||||
return await this.relayService.addRelay(ps.inbox);
|
||||
|
|
|
@ -2,57 +2,14 @@ import { Injectable } from '@nestjs/common';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { RelayService } from '@/core/RelayService.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
items: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'id',
|
||||
},
|
||||
inbox: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'url',
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
default: 'requesting',
|
||||
enum: [
|
||||
'requesting',
|
||||
'accepted',
|
||||
'rejected',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
export default class extends Endpoint<'admin/relays/list'> {
|
||||
name = 'admin/relays/list' as const;
|
||||
constructor(
|
||||
private relayService: RelayService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
return await this.relayService.listRelay();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -960,6 +960,86 @@ export const endpoints = {
|
|||
},
|
||||
}],
|
||||
},
|
||||
'admin/queue/promote': {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
type: { type: 'string', enum: ['deliver', 'inbox'] },
|
||||
},
|
||||
required: ['type'],
|
||||
},
|
||||
res: undefined,
|
||||
}],
|
||||
},
|
||||
'admin/queue/stats': {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
defines: [{
|
||||
req: undefined,
|
||||
res: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
deliver: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' },
|
||||
inbox: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' },
|
||||
db: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' },
|
||||
objectStorage: { $ref: 'https://misskey-hub.net/api/schemas/QueueCount' },
|
||||
},
|
||||
required: ['deliver', 'inbox', 'db', 'objectStorage'],
|
||||
}
|
||||
}],
|
||||
},
|
||||
'admin/relays/add': {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
errors: {
|
||||
invalidUrl: {
|
||||
message: 'Invalid URL',
|
||||
code: 'INVALID_URL',
|
||||
id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c',
|
||||
},
|
||||
},
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
inbox: { type: 'string' },
|
||||
},
|
||||
required: ['inbox'],
|
||||
},
|
||||
res: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Relay',
|
||||
},
|
||||
}],
|
||||
},
|
||||
'admin/relays/list': {
|
||||
tags: ['admin'],
|
||||
|
||||
requireCredential: true,
|
||||
requireModerator: true,
|
||||
|
||||
defines: [{
|
||||
req: undefined,
|
||||
res: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Relay',
|
||||
},
|
||||
},
|
||||
}],
|
||||
}
|
||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,7 @@ export type Clip = Packed<'Clip'>;
|
|||
export type Channel = Packed<'Channel'>;
|
||||
export type Following = Packed<'Following'>;
|
||||
export type Blocking = Packed<'Blocking'>;
|
||||
export type Relay = Packed<'Relay'>;
|
||||
|
||||
export type LiteInstanceMetadata = {
|
||||
maintainerName: string | null;
|
||||
|
|
|
@ -35,6 +35,7 @@ import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from './schemas/em
|
|||
import { packedFlashSchema } from './schemas/flash.js';
|
||||
import { packedAdSchema } from './schemas/ad.js';
|
||||
import { packedAnnouncementSchema } from './schemas/announcement.js';
|
||||
import { packedRelaySchema } from './schemas/relay.js';
|
||||
import { Error, ApiError } from './schemas/error.js';
|
||||
import type { JSONSchema7, JSONSchema7Definition, GetDef, GetRefs, GetKeys, UnionToArray } from 'schema-type';
|
||||
|
||||
|
@ -75,6 +76,7 @@ export const refs = {
|
|||
Flash: packedFlashSchema,
|
||||
Ad: packedAdSchema,
|
||||
Announcement: packedAnnouncementSchema,
|
||||
Relay: packedRelaySchema,
|
||||
|
||||
Error: Error,
|
||||
ApiError: ApiError,
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import type { JSONSchema7Definition } from 'schema-type';
|
||||
|
||||
export const packedRelaySchema = {
|
||||
$id: 'https://misskey-hub.net/api/schemas/Relay',
|
||||
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
format: 'id',
|
||||
},
|
||||
inbox: {
|
||||
type: 'string',
|
||||
format: 'url',
|
||||
},
|
||||
status: {
|
||||
type: 'string',
|
||||
default: 'requesting',
|
||||
enum: [
|
||||
'requesting',
|
||||
'accepted',
|
||||
'rejected',
|
||||
],
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'id',
|
||||
'inbox',
|
||||
'status'
|
||||
],
|
||||
} as const satisfies JSONSchema7Definition;
|
|
@ -97,6 +97,9 @@ describe('schemas', () => {
|
|||
test('ad', () => {
|
||||
type Ad = Packed<'Ad'>;
|
||||
});
|
||||
test('relay', () => {
|
||||
type Relay = Packed<'Relay'>;
|
||||
});
|
||||
test('error', () => {
|
||||
type Error = Packed<'Error'>;
|
||||
type ApiError = Packed<'ApiError'>;
|
||||
|
|
Loading…
Reference in New Issue