refactor: fix type

This commit is contained in:
syuilo 2022-04-17 20:44:21 +09:00
parent 6b31ea1992
commit 02bb36cdc4
7 changed files with 41 additions and 53 deletions

View file

@ -1,32 +1,26 @@
import Router from '@koa/router';
import { FindOptionsWhere, IsNull, LessThan } from 'typeorm';
import config from '@/config/index.js';
import $ from 'cafy';
import { ID } from '@/misc/cafy-id.js';
import * as url from '@/prelude/url.js';
import { renderActivity } from '@/remote/activitypub/renderer/index.js';
import renderOrderedCollection from '@/remote/activitypub/renderer/ordered-collection.js';
import renderOrderedCollectionPage from '@/remote/activitypub/renderer/ordered-collection-page.js';
import renderFollowUser from '@/remote/activitypub/renderer/follow-user.js';
import { setResponseType } from '../activitypub.js';
import { Users, Followings, UserProfiles } from '@/models/index.js';
import { IsNull, LessThan } from 'typeorm';
import { Following } from '@/models/entities/following.js';
import { setResponseType } from '../activitypub.js';
export default async (ctx: Router.RouterContext) => {
const userId = ctx.params.user;
// Get 'cursor' parameter
const [cursor, cursorErr] = $.default.optional.type(ID).get(ctx.request.query.cursor);
// Get 'page' parameter
const pageErr = !$.default.optional.str.or(['true', 'false']).ok(ctx.request.query.page);
const page: boolean = ctx.request.query.page === 'true';
// Validate parameters
if (cursorErr || pageErr) {
const cursor = ctx.request.query.cursor;
if (cursor != null && typeof cursor !== 'string') {
ctx.status = 400;
return;
}
const page = ctx.request.query.page === 'true';
const user = await Users.findOneBy({
id: userId,
host: IsNull(),
@ -57,7 +51,7 @@ export default async (ctx: Router.RouterContext) => {
if (page) {
const query = {
followeeId: user.id,
} as any;
} as FindOptionsWhere<Following>;
// カーソルが指定されている場合
if (cursor) {
@ -86,7 +80,7 @@ export default async (ctx: Router.RouterContext) => {
inStock ? `${partOf}?${url.query({
page: 'true',
cursor: followings[followings.length - 1].id,
})}` : undefined
})}` : undefined,
);
ctx.body = renderActivity(rendered);