This commit is contained in:
tamaina
2023-05-27 16:06:42 +00:00
parent 53ad4b18e5
commit 5268a55996
9 changed files with 130 additions and 146 deletions

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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);

View File

@@ -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();
});
}