なんかもうめっちゃ変えた

This commit is contained in:
syuilo
2022-09-18 03:27:08 +09:00
committed by GitHub
parent d9ab03f086
commit b75184ec8e
946 changed files with 41219 additions and 28839 deletions

View File

@@ -1,6 +1,9 @@
import define from '../../define.js';
import { Followings } from '@/models/index.js';
import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { FollowingsRepository } from '@/models/index.js';
import { QueryService } from '@/core/QueryService.js';
import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
@@ -30,13 +33,24 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const query = makePaginationQuery(Followings.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere(`following.followeeHost = :host`, { host: ps.host });
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,
const followings = await query
.take(ps.limit)
.getMany();
private followingEntityService: FollowingEntityService,
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere('following.followeeHost = :host', { host: ps.host });
return await Followings.packMany(followings, me, { populateFollowee: true });
});
const followings = await query
.take(ps.limit)
.getMany();
return await this.followingEntityService.packMany(followings, me, { populateFollowee: true });
});
}
}

View File

@@ -1,6 +1,9 @@
import define from '../../define.js';
import { Followings } from '@/models/index.js';
import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { FollowingsRepository } from '@/models/index.js';
import { QueryService } from '@/core/QueryService.js';
import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
@@ -30,13 +33,24 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const query = makePaginationQuery(Followings.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere(`following.followerHost = :host`, { host: ps.host });
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,
const followings = await query
.take(ps.limit)
.getMany();
private followingEntityService: FollowingEntityService,
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere('following.followerHost = :host', { host: ps.host });
return await Followings.packMany(followings, me, { populateFollowee: true });
});
const followings = await query
.take(ps.limit)
.getMany();
return await this.followingEntityService.packMany(followings, me, { populateFollowee: true });
});
}
}

View File

@@ -1,7 +1,9 @@
import config from '@/config/index.js';
import define from '../../define.js';
import { Instances } from '@/models/index.js';
import { fetchMeta } from '@/misc/fetch-meta.js';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { InstancesRepository } from '@/models/index.js';
import { InstanceEntityService } from '@/core/entities/InstanceEntityService.js';
import { MetaService } from '@/core/MetaService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
@@ -37,82 +39,93 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const query = Instances.createQueryBuilder('instance');
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,
switch (ps.sort) {
case '+pubSub': query.orderBy('instance.followingCount', 'DESC').orderBy('instance.followersCount', 'DESC'); break;
case '-pubSub': query.orderBy('instance.followingCount', 'ASC').orderBy('instance.followersCount', 'ASC'); break;
case '+notes': query.orderBy('instance.notesCount', 'DESC'); break;
case '-notes': query.orderBy('instance.notesCount', 'ASC'); break;
case '+users': query.orderBy('instance.usersCount', 'DESC'); break;
case '-users': query.orderBy('instance.usersCount', 'ASC'); break;
case '+following': query.orderBy('instance.followingCount', 'DESC'); break;
case '-following': query.orderBy('instance.followingCount', 'ASC'); break;
case '+followers': query.orderBy('instance.followersCount', 'DESC'); break;
case '-followers': query.orderBy('instance.followersCount', 'ASC'); break;
case '+caughtAt': query.orderBy('instance.caughtAt', 'DESC'); break;
case '-caughtAt': query.orderBy('instance.caughtAt', 'ASC'); break;
case '+lastCommunicatedAt': query.orderBy('instance.lastCommunicatedAt', 'DESC'); break;
case '-lastCommunicatedAt': query.orderBy('instance.lastCommunicatedAt', 'ASC'); break;
private instanceEntityService: InstanceEntityService,
private metaService: MetaService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.instancesRepository.createQueryBuilder('instance');
default: query.orderBy('instance.id', 'DESC'); break;
switch (ps.sort) {
case '+pubSub': query.orderBy('instance.followingCount', 'DESC').orderBy('instance.followersCount', 'DESC'); break;
case '-pubSub': query.orderBy('instance.followingCount', 'ASC').orderBy('instance.followersCount', 'ASC'); break;
case '+notes': query.orderBy('instance.notesCount', 'DESC'); break;
case '-notes': query.orderBy('instance.notesCount', 'ASC'); break;
case '+users': query.orderBy('instance.usersCount', 'DESC'); break;
case '-users': query.orderBy('instance.usersCount', 'ASC'); break;
case '+following': query.orderBy('instance.followingCount', 'DESC'); break;
case '-following': query.orderBy('instance.followingCount', 'ASC'); break;
case '+followers': query.orderBy('instance.followersCount', 'DESC'); break;
case '-followers': query.orderBy('instance.followersCount', 'ASC'); break;
case '+caughtAt': query.orderBy('instance.caughtAt', 'DESC'); break;
case '-caughtAt': query.orderBy('instance.caughtAt', 'ASC'); break;
case '+lastCommunicatedAt': query.orderBy('instance.lastCommunicatedAt', 'DESC'); break;
case '-lastCommunicatedAt': query.orderBy('instance.lastCommunicatedAt', 'ASC'); break;
default: query.orderBy('instance.id', 'DESC'); break;
}
if (typeof ps.blocked === 'boolean') {
const meta = await this.metaService.fetch(true);
if (ps.blocked) {
query.andWhere('instance.host IN (:...blocks)', { blocks: meta.blockedHosts });
} else {
query.andWhere('instance.host NOT IN (:...blocks)', { blocks: meta.blockedHosts });
}
}
if (typeof ps.notResponding === 'boolean') {
if (ps.notResponding) {
query.andWhere('instance.isNotResponding = TRUE');
} else {
query.andWhere('instance.isNotResponding = FALSE');
}
}
if (typeof ps.suspended === 'boolean') {
if (ps.suspended) {
query.andWhere('instance.isSuspended = TRUE');
} else {
query.andWhere('instance.isSuspended = FALSE');
}
}
if (typeof ps.federating === 'boolean') {
if (ps.federating) {
query.andWhere('((instance.followingCount > 0) OR (instance.followersCount > 0))');
} else {
query.andWhere('((instance.followingCount = 0) AND (instance.followersCount = 0))');
}
}
if (typeof ps.subscribing === 'boolean') {
if (ps.subscribing) {
query.andWhere('instance.followersCount > 0');
} else {
query.andWhere('instance.followersCount = 0');
}
}
if (typeof ps.publishing === 'boolean') {
if (ps.publishing) {
query.andWhere('instance.followingCount > 0');
} else {
query.andWhere('instance.followingCount = 0');
}
}
if (ps.host) {
query.andWhere('instance.host like :host', { host: '%' + ps.host.toLowerCase() + '%' });
}
const instances = await query.take(ps.limit).skip(ps.offset).getMany();
return await this.instanceEntityService.packMany(instances);
});
}
if (typeof ps.blocked === 'boolean') {
const meta = await fetchMeta(true);
if (ps.blocked) {
query.andWhere('instance.host IN (:...blocks)', { blocks: meta.blockedHosts });
} else {
query.andWhere('instance.host NOT IN (:...blocks)', { blocks: meta.blockedHosts });
}
}
if (typeof ps.notResponding === 'boolean') {
if (ps.notResponding) {
query.andWhere('instance.isNotResponding = TRUE');
} else {
query.andWhere('instance.isNotResponding = FALSE');
}
}
if (typeof ps.suspended === 'boolean') {
if (ps.suspended) {
query.andWhere('instance.isSuspended = TRUE');
} else {
query.andWhere('instance.isSuspended = FALSE');
}
}
if (typeof ps.federating === 'boolean') {
if (ps.federating) {
query.andWhere('((instance.followingCount > 0) OR (instance.followersCount > 0))');
} else {
query.andWhere('((instance.followingCount = 0) AND (instance.followersCount = 0))');
}
}
if (typeof ps.subscribing === 'boolean') {
if (ps.subscribing) {
query.andWhere('instance.followersCount > 0');
} else {
query.andWhere('instance.followersCount = 0');
}
}
if (typeof ps.publishing === 'boolean') {
if (ps.publishing) {
query.andWhere('instance.followingCount > 0');
} else {
query.andWhere('instance.followingCount = 0');
}
}
if (ps.host) {
query.andWhere('instance.host like :host', { host: '%' + ps.host.toLowerCase() + '%' });
}
const instances = await query.take(ps.limit).skip(ps.offset).getMany();
return await Instances.packMany(instances);
});
}

View File

@@ -1,6 +1,9 @@
import define from '../../define.js';
import { Instances } from '@/models/index.js';
import { toPuny } from '@/misc/convert-host.js';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { InstancesRepository } from '@/models/index.js';
import { InstanceEntityService } from '@/core/entities/InstanceEntityService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
@@ -26,9 +29,20 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const instance = await Instances
.findOneBy({ host: toPuny(ps.host) });
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,
return instance ? await Instances.pack(instance) : null;
});
private utilityService: UtilityService,
private instanceEntityService: InstanceEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const instance = await this.instancesRepository
.findOneBy({ host: this.utilityService.toPuny(ps.host) });
return instance ? await this.instanceEntityService.pack(instance) : null;
});
}
}

View File

@@ -1,7 +1,10 @@
import { IsNull, MoreThan, Not } from 'typeorm';
import { Followings, Instances } from '@/models/index.js';
import { awaitAll } from '@/prelude/await-all.js';
import define from '../../define.js';
import { Inject, Injectable } from '@nestjs/common';
import { FollowingsRepository, InstancesRepository } from '@/models/index.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { InstanceEntityService } from '@/core/entities/InstanceEntityService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
@@ -21,45 +24,58 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
Instances.find({
where: {
followersCount: MoreThan(0),
},
order: {
followersCount: 'DESC',
},
take: ps.limit,
}),
Instances.find({
where: {
followingCount: MoreThan(0),
},
order: {
followingCount: 'DESC',
},
take: ps.limit,
}),
Followings.count({
where: {
followeeHost: Not(IsNull()),
},
}),
Followings.count({
where: {
followerHost: Not(IsNull()),
},
}),
]);
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,
const gotSubCount = topSubInstances.map(x => x.followersCount).reduce((a, b) => a + b, 0);
const gotPubCount = topPubInstances.map(x => x.followingCount).reduce((a, b) => a + b, 0);
@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,
return await awaitAll({
topSubInstances: Instances.packMany(topSubInstances),
otherFollowersCount: Math.max(0, allSubCount - gotSubCount),
topPubInstances: Instances.packMany(topPubInstances),
otherFollowingCount: Math.max(0, allPubCount - gotPubCount),
});
});
private instanceEntityService: InstanceEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
this.instancesRepository.find({
where: {
followersCount: MoreThan(0),
},
order: {
followersCount: 'DESC',
},
take: ps.limit,
}),
this.instancesRepository.find({
where: {
followingCount: MoreThan(0),
},
order: {
followingCount: 'DESC',
},
take: ps.limit,
}),
this.followingsRepository.count({
where: {
followeeHost: Not(IsNull()),
},
}),
this.followingsRepository.count({
where: {
followerHost: Not(IsNull()),
},
}),
]);
const gotSubCount = topSubInstances.map(x => x.followersCount).reduce((a, b) => a + b, 0);
const gotPubCount = topPubInstances.map(x => x.followingCount).reduce((a, b) => a + b, 0);
return await awaitAll({
topSubInstances: this.instanceEntityService.packMany(topSubInstances),
otherFollowersCount: Math.max(0, allSubCount - gotSubCount),
topPubInstances: this.instanceEntityService.packMany(topPubInstances),
otherFollowingCount: Math.max(0, allPubCount - gotPubCount),
});
});
}
}

View File

@@ -1,6 +1,7 @@
import define from '../../define.js';
import { getRemoteUser } from '../../common/getters.js';
import { updatePerson } from '@/remote/activitypub/models/person.js';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { ApPersonService } from '@/core/remote/activitypub/models/ApPersonService.js';
import { GetterService } from '../../common/GetterService.js';
export const meta = {
tags: ['federation'],
@@ -17,7 +18,15 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
const user = await getRemoteUser(ps.userId);
await updatePerson(user.uri!);
});
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
private getterService: GetterService,
private apPersonService: ApPersonService,
) {
super(meta, paramDef, async (ps) => {
const user = await this.getterService.getRemoteUser(ps.userId);
await this.apPersonService.updatePerson(user.uri!);
});
}
}

View File

@@ -1,6 +1,9 @@
import define from '../../define.js';
import { Users } from '@/models/index.js';
import { makePaginationQuery } from '../../common/make-pagination-query.js';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { UsersRepository } from '@/models/index.js';
import { QueryService } from '@/core/QueryService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
@@ -30,13 +33,24 @@ export const paramDef = {
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, me) => {
const query = makePaginationQuery(Users.createQueryBuilder('user'), ps.sinceId, ps.untilId)
.andWhere(`user.host = :host`, { host: ps.host });
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
const users = await query
.take(ps.limit)
.getMany();
private userEntityService: UserEntityService,
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.usersRepository.createQueryBuilder('user'), ps.sinceId, ps.untilId)
.andWhere('user.host = :host', { host: ps.host });
return await Users.packMany(users, me, { detail: true });
});
const users = await query
.take(ps.limit)
.getMany();
return await this.userEntityService.packMany(users, me, { detail: true });
});
}
}