This commit is contained in:
tamaina 2023-05-26 07:39:13 +00:00
parent 41c353e24d
commit a57df6f2ca
4 changed files with 84 additions and 51 deletions

View File

@ -5,55 +5,26 @@ import { GetterService } from '@/server/api/GetterService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js'; import { ApiError } from '../../../error.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
errors: {
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc',
},
alreadyPromoted: {
message: 'The note has already promoted.',
code: 'ALREADY_PROMOTED',
id: 'ae427aa2-7a41-484f-a18c-2c1104051604',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },
expiresAt: { type: 'integer' },
},
required: ['noteId', 'expiresAt'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'admin/promo/create'> {
name = 'admin/promo/create' as const;
constructor( constructor(
@Inject(DI.promoNotesRepository) @Inject(DI.promoNotesRepository)
private promoNotesRepository: PromoNotesRepository, private promoNotesRepository: PromoNotesRepository,
private getterService: GetterService, private getterService: GetterService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const note = await this.getterService.getNote(ps.noteId).catch(e => { const note = await this.getterService.getNote(ps.noteId).catch(e => {
if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); if (e.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(this.meta.errors.noSuchNote);
throw e; throw e;
}); });
const exist = await this.promoNotesRepository.findOneBy({ noteId: note.id }); const exist = await this.promoNotesRepository.findOneBy({ noteId: note.id });
if (exist != null) { if (exist != null) {
throw new ApiError(meta.errors.alreadyPromoted); throw new ApiError(this.meta.errors.alreadyPromoted);
} }
await this.promoNotesRepository.insert({ await this.promoNotesRepository.insert({

View File

@ -3,27 +3,15 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { ModerationLogService } from '@/core/ModerationLogService.js'; import { ModerationLogService } from '@/core/ModerationLogService.js';
import { QueueService } from '@/core/QueueService.js'; import { QueueService } from '@/core/QueueService.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
} as const;
export const paramDef = {
type: 'object',
properties: {},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'admin/queue/clear'> {
name = 'admin/queue/clear' as const;
constructor( constructor(
private moderationLogService: ModerationLogService, private moderationLogService: ModerationLogService,
private queueService: QueueService, private queueService: QueueService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
this.queueService.destroy(); this.queueService.destroy();
this.moderationLogService.insertModerationLog(me, 'clearQueue'); this.moderationLogService.insertModerationLog(me, 'clearQueue');

View File

@ -41,11 +41,12 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'admin/queue/deliver-delayed'> {
name = 'admin/queue/deliver-delayed' as const;
constructor( constructor(
@Inject('queue:deliver') public deliverQueue: DeliverQueue, @Inject('queue:deliver') public deliverQueue: DeliverQueue,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const jobs = await this.deliverQueue.getJobs(['delayed']); const jobs = await this.deliverQueue.getJobs(['delayed']);
const res = [] as [string, number][]; const res = [] as [string, number][];

View File

@ -857,6 +857,79 @@ export const endpoints = {
res: undefined, res: undefined,
}], }],
}, },
'admin/promo/create': {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
errors: {
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'ee449fbe-af2a-453b-9cae-cf2fe7c895fc',
},
alreadyPromoted: {
message: 'The note has already promoted.',
code: 'ALREADY_PROMOTED',
id: 'ae427aa2-7a41-484f-a18c-2c1104051604',
},
},
defines: [{
req: {
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },
expiresAt: { type: 'integer' },
},
required: ['noteId', 'expiresAt'],
},
res: undefined,
}],
},
'admin/queue/clear': {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
defines: [{
req: undefined,
res: undefined,
}],
},
'admin/queue/deliver-delayed': {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
defines: [{
req: undefined,
res: {
type: 'array',
items: {
type: 'array',
items: {
anyOf: [
{
type: 'string',
},
{
type: 'number',
},
],
},
},
examples: [[
'example.com',
12,
]],
},
}],
},
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };
export function getEndpointSchema(reqres: 'req' | 'res', key: keyof typeof endpoints) { export function getEndpointSchema(reqres: 'req' | 'res', key: keyof typeof endpoints) {