wip
This commit is contained in:
		@@ -5,55 +5,26 @@ import { GetterService } from '@/server/api/GetterService.js';
 | 
			
		||||
import { DI } from '@/di-symbols.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
 | 
			
		||||
@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(
 | 
			
		||||
		@Inject(DI.promoNotesRepository)
 | 
			
		||||
		private promoNotesRepository: PromoNotesRepository,
 | 
			
		||||
 | 
			
		||||
		private getterService: GetterService,
 | 
			
		||||
	) {
 | 
			
		||||
		super(meta, paramDef, async (ps, me) => {
 | 
			
		||||
		super(async (ps, me) => {
 | 
			
		||||
			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;
 | 
			
		||||
			});
 | 
			
		||||
 | 
			
		||||
			const exist = await this.promoNotesRepository.findOneBy({ noteId: note.id });
 | 
			
		||||
 | 
			
		||||
			if (exist != null) {
 | 
			
		||||
				throw new ApiError(meta.errors.alreadyPromoted);
 | 
			
		||||
				throw new ApiError(this.meta.errors.alreadyPromoted);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			await this.promoNotesRepository.insert({
 | 
			
		||||
 
 | 
			
		||||
@@ -3,27 +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: {},
 | 
			
		||||
	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/clear'> {
 | 
			
		||||
	name = 'admin/queue/clear' as const;
 | 
			
		||||
	constructor(
 | 
			
		||||
		private moderationLogService: ModerationLogService,
 | 
			
		||||
		private queueService: QueueService,
 | 
			
		||||
	) {
 | 
			
		||||
		super(meta, paramDef, async (ps, me) => {
 | 
			
		||||
		super(async (ps, me) => {
 | 
			
		||||
			this.queueService.destroy();
 | 
			
		||||
 | 
			
		||||
			this.moderationLogService.insertModerationLog(me, 'clearQueue');
 | 
			
		||||
 
 | 
			
		||||
@@ -41,11 +41,12 @@ 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/queue/deliver-delayed'> {
 | 
			
		||||
	name = 'admin/queue/deliver-delayed' as const;
 | 
			
		||||
	constructor(
 | 
			
		||||
		@Inject('queue:deliver') public deliverQueue: DeliverQueue,
 | 
			
		||||
	) {
 | 
			
		||||
		super(meta, paramDef, async (ps, me) => {
 | 
			
		||||
		super(async (ps, me) => {
 | 
			
		||||
			const jobs = await this.deliverQueue.getJobs(['delayed']);
 | 
			
		||||
 | 
			
		||||
			const res = [] as [string, number][];
 | 
			
		||||
 
 | 
			
		||||
@@ -857,6 +857,79 @@ export const endpoints = {
 | 
			
		||||
			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; };
 | 
			
		||||
 | 
			
		||||
export function getEndpointSchema(reqres: 'req' | 'res', key: keyof typeof endpoints) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user