60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Injectable } from '@nestjs/common';
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
import { GetterService } from '@/server/api/GetterService.js';
|
|
import { UserFollowingService } from '@/core/UserFollowingService.js';
|
|
import { ApiError } from '../../../error.js';
|
|
|
|
export const meta = {
|
|
tags: ['following', 'account'],
|
|
|
|
requireCredential: true,
|
|
|
|
kind: 'write:following',
|
|
|
|
errors: {
|
|
noSuchUser: {
|
|
message: 'No such user.',
|
|
code: 'NO_SUCH_USER',
|
|
id: 'abc2ffa6-25b2-4380-ba99-321ff3a94555',
|
|
},
|
|
},
|
|
|
|
// 10 calls per 5 seconds
|
|
limit: {
|
|
duration: 1000 * 5,
|
|
max: 10,
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
userId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['userId'],
|
|
} as const;
|
|
|
|
@Injectable()
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
|
constructor(
|
|
private getterService: GetterService,
|
|
private userFollowingService: UserFollowingService,
|
|
) {
|
|
super(meta, paramDef, async (ps, me) => {
|
|
// Fetch follower
|
|
const follower = await this.getterService.getUser(ps.userId).catch(err => {
|
|
if (err.id === '15348ddd-432d-49c2-8a5a-8069753becff') throw new ApiError(meta.errors.noSuchUser);
|
|
throw err;
|
|
});
|
|
|
|
await this.userFollowingService.rejectFollowRequest(me, follower);
|
|
|
|
return;
|
|
});
|
|
}
|
|
}
|